1/* global ecommerce_plus_l10n */ 2/** 3 * Theme functions file. 4 * 5 * Contains handlers for navigation and widget area. 6 */ 7 8(function( $ ) { 9 var masthead, menuToggle, siteNavContain, siteNavigation; 10 11 $(document).ready(function() { 12 13 //Preloader 14 preloaderFadeOutTime = 500; 15 function hidePreloader() { 16 var preloader = $('.preloader-wrap'); 17 preloader.fadeOut(preloaderFadeOutTime); 18 } 19 hidePreloader(); 20 21 $(window).scroll(function () { 22 if( $('#theme-header')) { 23 if ($(window).scrollTop() > 280) { 24 25 $('#theme-header').addClass('header-ticky-menu'); 26 } 27 if ($(window).scrollTop() < 281) { 28 $('#theme-header').removeClass('header-ticky-menu'); 29 } 30 } 31 }); 32 }); 33 34 function initMainNavigation( container ) { 35 36 if (typeof ecommerce_plus_l10n !== 'undefined') { 37 38 // Add dropdown toggle that displays child menu items. 39 var dropdownToggle = $( '<button />', { 'class': 'dropdown-toggle', 'aria-expanded': false }) 40 .append( ecommerce_plus_l10n.icon ) 41 .append( $( '<span />', { 'class': 'screen-reader-text', text: ecommerce_plus_l10n.expand }) ); 42 43 container.find( '.menu-item-has-children > a, .page_item_has_children > a' ).after( dropdownToggle ); 44 45 // Set the active submenu dropdown toggle button initial state. 46 container.find( '.current-menu-ancestor > button' ) 47 .addClass( 'toggled-on' ) 48 .attr( 'aria-expanded', 'true' ) 49 .find( '.screen-reader-text' ) 50 .text( ecommerce_plus_l10n.collapse ); 51 // Set the active submenu initial state. 52 container.find( '.current-menu-ancestor > .sub-menu' ).addClass( 'toggled-on' ); 53 54 container.find( '.dropdown-toggle' ).click( function( e ) { 55 var _this = $( this ), 56 screenReaderSpan = _this.find( '.screen-reader-text' ); 57 58 e.preventDefault(); 59 _this.toggleClass( 'toggled-on' ); 60 _this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' ); 61 62 _this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' ); 63 64 screenReaderSpan.text( screenReaderSpan.text() === ecommerce_plus_l10n.expand ? ecommerce_plus_l10n.collapse : ecommerce_plus_l10n.expand ); 65 }); 66 } 67 } 68 69 initMainNavigation( $( '.main-navigation' ) ); 70 71 masthead = $( '#masthead' ); 72 menuToggle = masthead.find( '.menu-toggle' ); 73 siteNavContain = masthead.find( '.main-navigation' ); 74 siteNavigation = masthead.find( '.main-navigation > div > ul' ); 75 76 // Enable menuToggle. 77 (function() { 78 79 // Return early if menuToggle is missing. 80 if ( ! menuToggle.length ) { 81 return; 82 } 83 84 // Add an initial value for the attribute. 85 menuToggle.attr( 'aria-expanded', 'false' ); 86 87 menuToggle.on( 'click.wp_theme_prefix', function() { 88 siteNavContain.toggleClass( 'toggled-on' ); 89 90 $( this ).attr( 'aria-expanded', siteNavContain.hasClass( 'toggled-on' ) ); 91 }); 92 })(); 93 94 // Fix sub-menus for touch devices and better focus for hidden submenu items for accessibility. 95 (function() { 96 if ( ! siteNavigation.length || ! siteNavigation.children().length ) { 97 return; 98 } 99 100 // Toggle `focus` class to allow submenu access on tablets. 101 function toggleFocusClassTouchScreen() { 102 if ( 'none' === $( '.menu-toggle' ).css( 'display' ) ) { 103 104 $( document.body ).on( 'touchstart.wp_theme_prefix', function( e ) { 105 if ( ! $( e.target ).closest( '.main-navigation li' ).length ) { 106 $( '.main-navigation li' ).removeClass( 'focus' ); 107 } 108 }); 109 110 siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' ) 111 .on( 'touchstart.wp_theme_prefix', function( e ) { 112 var el = $( this ).parent( 'li' ); 113 114 if ( ! el.hasClass( 'focus' ) ) { 115 e.preventDefault(); 116 el.toggleClass( 'focus' ); 117 el.siblings( '.focus' ).removeClass( 'focus' ); 118 } 119 }); 120 121 } else { 122 siteNavigation.find( '.menu-item-has-children > a, .page_item_has_children > a' ).unbind( 'touchstart.wp_theme_prefix' ); 123 } 124 } 125 126 if ( 'ontouchstart' in window ) { 127 $( window ).on( 'resize.wp_theme_prefix', toggleFocusClassTouchScreen ); 128 toggleFocusClassTouchScreen(); 129 } 130 131 siteNavigation.find( 'a' ).on( 'focus.wp_theme_prefix blur.wp_theme_prefix', function() { 132 $( this ).parents( '.menu-item, .page_item' ).toggleClass( 'focus' ); 133 }); 134 })(); 135})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.