1jQuery(function($) { 2 3 // Check your elements 4 $.fn.checkNavPositioning = function($el, $nav, scrollClass) { 5 var navHeight = $nav.outerHeight(); 6 7 if(((this.outerHeight() - $(window).scrollTop()) < $nav.outerHeight()) && !$el.hasClass(scrollClass)) { 8 $el.addClass(scrollClass); 9 $el.css('padding-top', navHeight); 10 } else if((this.outerHeight() >= $(window).scrollTop()) && $el.hasClass(scrollClass)) { 11 $el.removeClass(scrollClass); 12 $el.css('padding-top', 0); 13 } 14 } 15 16 // Mobile sidebars 17 $.fn.expandableSidebar = function(expandedClass) { 18 var $me = this; 19 20 $me.on('click', function() { 21 if(!$me.hasClass(expandedClass)) { 22 $me.addClass(expandedClass); 23 } else { 24 $me.removeClass(expandedClass); 25 } 26 }); 27 } 28 29 // Interval loop 30 $.fn.intervalLoop = function(condition, action, duration, limit) { 31 var counter = 0; 32 var looper = setInterval(function(){ 33 if (counter >= limit || $.fn.checkIfElementExists(condition)) { 34 clearInterval(looper); 35 } else { 36 action(); 37 counter++; 38 } 39 }, duration); 40 } 41 42 // Check if element exists 43 $.fn.checkIfElementExists = function(selector) { 44 return $(selector).length; 45 } 46 47 48 var centoController = { 49 init: function(opts) { 50 var base = this; 51 52 // Check content positioning 53 if($(window).width() > 767) { 54 $('.cento-header').checkNavPositioning($('body'), $('.nav-wrap'), 'affix'); 55 } 56 57 // Add classes to elements 58 base._addClasses(); 59 base._attachEvents(); 60 61 setTimeout(function() { 62 $.fn.intervalLoop('', base._checkCartItems, 800, 3); 63 }, 500); 64 }, 65 66 _addClasses: function() { 67 var base = this; 68
69 // Add class to nav items with subnav 70 $('.wsite-menu-default').find('li.wsite-menu-item-wrap').each(function(){ 71 var $me = $(this); 72 73 if($me.children('.wsite-menu-wrap').length > 0) { 74 75 $me.addClass('has-submenu'); 76 $('<span class="icon-caret"></span>').insertAfter($me.children('a.wsite-menu-item')); 77 } 78 }); 79 80 // Add class to subnav items with subnav 81 $('.wsite-menu').find('li.wsite-menu-subitem-wrap').each(function(){ 82 var $me = $(this); 83 84 if($me.children('.wsite-menu-wrap').length > 0) { 85 86 $me.addClass('has-submenu'); 87 $('<span class="icon-caret"></span>').insertAfter($me.children('a.wsite-menu-subitem')); 88 } 89 }); 90 91 // Keep subnav open if submenu item is active 92 $('li.wsite-menu-subitem-wrap.wsite-nav-current').parents('.wsite-menu-wrap').addClass('open'); 93 94 // Add placeholder text to inputs 95 $('.wsite-form-sublabel').each(function(){ 96 var sublabel = $(this).text(); 97 $(this).prev('.wsite-form-input').attr('placeholder', sublabel); 98 }); 99 100 // Add fullwidth class to gallery thumbs if less than 6 101 $('.imageGallery').each(function(){ 102 if ($(this).children('div').length <= 6) { 103 $(this).children('div').addClass('fullwidth-mobile'); 104 } 105 }); 106 }, 107 108 _checkCartItems: function() { 109 var base = this; 110 111 if($('#wsite-mini-cart').find('li.wsite-product-item').length > 0) { 112 $('body').addClass('cart-full'); 113 } else { 114 $('body').removeClass('cart-full'); 115 } 116 }, 117 118 _moveLogin: function() { 119 var loginDetach = $('#member-login').detach(); 120 $('.mobile-nav .wsite-menu-default > li:last-child').after(loginDetach); 121 }, 122 123 _attachEvents: function() { 124 var base = this; 125 126 // Nav toggle 127 $('label.hamburger').on('click', function() { 128 if(!$('body').hasClass('nav-open')) { 129 $('body').addClass('nav-open'); 130 } else { 131 $('body').removeClass('nav-open'); 132 } 133 }); 134 135 // Move cart + login 136 if ($(window).width() <= 992) { 137 $.fn.intervalLoop('.mobile-nav #member-login', base._moveLogin, 800, 5); 138 } 139 140 // Window scroll 141 $(window).on('scroll', function(){ 142 // Affix nav 143 if($(window).width() > 767) { 144 $('.cento-header').checkNavPositioning($('body'), $('.nav-wrap'), 'affix'); 145 } 146 }); 147 148 // Subnav toggle 149 $('li.has-submenu span.icon-caret').on('click', function() { 150 var $me = $(this); 151 152 if($me.siblings('.wsite-menu-wrap').hasClass('open')) { 153 $me.siblings('.wsite-menu-wrap').removeClass('open'); 154 } else { 155 $me.siblings('.wsite-menu-wrap').addClass('open'); 156 } 157 }); 158 159 160 // Store category dropdown 161 $('.wsite-com-sidebar').expandableSidebar('sidebar-expanded'); 162 163 // Search filters dropdown 164 $('#wsite-search-sidebar').expandableSidebar('sidebar-expanded'); 165 166 // Init fancybox swipe on mobile 167 if ('ontouchstart' in window) { 168 $('body').on('click', 'a.w-fancybox', function() { 169 base._initSwipeGallery(); 170 }); 171 } 172 173 $('.wsite-product-button, #wsite-com-product-add-to-cart, .wsite-product-item .wsite-remove-button').on('click', function(){ 174 setTimeout(function() { base._checkCartItems(); }, 800); 175 }); 176 }, 177 178 _initSwipeGallery: function() { 179 var base = this; 180 181 setTimeout(function(){ 182 var touchGallery = document.getElementsByClassName('fancybox-wrap')[0]; 183 var mc = new Hammer(touchGallery); 184 mc.on("panleft panright", function(ev) { 185 if (ev.type == "panleft") { 186 $("a.fancybox-next").trigger("click"); 187 } else if (ev.type == "panright") { 188 $("a.fancybox-prev").trigger("click"); 189 } 190 base._initSwipeGallery(); 191 }); 192 }, 500); 193 } 194 } 195 196 $(document).ready(function(){ 197 centoController.init(); 198 }); 199 200});
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.