PageSourceSearch

https://www.emuaustralia.com/on/demandware.static/Sites-emuCA-Site/-/en_CA/v1790373997725/js/responsive.js

js emuaustralia.com collected 2026-09-26 06:52:16 UTC 13,724 bytes, 359 lines download raw bytes

1(function($,sr){
2
3  // debouncing function from John Hann
4  // http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
5    var debounce = function (func, threshold, execAsap) {
6    var timeout;
7
8    return function debounced () {
9        var obj = this, args = arguments;
10        function delayed () {
11            if (!execAsap)
12                func.apply(obj, args);
13                timeout = null;
14        };
15
16        if (timeout)
17            clearTimeout(timeout);
18        else if (execAsap)
19            func.apply(obj, args);
20
21        timeout = setTimeout(delayed, threshold || 500);
22    };
23  }
24    // smartresize
25    jQuery.fn[sr] = function(fn){  return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
26
27}(jQuery,'smartresize'));
28
29
30/*
31 * All java script logic for the mobile layout.
32 *
33 * The code relies on the jQuery JS library to be also loaded.
34 *
35 * The logic extends the JS namespace app.*
36 */
37(function(app, $, undefined) {
38	app.responsive = {
39		mobileLayoutWidth : 767,
40
41		init : function () {
42
43			$cache = {
44                wrapper: $('#wrapper'),
45                navigation: $('#navigation'),
46                topLevelNavigation: $('.menu-category .level-1'),
47                menuNavigation: $('.menu-navigation'),
48            };
49
50			// toggle menu element
51			$cache.navigation.find('.navigation-header')
52				.click(function(){
53					jQuery(this).siblings('.menu-category').toggle();
54				});
55
56			//handle click on responsive-mode
57			$cache.navigation.find('li.category-level-2,.menu-category>li')
58            .on('click',function(e){
59                //check if in mobile mode
60                if(jQuery(this).parents('.nav-stacked').length != 0) {
61                    //child tag <span> click handler
62                    if(jQuery(e.target).closest('span').length > 0 || $(e.target).hasClass('link-headers')) {
63                            e.preventDefault();
64                            if(jQuery(this).hasClass('level-1') || jQuery(this).children('a').hasClass('level-1')) {
65                                jQuery(this).find('span').first().toggleClass('icon-mobile-arrow-up icon-mobile-arrow-down');
66                                jQuery(this).children().siblings('div').toggleClass('onHide');
67                            } else {
68                                jQuery(this).find('span').first().toggleClass('icon-mobile-plus icon-mobile-minus');
69                                jQuery(this).children().siblings('.navbar-items').toggle();
70                            }
71
72                        } else {
73                            // parent tag <a> click handler
74                            if(jQuery(this).children('ul').is(':hidden')) {
75                                e.preventDefault();
76                                jQuery(this).find('span').first().toggleClass('icon-mobile-plus icon-mobile-minus');
77                                jQuery(this).children().siblings('.navbar-items').toggle();
78                            } else if($(e.target).closest('a').length == 0 || $(this).find('.menu-navigation').hasClass('onHide')) {
79                                jQuery(this).children().siblings('div').toggleClass('onHide');
80                                jQuery(this).find('span').first().toggleClass('icon-mobile-arrow-up icon-mobile-arrow-down');
81                            } else {
82                            return true;
83                        }
84                    }
85                    return false;
86                } else {
87                    return true;
88                }
89            });
90
91			//add onHide Class when ready
92			$cache.navigation.find('.menu-navigation').addClass('onHide');
93
94
95			// check onload to see if mobile enabled
96			if (app.responsive.isMobileLayout()) {
97				app.responsive.enableMobileComponents();
98			}
99
100            $cache.navigation.on('keyup', '.menu-category .level-1, .menu-navigation', function(e) {
101                var code = e.keyCode || e.which;
102                if (code === 27) { // ESC Keyboard
103                    var $parentItem = $(e.target).closest('.menu-category').find('.level-1.is-active');
104                    if ($parentItem) {
105                        $parentItem.focus();
106                        $cache.menuNavigation.removeClass('is-open');
107                        $cache.topLevelNavigation.removeClass('is-active');
108                    }
109                }
110            })
111
112            // handle focus in and out when navigate to navigation
113            $cache.topLevelNavigation.on('focusout', function() {
114                var self = this;
115                var menuNavigation = $(this).siblings('.menu-navigation');
116                setTimeout(function() {
117                    if ($(menuNavigation).has(document.activeElement).length == 0) {
118                        $(menuNavigation).removeClass('is-open');
119                        $(self).removeClass('is-active');
120                    }
121                }, 10);
122            }).on('focus', function() {
123                $cache.menuNavigation.removeClass('is-open');
124                $(this).siblings('.menu-navigation').addClass('is-open');
125                $(this).addClass('is-active');
126            });
127            
128            // handle focus out sub navigation menu
129            $cache.menuNavigation.on('focusout', function() {
130                var self = this;
131                var $topLevelNavigation = $(this).siblings('.level-1');
132                setTimeout(function() {
133                    if ($(self).has(document.activeElement).length == 0 && !$topLevelNavigation.is(':focus')) {
134                        $(self).removeClass('is-open');
135                        $topLevelNavigation.removeClass('is-active');
136                    }
137                }, 10);
138            });
139		},
140
141		isMobileLayout : function () {
142		    return $cache.wrapper.width() < this.mobileLayoutWidth;
143		},
144
145		enableMobileComponents : function ()
146		{
147			//app.responsive.enableMobileNav(); //amblique's function
148			//app.responsive.enableMobileMiniMenu();
149			app.responsive.disableSwiperPagination();
150			//my responsive navbar enable handler
151			//app.responsive.enableMobileNavBar();
152		},
153
154		disableMobileComponents : function ()
155		{
156			//app.responsive.disableMobileNav();
157			//app.responsive.disableMobileMiniMenu();
158			app.responsive.enableSwiperPagination();
159		},
160
161		enableMobileNavBar : function(){
162		    if(!$cache.navigation.find('.menu-category').hasClass('nav-stacked')){
163		        $cache.navigation.find('.menu-category').addClass('nav-stacked');
164		        $cache.navigation.find('.navbar-items').css({'display':'none'});
165		        $cache.navigation.find('.menu-category').hide()
166		    }
167
168		},
169
170
171        // build vertical, collapsable menu
172        enableMobileNav : function(){
173            $cache.navigation.find('.menu-category')
174                .hide()
175                .addClass('nav-stacked')
176                .children('li')
177                    .children('a')
178                        .click(function(){
179                            if( (jQuery(this).siblings().length > 0 ) && (!jQuery(this).siblings().is(":visible"))) {
180                                jQuery(this)
181                                    .append('<span>close</span>')
182                                    .children('span')
183                                        .click(function(){
184                                            jQuery(this).parent().siblings().hide();
185                                            jQuery(this).remove();
186                                            return false;
187                                        })
188                                    .parent().siblings().show();
189                                return false;
190                            }
191                        })
192        },
193
194		// revert to standard horizontal menu
195		disableMobileNav : function(){
196			$cache.navigation.find('.menu-category').show();
197			$cache.navigation.find('.menu-category').removeClass('nav-stacked');
198			$cache.navigation.find('.level-2').removeAttr('style');
199			//cache.navigation.find('.level-1 span').remove();
200			$cache.navigation.find('.navbar-items').removeAttr('style');
201			$cache.navigation.find('.menu-navigation').addClass('onHide');
202		},
203
204        disableSwiperPagination : function() {
205            $(".swiper-container").each(function() {
206                var $swiperComponent = $(this);
207                var swiperControl = $swiperComponent.data("swiper");
208                if (typeof (swiperControl) !== "undefined" &&
209                        swiperControl.params.pagination &&
210                        swiperControl.params.paginationClickable &&
211                        swiperControl.params.disablePaginationOnMobile) {
212                    swiperControl.params.paginationClickable = false;
213                    swiperControl.createPagination();
214                }
215            });
216        },
217
218        enableSwiperPagination : function() {
219            $(".swiper-container").each(function() {
220                var $swiperComponent = $(this);
221                var swiperControl = $swiperComponent.data("swiper");
222                if (typeof (swiperControl) !== "undefined" &&
223                        swiperControl.params.pagination &&
224                        !swiperControl.params.paginationClickable &&
225                        swiperControl.params.disablePaginationOnMobile) {
226                    swiperControl.params.paginationClickable = true;
227                    swiperControl.createPagination();
228                }
229            });
230        },
231
232		toggleGridWideTileView : function(){
233
234			/*	toggle grid/wide tile	*/
235			if(jQuery('.toggle-grid').length == 0)
236			{
237				/* On clickthrough and FSD don't have it, so I comment it.
238				jQuery('.results-hits').prepend('<a class="toggle-grid" href="'+location.href+'">+</a>');
239				jQuery('.toggle-grid').click(function(){
240					jQuery('.search-result-content').toggleClass('wide-tiles');
241					return false;
242				});
243				*/
244			}
245		},
246
247		enableMobileMiniMenu : function() {
248			$('.header-menu').removeClass('menu-utility');
249			$('.header-menu').addClass('mobile-mini-menu-content');
250			$('.header-menu').hide();
251		},
252
253		disableMobileMiniMenu : function() {
254			$('.header-menu').addClass('menu-utility');
255			$('.header-menu').removeClass('mobile-mini-menu-content');
256			$('.header-menu').hide();
257		},
258
259        updateSwiperControls : function() {
260            $(".swiper-container").each(function() {
261                var $swiperComponent = $(this);
262                var swiperControl = $swiperComponent.data("swiper");
263                if (swiperControl === undefined) {
264                    return;
265                }
266                if (swiperControl.params.responsiveReinit) {
267                    swiperControl.reInit(true);
268                    swiperControl.params.onlyExternal = swiperControl.slides.length == swiperControl.visibleSlides.length;
269                    swiperControl.params.slidesPerGroup = swiperControl.visibleSlides.length;
270                }
271                if ($swiperComponent.hasClass("product-swiper") && $swiperComponent.closest(".hidden-phone").length == 0) {
272                    if (app.responsive.isMobileLayout()) {
273                        swiperControl.params.slidesPerView = 2;
274                        swiperControl.params.slidesPerGroup = 2;
275                    }
276                    else {
277                        swiperControl.params.slidesPerView = $swiperComponent.data("slidesperview");
278                        swiperControl.params.slidesPerGroup = $swiperComponent.data("slidespergroup");
279                    }
280                    swiperControl.reInit(true);
281                }
282            });
283        }
284    }
285
286    var screenWidthFirstLoad = window.innerWidth;
287
288    function reloadPageWhenResize(widthFirstLoad , widthResize) {
289        if (widthFirstLoad < 768) {
290            if (widthResize >= 768) {
291                location.reload();
292            }
293        } else {
294            if (widthResize < 768) {
295                location.reload();
296            }
297        }
298        screenWidthFirstLoad = widthResize;
299    }
300
301    $(document).ready(function(){
302        app.responsive.init();
303        var _wasMobileLayout = app.responsive.isMobileLayout();
304        var screenWidth;
305
306        $(window).smartresize(function(){
307            if (app.responsive.isMobileLayout()) {
308                app.responsive.enableMobileComponents();
309            } else {
310                app.responsive.disableMobileComponents();
311            }
312
313            var isMobileLayout = app.responsive.isMobileLayout();
314            if (_wasMobileLayout && !isMobileLayout) {
315                // Do Small Desktop/ Large Desktop things
316                _wasMobileLayout = false;
317                app.responsive.updateSwiperControls();
318            } else if (!_wasMobileLayout && isMobileLayout) {
319                // Do Mobile things
320                _wasMobileLayout = true;
321                app.responsive.updateSwiperControls();
322            }
323
324            screenWidth = window.innerWidth;
325            reloadPageWhenResize(screenWidthFirstLoad , screenWidth)
326        });
327
328        InitMobileMiniMenu();
329    });
330
331}(window.app = window.app || {}, jQuery));
332
333
334function InitMobileMiniMenu() {
335	$('.mobile-mini-menu').toggle(function() {
336		$('.mobile-mini-menu').addClass('expanded');
337		$('.header-menu').addClass('mobile-mini-menu-content');
338		$('.header-menu').slideDown('slow', function() {
339		// Animation complete.
340		});
341		$('#header').animate({
342			height: '+='+amblique.responsive.menuHeight,
343			}, 458, 'swing', function() {
344		});
345	}, function() {
346		$('.mobile-mini-menu').removeClass('expanded');
347		$('.header-menu').slideUp('slow', function() {
348		});
349
350		$('#header').animate({
351			height: '-='+amblique.responsive.menuHeight,
352		}, 458, 'swing', function() {
353		});
354	});
355};
356
357
358
359

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.