PageSourceSearch

https://www.finlandiatalo.fi/wp-content/plugins/megamenu-pro/assets/public.js?ver=2.3.1

js finlandiatalo.fi collected 2026-09-24 20:06:04 UTC 25,942 bytes, 712 lines download raw bytes

1/*jslint browser: true, white: true */
2/*global console,jQuery,megamenu,window,navigator*/
3
4/**
5 * EDD Ajax Cart
6 */
7(function($) {
8    "use strict";
9
10    $(function() {
11        $('body').on('edd_cart_item_added', function(event, data) {
12            $('.mega-menu-edd-cart-total').html(data.total);
13            $('.mega-menu-edd-cart-count').html(data.cart_quantity);
14        });
15    });
16
17    $(".max-mega-menu").on("after_mega_menu_init", function() {
18        $('li.mega-menu-megamenu').on('open_panel', function() {
19            // reset default
20            var placeholder = $(this).closest(".mega-menu-megamenu").find(".widget_maxmegamenu_image_swap img.mega-placeholder");
21            var default_src = placeholder.attr('data-default-src');
22            var default_alt = placeholder.attr('data-default-alt');
23            placeholder.attr('src', default_src);
24            placeholder.attr('alt', default_alt);
25
26            // preload
27            $('.mega-sub-menu [data-image-swap-url]', $(this) ).not(['data-preloaded']).each( function() {
28                $('<img/>')[0].src = $(this).attr('data-image-swap-url');
29                $(this).attr('data-preloaded', 'true');
30            });
31        });
32
33        if ( ! $.isFunction($.fn.hoverIntent) ) {
34            return;
35        }
36        
37        $('.mega-sub-menu [data-image-swap-url]').hoverIntent({
38            over: function () {
39                var placeholder = $(this).closest(".mega-menu-megamenu").find(".widget_maxmegamenu_image_swap img.mega-placeholder");
40                var new_src = $(this).attr('data-image-swap-url');
41                var new_alt = $(this).is("[data-image-swap-alt]") ? $(this).attr('data-image-swap-alt') : "";
42                placeholder.attr('src', new_src);
43                placeholder.attr('alt', new_alt);
44            },
45            out: function() {}
46        });
47    });
48
49})(jQuery);
50
51/**
52 * Searchbox jQuery plugin
53 */
54(function($) {
55    "use strict";
56
57    $.maxmegamenu_searchbox = function(form, options) {
58
59        var plugin = this;
60        var form = $(form);
61        var $menu = form.parents('.max-mega-menu');
62        var $wrap = $menu.parent();
63        var breakpoint = $menu.attr('data-breakpoint');
64        var input = $('input[type=text]', form);
65        var icon = $('.search-icon', form);
66
67        plugin.isDesktopView = function() {
68            return Math.max(window.outerWidth, $(window).width()) >= breakpoint; // account for scrollbars
69        };
70
71        plugin.monitorView = function() {
72            if (typeof $menu.data("view") === 'undefined') {
73                if (plugin.isDesktopView()) {
74                    $menu.data("view", "desktop");
75                } else {
76                    $menu.data("view", "mobile");
77                }
78            }
79
80            plugin.checkWidth();
81
82            $(window).resize(function() {
83                plugin.checkWidth();
84            });
85        };
86
87        plugin.checkWidth = function() {
88            var expanding_search = $("li.mega-menu-item .mega-search.expand-to-left input[type=text], li.mega-menu-item .mega-search.expand-to-right input[type=text]", $menu);
89
90            if ( $menu.data("view") === "mobile" ) {
91                var placeholder = expanding_search.attr('data-placeholder');
92                expanding_search.attr('placeholder', placeholder);
93            }
94
95            if ( $menu.data("view") === "desktop" ) {
96                expanding_search.attr('placeholder', '');
97            }
98        };
99
100        plugin.close_search = function(moveFocus = true) {
101            $menu.triggerHandler("mmm:closeSearch");
102            input.val("");
103            input.attr('placeholder', '');
104            input.attr('tabindex', '-1');
105            form.removeClass('mega-search-open');
106            form.addClass('mega-search-closed');
107            icon.attr('aria-expanded', 'false');
108
109            if (moveFocus) {
110                icon.trigger("focus");
111            }
112        }
113
114        plugin.open_search = function() {
115            $menu.triggerHandler("mmm:openSearch");
116            input.attr('placeholder', input.attr('data-placeholder'));
117            input.attr('tabindex', '0');
118            form.removeClass('mega-search-closed');
119            form.addClass('mega-search-open');
120            icon.attr('aria-expanded', 'true');
121            input.trigger("focus");
122        }
123
124        plugin.detect_background_click = function() {
125            var dragging = false;
126
127            $(document).on({
128                "touchmove": function(e) { dragging = true; },
129                "touchstart": function(e) { dragging = false; }
130            });
131
132            $(document).on("click touchend", function(e) { // hide menu when clicked away from
133                if ( form.parent().hasClass('mega-static') ) {
134                    return;
135                }
136                if ( ! dragging && ! $(e.target).closest(".max-mega-menu li").length && ! $(e.target).closest(".mega-menu-toggle").length ) {
137                    plugin.close_search(false);
138                }
139                dragging = false;
140            });
141        }
142
143        plugin.init_replacements_search = function() {
144            if ( $menu.data("view") === "mobile" ) {
145                input.attr('tabindex', '0');
146
147                $(".search-icon", $menu).on('click', function(e) {
148                    $(this).parents(".mega-search").submit();
149                });
150            }
151
152            if ( $menu.data("view") === "desktop" ) {
153                input.on('blur', function(e) {
154                    if ( $menu.parent().hasClass("mega-keyboard-navigation") && input.val() == '' && ! form.parent().hasClass('mega-static') && form.hasClass('mega-search-open') ) {
155                        plugin.close_search();
156                    }
157                });
158
159                icon.on('keypress click', function(e) {
160                    var enter_key = 13;
161                    var space_key = 32;
162
163                    if (e.which === enter_key || e.which === space_key || e.type === 'click') {
164                        e.preventDefault();
165
166                        if (form.parent().hasClass('mega-static') ) {
167                            form.submit();
168                            return;
169                        }
170
171                        if ( input.val() != '' ) {
172                            form.submit();
173                            return;
174                        }
175
176                        if ( form.hasClass('mega-search-open') ) {
177                            plugin.close_search();
178                            return;
179                        }
180
181                        if ( form.hasClass('mega-search-closed') ) {
182                            plugin.open_search();
183                            return;
184                        }
185                    }
186                });
187
188                $menu.on('keydown', function(e) {
189                    var escape_key = 27;
190
191                    if (e.which === escape_key) {
192                        if (! form.parent().hasClass('mega-static') && form.hasClass('mega-search-open') ) {
193                            plugin.close_search();
194                            return;
195                        }
196                    }
197                });
198            }
199        };
200
201        plugin.monitorView();
202        plugin.init_replacements_search();
203        plugin.detect_background_click();
204    };
205
206    $.fn.maxmegamenu_searchbox = function(options) {
207        return this.each(function() {
208            if (undefined === $(this).data('maxmegamenu_searchbox')) {
209                var plugin = new $.maxmegamenu_searchbox(this, options);
210                $(this).data('maxmegamenu_searchbox', plugin);
211            }
212        });
213    };
214
215    $(".max-mega-menu").on("after_mega_menu_init", function() {
216        $(".mega-search", this).maxmegamenu_searchbox();
217    });
218})(jQuery);
219
220
221/**
222 * Searchbox jQuery plugin
223 */
224(function($) {
225    "use strict";
226
227    $.maxmegamenu_toggle_searchbox = function(form, options) {
228
229        var plugin = this;
230        var form = $(form);
231        var $wrap = form.parents('.mega-menu-wrap');
232        var input = $("input[type=text]", form);
233        var icon = $(".search-icon", form);
234        
235        plugin.open_search = function() {
236            input.attr('placeholder', input.attr('data-placeholder'));
237            form.removeClass('mega-search-closed');
238            form.addClass('mega-search-open');
239        }
240
241        plugin.close_search = function() {
242            input.attr('placeholder', '');
243            form.removeClass('mega-search-open');
244            form.addClass('mega-search-closed');
245        }
246
247        plugin.init_toggle_search = function() {
248
249            input.val("");
250
251            input.on('focus', function(e) {
252                if (! form.parent().hasClass('mega-static') && form.hasClass('mega-search-closed') && $wrap.hasClass('mega-keyboard-navigation') ) {
253                    plugin.open_search();
254                }
255            });
256
257            input.on('blur', function(e) {
258                if ( ! form.parent().hasClass('mega-static') && form.hasClass('mega-search-open') && $wrap.hasClass('mega-keyboard-navigation') ) {
259                    plugin.close_search();
260                }
261            });
262
263            icon.on('click', function(e) {
264                if (form.hasClass('static') ) {
265                    if ( input.attr('required') == 'required' && input.val() == "" ) {
266                        return;
267                    } else {
268                        form.submit();
269                    }
270                } else if (form.hasClass('mega-search-closed')) {
271                    input.focus();
272                    plugin.open_search();
273                } else if ( input.val() == '' ) {
274                    plugin.close_search();
275                } else {
276                    form.submit();
277                }
278            });
279
280        };
281
282        plugin.init_toggle_search();
283
284    };
285
286    $.fn.maxmegamenu_toggle_searchbox = function(options) {
287        return this.each(function() {
288            if (undefined === $(this).data('maxmegamenu_toggle_searchbox')) {
289                var plugin = new $.maxmegamenu_toggle_searchbox(this, options);
290                $(this).data('maxmegamenu_toggle_searchbox', plugin);
291            }
292        });
293    };
294
295    $(function() {
296        $(".mega-menu-toggle .mega-search").maxmegamenu_toggle_searchbox();
297    });
298})(jQuery);
299
300/**
301 * Sticky jQuery Plugin
302 */
303(function($) {
304
305    "use strict";
306
307    $.maxmegamenu_sticky = function(menu, options) {
308        var plugin = this;
309        var $menu = $(menu);
310        var $wrap = $menu.parent();
311        var breakpoint = $menu.attr('data-breakpoint');
312        var sticky_on_mobile = $menu.attr('data-sticky-mobile');
313        var sticky_on_desktop = $menu.attr('data-sticky-desktop');
314        var sticky_expand = $menu.attr('data-sticky-expand');
315        var sticky_expand_mobile = $menu.attr('data-sticky-expand-mobile');
316        var sticky_offset = isNaN(parseInt($menu.attr('data-sticky-offset'))) ? 0 : parseInt($menu.attr('data-sticky-offset'));
317        var sticky_hide_until_scroll_up = $menu.attr('data-sticky-hide');
318        var sticky_hide_until_scroll_up_tolerance = isNaN(parseInt($menu.attr('data-sticky-hide-tolerance'))) ? 0 : parseInt($menu.attr('data-sticky-hide-tolerance'));
319        var sticky_hide_until_scroll_up_offset = isNaN(parseInt($menu.attr('data-sticky-hide-offset'))) ? 0 : parseInt($menu.attr('data-sticky-hide-offset'));
320        var sticky_transition = $menu.attr('data-sticky-transition');
321        var sticky_menu_offset_top;
322        var sticky_menu_offset_left;
323        var sticky_menu_width;
324        var sticky_menu_width_round_up;
325        var sticky_menu_height;
326        var is_stuck = false;
327        var admin_bar_height = 0;
328        var last_scroll_top = 0;
329        var saved_scroll_top = 0;
330        var is_vertical = $menu.hasClass('mega-menu-vertical') || $menu.hasClass('mega-menu-accordion');
331
332        plugin.isDesktopView = function() {
333            return Math.max(window.outerWidth, $(window).width()) >= breakpoint; // account for scrollbars
334        };
335
336        var sticky_hide_until_scroll_up_enabled = function() {
337            return $menu.hasClass('mega-menu-horizontal') && sticky_hide_until_scroll_up == "true";
338        }
339
340        var sticky_enabled = function() {
341            if ( plugin.isDesktopView() ) {
342                return sticky_on_desktop === 'true';
343            } else {
344                return sticky_on_mobile === 'true';
345            }
346
347            return false;
348        };
349
350        plugin.calculate_menu_position = function() {
351            sticky_menu_offset_top = $wrap.offset().top;
352
353            if ($('body').hasClass('admin-bar') && $("#wpadminbar").is(":visible") && $("#wpadminbar").css('top') == '0px' && $("#wpadminbar").css('position') == 'fixed') {
354                admin_bar_height = $('#wpadminbar').height();
355                sticky_menu_offset_top = sticky_menu_offset_top - admin_bar_height;
356            }
357
358            if (sticky_offset < 0) {
359                sticky_menu_offset_top = sticky_menu_offset_top + sticky_offset;
360            } else {
361                sticky_menu_offset_top = sticky_menu_offset_top - sticky_offset;
362            }
363
364            sticky_menu_offset_left = $menu.parent().offset().left;
365            sticky_menu_width = window.getComputedStyle($wrap[0]).width;
366            sticky_menu_width_round_up = Math.ceil(parseFloat(sticky_menu_width));
367            sticky_menu_height = $wrap.height();
368        };
369
370        plugin.stick_menu = function() {
371            is_stuck = true;
372
373            var total_offset = parseInt(admin_bar_height, 10) + parseInt(sticky_offset, 10);
374
375            if (sticky_offset < 0) {
376                total_offset = parseInt(admin_bar_height, 10);
377            }
378
379            var placeholder = $("<div />").addClass("mega-sticky-wrapper").css({
380                'height' : sticky_menu_height + 'px',
381                'position' :'static'
382            });
383
384            $wrap.addClass('mega-sticky').wrap(placeholder).css({
385                'margin-top' : total_offset + 'px'
386            });
387
388            $("body").addClass($menu.attr("id") + "-mega-sticky");
389
390            $menu.css({
391                'max-width' : sticky_menu_width_round_up + 'px'
392            });
393
394            if (sticky_menu_offset_left > 0) {
395                $menu.css({
396                    'margin-left' : sticky_menu_offset_left + 'px'
397                });
398            }
399
400            if (is_vertical || sticky_expand === 'false') {
401                $wrap.css({
402                    'margin-left' : '0',
403                    'margin-right' : '0',
404                    'width' : sticky_menu_width_round_up + 'px',
405                    'left' : sticky_menu_offset_left + 'px'
406                });
407
408                $menu.css({
409                    'margin-left' : '0'
410                });
411            }
412
413            if ( $(window).width() <= breakpoint ) {
414                $wrap.css({
415                    'width' : sticky_menu_width_round_up + 'px'
416                });
417
418                if (sticky_expand_mobile === 'true') {
419                   $wrap.css({
420                        'margin-left' : '',
421                        'margin-right' : '',
422                        'width' : '',
423                        'left' : ''
424                    });
425
426                    $menu.css({
427                        'max-width' : '',
428                        'margin-left' : '',
429                        'width' : '',
430                        'left' : ''
431                    });
432                }
433            }
434
435            $wrap.delay(0).queue(function(next){
436                $(this).addClass('mega-stuck');
437                next();
438            });
439        };
440
441        plugin.unstick_menu = function(doing_resize) {
442            doing_resize = doing_resize || false;
443            is_stuck = false;
444            
445            $wrap.removeClass('mega-sticky').removeClass('mega-hide').css({
446                'margin' : '',
447                'width' : '',
448                'left': ''
449            });
450
451            $("body").removeClass($menu.attr("id") + "-mega-sticky");
452
453            if ( ! doing_resize ) { // this class is used for the height transition, do not remove it if we are simply resizing the window
454                $wrap.delay(0).queue(function(next){
455                    $(this).removeClass('mega-stuck');
456                    next();
457                });
458            }
459
460            $menu.css({
461                'margin-left' : '',
462                'max-width' : '',
463                'left' : '',
464                'width' : ''
465            });
466            
467            if ( $(window).width() <= breakpoint ) {
468                $menu.data('maxmegamenu').toggleBarForceWidth();
469            }
470
471            if (sticky_transition == 'true' && ! doing_resize ) {
472                var delay = 250; // allows the transiton to complete before unwrapping the menu
473            } else {
474                var delay = 0;
475            }
476
477            $wrap.delay(delay).queue(function(next){
478                $(this).unwrap();
479                next();
480            });
481        };
482
483        plugin.mega_sticky_on_scroll = function(){
484            if ( ! sticky_enabled() ) {
485                return;
486            }
487
488            var scroll_top = $(window).scrollTop();
489
490            if (scroll_top > sticky_menu_offset_top) {
491                if (!is_stuck) {
492                    plugin.stick_menu();
493                }
494            } else {
495                if (is_stuck) {
496                    plugin.unstick_menu();
497                }
498            }
499        };
500
501        var mega_hide_on_scroll_up = function() {
502            if (sticky_hide_until_scroll_up_enabled()) {
503
504                if ( $menu.data("view") === "mobile" && $('.mega-menu-toggle', $wrap).hasClass('mega-menu-open') ) {
505                    return;
506                }
507
508                var scroll_top = $(window).scrollTop();
509                
510                if ( scroll_top < sticky_hide_until_scroll_up_offset ) {
511                    $wrap.removeClass('mega-hide');
512                    $("body").removeClass($menu.attr("id") + "-mega-hide");
513                }
514                
515                saved_scroll_top = last_scroll_top;
516
517                if (scroll_top < last_scroll_top) {
518                    // scroll up
519                    if (saved_scroll_top - scroll_top > sticky_hide_until_scroll_up_tolerance) {
520                        $wrap.removeClass('mega-hide');
521                        $("body").removeClass($menu.attr("id") + "-mega-hide");
522                    }
523                } else {
524                    // scroll down
525                    if (is_stuck && scroll_top - saved_scroll_top > sticky_hide_until_scroll_up_tolerance) {
526                        $wrap.addClass('mega-hide');
527                        $("body").addClass($menu.attr("id") + "-mega-hide");
528                    }
529                }
530
531                last_scroll_top = scroll_top;
532            }
533        }
534
535        plugin.mega_sticky_on_resize = function() {
536            if ($('input', $wrap).is(':focus')) {
537                return;
538            }
539
540            if ( sticky_enabled() ) {
541                if (is_stuck) {
542                    plugin.unstick_menu(true);
543                    plugin.calculate_menu_position();
544                    plugin.stick_menu();
545                } else {
546                    plugin.calculate_menu_position();
547                    plugin.mega_sticky_on_scroll();
548                }
549            } else {
550                if (is_stuck) {
551                    plugin.unstick_menu();
552                }
553            }
554        };
555
556        plugin.init = function() {
557            plugin.calculate_menu_position();
558            plugin.mega_sticky_on_scroll();
559
560            $('.mega-menu-accordion li.mega-menu-item').on('open_panel', function() {
561                plugin.calculate_menu_position();
562            });
563
564            var $window = $(window);
565
566            $window.scroll(function() {
567                 plugin.mega_sticky_on_scroll();
568                 mega_hide_on_scroll_up();
569            });
570
571            var windowWidth = $window.width();
572            var resizeTimer;
573
574            $window.resize(function() {
575                clearTimeout(resizeTimer);
576                resizeTimer = setTimeout(function(){    
577                    windowWidth = $window.width();
578                    plugin.mega_sticky_on_resize();
579                }, 100);
580            });
581        };
582
583        plugin.init();
584    };
585
586    $.fn.maxmegamenu_sticky = function(options) {
587
588        return this.each(function() {
589            if (undefined === $(this).data('maxmegamenu_sticky')) {
590                var plugin = new $.maxmegamenu_sticky(this, options);
591                $(this).data('maxmegamenu_sticky', plugin);
592            }
593        });
594
595    };
596
597    $(window).on('load', function (e) {
598        $(".mega-menu[data-sticky-enabled]").maxmegamenu_sticky();
599    });
600
601})(jQuery);
602
603/**
604 * Handle tabbed functionality
605 */
606(function($) {
607    $(function() {
608
609        var calculate_tabbed_sub_menu_widths = function( menu_item ) {
610            var menu = menu_item.parents('.max-mega-menu');
611
612            if( $(menu.attr('data-panel-inner-width')).length > 0 ) {
613                if ( menu.data("view") === "desktop" ) {
614                    $('> ul.mega-sub-menu', menu_item).each(function() {
615                        var tab_content = $(this);
616                        var parent_submenu_content_width = parseInt(tab_content.width());
617                        var parent_submenu_left_padding = parseInt(tab_content.css('paddingLeft'));
618                        var tabs_width = $(this).find('a.mega-menu-link').first().outerWidth();
619
620                        $('> li.mega-menu-item > ul.mega-sub-menu', $(this)).each(function() {
621                            $(this).css('width', parent_submenu_content_width - tabs_width + 'px');
622                            $(this).css('left', parent_submenu_left_padding + tabs_width + 'px'); 
623                        });
624                    });
625                } else {
626                    $('> ul.mega-sub-menu > li.mega-menu-item > ul.mega-sub-menu', menu_item).each(function() {
627                        $(this).css('width', '');
628                        $(this).css('left', ''); 
629                    });
630                }
631            }
632        }
633
634        var calculate_tabbed_sub_menu_heights = function( menu_item ) {
635
636            var menu = menu_item.parents('.max-mega-menu');
637            var max_height = 0;
638
639            if ( menu.data("view") === "desktop" ) {
640
641                $('> ul.mega-sub-menu', menu_item).css('minHeight', '');
642                
643                $('> ul.mega-sub-menu > li.mega-menu-item > ul.mega-sub-menu', menu_item).each(function() {
644                    var tab_content = $(this);
645                    var this_height = parseInt(tab_content.css('height'));
646
647                    if (this_height > max_height) {
648                        max_height = this_height;
649                    }
650                });
651
652                var border_top_width = parseInt($('> ul.mega-sub-menu', menu_item).css('borderTopWidth'),10);
653                var border_bottom_width = parseInt($('> ul.mega-sub-menu', menu_item).css('borderBottomWidth'),10);
654                
655                $('> ul.mega-sub-menu', menu_item).css('minHeight', max_height + border_bottom_width + border_top_width);
656            } else {
657                $('> ul.mega-sub-menu', menu_item).css('minHeight', '');
658            }
659        }
660
661        var $window = $(window);
662
663        var windowWidth = $window.width();
664
665        $window.resize(function() {
666            if ($window.width() != windowWidth) {
667                calculate_tabbed_sub_menu_widths($('li.mega-menu-tabbed'));
668                calculate_tabbed_sub_menu_heights($('li.mega-menu-tabbed'));
669            }            
670        });
671
672        $('li.mega-menu-tabbed, li.mega-menu-tabbed li.mega-collapse-children').on('open_panel', function() {
673            var menu = $(this).parents('.max-mega-menu');
674            var menu_item = $(this).closest(".mega-menu-tabbed");
675
676            calculate_tabbed_sub_menu_widths( menu_item );
677
678            $(">
678 ul.mega-sub-menu", $(this)).promise().done(function(){ // wait until slide animation has completed
679                calculate_tabbed_sub_menu_heights( menu_item );
680            });
681
682            if ( menu.data('view') == 'desktop' ) {
683                if ($('> ul.mega-sub-menu > li.mega-menu-item-has-children.mega-toggle-on', menu_item).length == 0 ) {
684                    
685
686                    if ( $('> ul.mega-sub-menu > li.mega-current-menu-item:visible', menu_item).length ) {
687                        $('> ul.mega-sub-menu > li.mega-current-menu-item:visible', menu_item).first().addClass('mega-toggle-on');
688                    } else if ( $('> ul.mega-sub-menu > li.mega-current-menu-ancestor:visible', menu_item).length ) {
689                        $('> ul.mega-sub-menu > li.mega-current-menu-ancestor:visible', menu_item).first().addClass('mega-toggle-on');
690                    }
691                    
692
693                    if ($('> ul.mega-sub-menu > li.mega-toggle-on', menu_item).length == 0 ) {
694                        $('> ul.mega-sub-menu > li.mega-menu-item-has-children:visible', menu_item).first().addClass('mega-toggle-on');
695                    }
696                }
697
698                $('li.mega-menu-tabbed', menu).on('close_panel', function() {
699                    $('li.mega-menu-tabbed .mega-toggle-on', menu).removeClass('mega-toggle-on');
700                });
701            }
702
703            $('li.mega-menu-tabbed li.mega-collapse-children').on('close_panel', function() {
704                var menu_item = $(this).closest('.mega-menu-tabbed');
705
706                $("> ul.mega-sub-menu", $(this)).promise().done(function(){ // wait until slide animation has completed
707                    calculate_tabbed_sub_menu_heights( menu_item );
708                });
709            });
710        });
711    });
712})(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.