/** * Theme functions file * * Contains handlers for navigation, accessibility, header sizing * footer widgets and Featured Content slider * */ ( function( $ ) { var body = $( 'body' ), _window = $( window ), nav, button, menu; nav = $( '#primary-navigation' ); button = nav.find( '.menu-toggle' ); menu = nav.find( '.nav-menu' ); // Enable menu toggle for small screens. ( function() { if ( ! nav || ! button ) { return; } // Hide button if menu is missing or empty. if ( ! menu || ! menu.children().length ) { button.hide(); return; } button.on( 'click.basetheme', function() { nav.toggleClass( 'toggled-on' ); if ( nav.hasClass( 'toggled-on' ) ) { $( this ).attr( 'aria-expanded', 'true' ); menu.attr( 'aria-expanded', 'true' ); } else { $( this ).attr( 'aria-expanded', 'false' ); menu.attr( 'aria-expanded', 'false' ); } } ); } )(); /* * Makes "skip to content" link work correctly in IE9 and Chrome for better * accessibility. * * @link http://www.nczonline.net/blog/2013/01/15/fixing-skip-to-content-links/ */ _window.on( 'hashchange.basetheme', function() { var hash = location.hash.substring( 1 ), element; if ( ! hash ) { return; } element = document.getElementById( hash ); if ( element ) { if ( ! /^(?:a|select|input|button|textarea)$/i.test( element.tagName ) ) { element.tabIndex = -1; } element.focus(); // Repositions the window on jump-to-anchor to account for header height. window.scrollBy( 0, -80 ); } } ); $( function() { // Search toggle. $( '.search-toggle' ).on( 'click.basetheme', function( event ) { var that = $( this ), wrapper = $( '#search-container' ), container = that.find( 'a' ); that.toggleClass( 'active' ); wrapper.toggleClass( 'hide' ); if ( that.hasClass( 'active' ) ) { container.attr( 'aria-expanded', 'true' ); } else { container.attr( 'aria-expanded', 'false' ); } if ( that.is( '.active' ) || $( '.search-toggle .screen-reader-text' )[0] === event.target ) { wrapper.find( '.search-field' ).focus(); } } ); /* * Fixed header for large screen. * If the header becomes more than 48px tall, unfix the header. * * The callback on the scroll event is only added if there is a header * image and we are not on mobile. */ if ( _window.width() > 781 ) { var mastheadHeight = $( '#masthead' ).height(), toolbarOffset, mastheadOffset; if ( mastheadHeight > 48 ) { body.removeClass( 'masthead-fixed' ); } if ( body.is( '.header-image' ) ) { toolbarOffset = body.is( '.admin-bar' ) ? $( '#wpadminbar' ).height() : 0; mastheadOffset = $( '#masthead' ).offset().top - toolbarOffset; _window.on( 'scroll.basetheme', function() { if ( _window.scrollTop() > mastheadOffset && mastheadHeight < 49 ) { body.addClass( 'masthead-fixed' ); } else { body.removeClass( 'masthead-fixed' ); } } ); } } // Focus styles for menus. $( '.primary-navigation, .secondary-navigation' ).find( 'a' ).on( 'focus.basetheme blur.basetheme', function() { $( this ).parents().toggleClass( 'focus' ); } ); } ); /** * @summary Add or remove ARIA attributes. * Uses jQuery's width() function to determine the size of the window and add * the default ARIA attributes for the menu toggle if it's visible. * @since Basee 1.4 */ function onResizeARIA() { if ( 781 > _window.width() ) { button.attr( 'aria-expanded', 'false' ); menu.attr( 'aria-expanded', 'false' ); button.attr( 'aria-controls', 'primary-menu' ); } else { button.removeAttr( 'aria-expanded' ); menu.removeAttr( 'aria-expanded' ); button.removeAttr( 'aria-controls' ); } } _window .on( 'load.basetheme', onResizeARIA ) .on( 'resize.basetheme', function() { onResizeARIA(); } ); _window.load( function() { // Arrange footer widgets vertically. if ( $.isFunction( $.fn.masonry ) ) { $( '#footer-sidebar' ).masonry( { itemSelector: '.widget', columnWidth: function( containerWidth ) { return containerWidth / 4; }, gutterWidth: 0, isResizable: true, isRTL: $( 'body' ).is( '.rtl' ) } ); } // Initialize Featured Content slider. if ( body.is( '.slider' ) ) { $( '.featured-content' ).featuredslider( { selector: '.featured-content-inner > article', controlsContainer: '.featured-content' } ); } } ); $( document ).ready( function(){ /** * * Automatic apply OWL carousel */ $(".owl-carousel-play .owl-carousel").each( function(){ var config = { navigation : false, // Show next and prev buttons slideSpeed : 300, paginationSpeed : 400, pagination : $(this).data( 'pagination' ), autoHeight: true }; var owl = $(this); if( $(this).data('slide') == 1 ){ config.singleItem = true; }else { config.items = $(this).data( 'slide' ); } if ($(this).data('desktop')) { config.itemsDesktop = $(this).data('desktop'); } if ($(this).data('desktopsmall')) { config.itemsDesktopSmall = $(this).data('desktopsmall'); } if ($(this).data('desktopsmall')) { config.itemsTablet = $(this).data('tablet'); } if ($(this).data('tabletsmall')) { config.itemsTabletSmall = $(this).data('tabletsmall'); } if ($(this).data('mobile')) { config.itemsMobile = $(this).data('mobile'); } $(this).owlCarousel( config ); $('.left',$(this).parent()).click(function(){ owl.trigger('owl.prev'); return false; }); $('.right',$(this).parent()).click(function(){ owl.trigger('owl.next'); return false; }); } ); } ); } )( jQuery );