PageSourceSearch

https://friendshipplace.org/wp-content/plugins/megamenu-pro/assets/public.js?ver=2.2.9.1

js friendshipplace.org collected 2026-10-03 21:26:19 UTC 25,768 bytes, 708 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                    form.submit();
266                } else if (form.hasClass('mega-search-closed')) {
267                    input.focus();
268                    plugin.open_search();
269                } else if ( input.val() == '' ) {
270                    plugin.close_search();
271                } else {
272                    form.submit();
273                }
274            });
275
276        };
277
278        plugin.init_toggle_search();
279
280    };
281
282    $.fn.maxmegamenu_toggle_searchbox = function(options) {
283        return this.each(function() {
284            if (undefined === $(this).data('maxmegamenu_toggle_searchbox')) {
285                var plugin = new $.maxmegamenu_toggle_searchbox(this, options);
286                $(this).data('maxmegamenu_toggle_searchbox', plugin);
287            }
288        });
289    };
290
291    $(function() {
292        $(".mega-menu-toggle .mega-search").maxmegamenu_toggle_searchbox();
293    });
294})(jQuery);
295
296/**
297 * Sticky jQuery Plugin
298 */
299(function($) {
300
301    "use strict";
302
303    $.maxmegamenu_sticky = function(menu, options) {
304        var plugin = this;
305        var $menu = $(menu);
306        var $wrap = $menu.parent();
307        var breakpoint = $menu.attr('data-breakpoint');
308        var sticky_on_mobile = $menu.attr('data-sticky-mobile');
309        var sticky_on_desktop = $menu.attr('data-sticky-desktop');
310        var sticky_expand = $menu.attr('data-sticky-expand');
311        var sticky_expand_mobile = $menu.attr('data-sticky-expand-mobile');
312        var sticky_offset = isNaN(parseInt($menu.attr('data-sticky-offset'))) ? 0 : parseInt($menu.attr('data-sticky-offset'));
313        var sticky_hide_until_scroll_up = $menu.attr('data-sticky-hide');
314        var sticky_hide_until_scroll_up_tolerance = isNaN(parseInt($menu.attr('data-sticky-hide-tolerance'))) ? 0 : parseInt($menu.attr('data-sticky-hide-tolerance'));
315        var sticky_hide_until_scroll_up_offset = isNaN(parseInt($menu.attr('data-sticky-hide-offset'))) ? 0 : parseInt($menu.attr('data-sticky-hide-offset'));
316        var sticky_transition = $menu.attr('data-sticky-transition');
317        var sticky_menu_offset_top;
318        var sticky_menu_offset_left;
319        var sticky_menu_width;
320        var sticky_menu_width_round_up;
321        var sticky_menu_height;
322        var is_stuck = false;
323        var admin_bar_height = 0;
324        var last_scroll_top = 0;
325        var saved_scroll_top = 0;
326        var is_vertical = $menu.hasClass('mega-menu-vertical') || $menu.hasClass('mega-menu-accordion');
327
328        plugin.isDesktopView = function() {
329            return Math.max(window.outerWidth, $(window).width()) >= breakpoint; // account for scrollbars
330        };
331
332        var sticky_hide_until_scroll_up_enabled = function() {
333            return $menu.hasClass('mega-menu-horizontal') && sticky_hide_until_scroll_up == "true";
334        }
335
336        var sticky_enabled = function() {
337            if ( plugin.isDesktopView() ) {
338                return sticky_on_desktop === 'true';
339            } else {
340                return sticky_on_mobile === 'true';
341            }
342
343            return false;
344        };
345
346        plugin.calculate_menu_position = function() {
347            sticky_menu_offset_top = $wrap.offset().top;
348
349            if ($('body').hasClass('admin-bar') && $("#wpadminbar").is(":visible") && $("#wpadminbar").css('top') == '0px' && $("#wpadminbar").css('position') == 'fixed') {
350                admin_bar_height = $('#wpadminbar').height();
351                sticky_menu_offset_top = sticky_menu_offset_top - admin_bar_height;
352            }
353
354            if (sticky_offset < 0) {
355                sticky_menu_offset_top = sticky_menu_offset_top + sticky_offset;
356            } else {
357                sticky_menu_offset_top = sticky_menu_offset_top - sticky_offset;
358            }
359
360            sticky_menu_offset_left = $menu.parent().offset().left;
361            sticky_menu_width = window.getComputedStyle($wrap[0]).width;
362            sticky_menu_width_round_up = Math.ceil(parseFloat(sticky_menu_width));
363            sticky_menu_height = $wrap.height();
364        };
365
366        plugin.stick_menu = function() {
367            is_stuck = true;
368
369            var total_offset = parseInt(admin_bar_height, 10) + parseInt(sticky_offset, 10);
370
371            if (sticky_offset < 0) {
372                total_offset = parseInt(admin_bar_height, 10);
373            }
374
375            var placeholder = $("<div />").addClass("mega-sticky-wrapper").css({
376                'height' : sticky_menu_height + 'px',
377                'position' :'static'
378            });
379
380            $wrap.addClass('mega-sticky').wrap(placeholder).css({
381                'margin-top' : total_offset + 'px'
382            });
383
384            $("body").addClass($menu.attr("id") + "-mega-sticky");
385
386            $menu.css({
387                'max-width' : sticky_menu_width_round_up + 'px'
388            });
389
390            if (sticky_menu_offset_left > 0) {
391                $menu.css({
392                    'margin-left' : sticky_menu_offset_left + 'px'
393                });
394            }
395
396            if (is_vertical || sticky_expand === 'false') {
397                $wrap.css({
398                    'margin-left' : '0',
399                    'margin-right' : '0',
400                    'width' : sticky_menu_width_round_up + 'px',
401                    'left' : sticky_menu_offset_left + 'px'
402                });
403
404                $menu.css({
405                    'margin-left' : '0'
406                });
407            }
408
409            if ( $(window).width() <= breakpoint ) {
410                $wrap.css({
411                    'width' : sticky_menu_width_round_up + 'px'
412                });
413
414                if (sticky_expand_mobile === 'true') {
415                   $wrap.css({
416                        'margin-left' : '',
417                        'margin-right' : '',
418                        'width' : '',
419                        'left' : ''
420                    });
421
422                    $menu.css({
423                        'max-width' : '',
424                        'margin-left' : '',
425                        'width' : '',
426                        'left' : ''
427                    });
428                }
429            }
430
431            $wrap.delay(0).queue(function(next){
432                $(this).addClass('mega-stuck');
433                next();
434            });
435        };
436
437        plugin.unstick_menu = function(doing_resize) {
438            doing_resize = doing_resize || false;
439            is_stuck = false;
440            
441            $wrap.removeClass('mega-sticky').removeClass('mega-hide').css({
442                'margin' : '',
443                'width' : '',
444                'left': ''
445            });
446
447            $("body").removeClass($menu.attr("id") + "-mega-sticky");
448
449            if ( ! doing_resize ) { // this class is used for the height transition, do not remove it if we are simply resizing the window
450                $wrap.delay(0).queue(function(next){
451                    $(this).removeClass('mega-stuck');
452                    next();
453                });
454            }
455
456            $menu.css({
457                'margin-left' : '',
458                'max-width' : '',
459                'left' : '',
460                'width' : ''
461            });
462            
463            if ( $(window).width() <= breakpoint ) {
464                $menu.data('maxmegamenu').toggleBarForceWidth();
465            }
466
467            if (sticky_transition == 'true' && ! doing_resize ) {
468                var delay = 250; // allows the transiton to complete before unwrapping the menu
469            } else {
470                var delay = 0;
471            }
472
473            $wrap.delay(delay).queue(function(next){
474                $(this).unwrap();
475                next();
476            });
477        };
478
479        plugin.mega_sticky_on_scroll = function(){
480            if ( ! sticky_enabled() ) {
481                return;
482            }
483
484            var scroll_top = $(window).scrollTop();
485
486            if (scroll_top > sticky_menu_offset_top) {
487                if (!is_stuck) {
488                    plugin.stick_menu();
489                }
490            } else {
491                if (is_stuck) {
492                    plugin.unstick_menu();
493                }
494            }
495        };
496
497        var mega_hide_on_scroll_up = function() {
498            if (sticky_hide_until_scroll_up_enabled()) {
499
500                if ( $menu.data("view") === "mobile" && $('.mega-menu-toggle', $wrap).hasClass('mega-menu-open') ) {
501                    return;
502                }
503
504                var scroll_top = $(window).scrollTop();
505                
506                if ( scroll_top < sticky_hide_until_scroll_up_offset ) {
507                    $wrap.removeClass('mega-hide');
508                    $("body").removeClass($menu.attr("id") + "-mega-hide");
509                }
510                
511                saved_scroll_top = last_scroll_top;
512
513                if (scroll_top < last_scroll_top) {
514                    // scroll up
515                    if (saved_scroll_top - scroll_top > sticky_hide_until_scroll_up_tolerance) {
516                        $wrap.removeClass('mega-hide');
517                        $("body").removeClass($menu.attr("id") + "-mega-hide");
518                    }
519                } else {
520                    // scroll down
521                    if (is_stuck && scroll_top - saved_scroll_top > sticky_hide_until_scroll_up_tolerance) {
522                        $wrap.addClass('mega-hide');
523                        $("body").addClass($menu.attr("id") + "-mega-hide");
524                    }
525                }
526
527                last_scroll_top = scroll_top;
528            }
529        }
530
531        plugin.mega_sticky_on_resize = function() {
532            if ($('input', $wrap).is(':focus')) {
533                return;
534            }
535
536            if ( sticky_enabled() ) {
537                if (is_stuck) {
538                    plugin.unstick_menu(true);
539                    plugin.calculate_menu_position();
540                    plugin.stick_menu();
541                } else {
542                    plugin.calculate_menu_position();
543                    plugin.mega_sticky_on_scroll();
544                }
545            } else {
546                if (is_stuck) {
547                    plugin.unstick_menu();
548                }
549            }
550        };
551
552        plugin.init = function() {
553            plugin.calculate_menu_position();
554            plugin.mega_sticky_on_scroll();
555
556            $('.mega-menu-accordion li.mega-menu-item').on('open_panel', function() {
557                plugin.calculate_menu_position();
558            });
559
560            var $window = $(window);
561
562            $window.scroll(function() {
563                 plugin.mega_sticky_on_scroll();
564                 mega_hide_on_scroll_up();
565            });
566
567            var windowWidth = $window.width();
568            var resizeTimer;
569
570            $window.resize(function() {
571                clearTimeout(resizeTimer);
572                resizeTimer = setTimeout(function(){    
573                    windowWidth = $window.width();
574                    plugin.mega_sticky_on_resize();
575                }, 100);
576            });
577        };
578
579        plugin.init();
580    };
581
582    $.fn.maxmegamenu_sticky = function(options) {
583
584        return this.each(function() {
585            if (undefined === $(this).data('maxmegamenu_sticky')) {
586                var plugin = new $.maxmegamenu_sticky(this, options);
587                $(this).data('maxmegamenu_sticky', plugin);
588            }
589        });
590
591    };
592
593    $(window).on('load', function (e) {
594        $(".mega-menu[data-sticky-enabled]").maxmegamenu_sticky();
595    });
596
597})(jQuery);
598
599/**
600 * Handle tabbed functionality
601 */
602(function($) {
603    $(function() {
604
605        var calculate_tabbed_sub_menu_widths = function( menu_item ) {
606            var menu = menu_item.parents('.max-mega-menu');
607
608            if( $(menu.attr('data-panel-inner-width')).length > 0 ) {
609                if ( menu.data("view") === "desktop" ) {
610                    $('> ul.mega-sub-menu', menu_item).each(function() {
611                        var tab_content = $(this);
612                        var parent_submenu_content_width = parseInt(tab_content.width());
613                        var parent_submenu_left_padding = parseInt(tab_content.css('paddingLeft'));
614                        var tabs_width = $(this).find('a.mega-menu-link').first().outerWidth();
615
616                        $('> li.mega-menu-item > ul.mega-sub-menu', $(this)).each(function() {
617                            $(this).css('width', parent_submenu_content_width - tabs_width + 'px');
618                            $(this).css('left', parent_submenu_left_padding + tabs_width + 'px'); 
619                        });
620                    });
621                } else {
622                    $('> ul.mega-sub-menu > li.mega-menu-item > ul.mega-sub-menu', menu_item).each(function() {
623                        $(this).css('width', '');
624                        $(this).css('left', ''); 
625                    });
626                }
627            }
628        }
629
630        var calculate_tabbed_sub_menu_heights = function( menu_item ) {
631
632            var menu = menu_item.parents('.max-mega-menu');
633            var max_height = 0;
634
635            if ( menu.data("view") === "desktop" ) {
636
637                $('> ul.mega-sub-menu', menu_item).css('minHeight', '');
638                
639                $('> ul.mega-sub-menu > li.mega-menu-item > ul.mega-sub-menu', menu_item).each(function() {
640                    var tab_content = $(this);
641                    var this_height = parseInt(tab_content.css('height'));
642
643                    if (this_height > max_height) {
644                        max_height = this_height;
645                    }
646                });
647
648                var border_top_width = parseInt($('> ul.mega-sub-menu', menu_item).css('borderTopWidth'),10);
649                var border_bottom_width = parseInt($('> ul.mega-sub-menu', menu_item).css('borderBottomWidth'),10);
650                
651                $('> ul.mega-sub-menu', menu_item).css('minHeight', max_height + border_bottom_width + border_top_width);
652            } else {
653                $('> ul.mega-sub-menu', menu_item).css('minHeight', '');
654            }
655        }
656
657        var $window = $(window);
658
659        var windowWidth = $window.width();
660
661        $window.resize(function() {
662            if ($window.width() != windowWidth) {
663                calculate_tabbed_sub_menu_widths($('li.mega-menu-tabbed'));
664                calculate_tabbed_sub_menu_heights($('li.mega-menu-tabbed'));
665            }            
666        });
667
668        $('li.mega-menu-tabbed, li.mega-menu-tabbed li.mega-collapse-children').on('open_panel', function() {
669            var menu = $(this).parents('.max-mega-menu');
670            var menu_item = $(this).closest(".mega-menu-tabbed");
671
672            calculate_tabbed_sub_menu_widths( menu_item );
673
674            $(">
674 ul.mega-sub-menu", $(this)).promise().done(function(){ // wait until slide animation has completed
675                calculate_tabbed_sub_menu_heights( menu_item );
676            });
677
678            if ( menu.data('view') == 'desktop' ) {
679                if ($('> ul.mega-sub-menu > li.mega-menu-item-has-children.mega-toggle-on', menu_item).length == 0 ) {
680                    
681
682                    if ( $('> ul.mega-sub-menu > li.mega-current-menu-item:visible', menu_item).length ) {
683                        $('> ul.mega-sub-menu > li.mega-current-menu-item:visible', menu_item).first().addClass('mega-toggle-on');
684                    } else if ( $('> ul.mega-sub-menu > li.mega-current-menu-ancestor:visible', menu_item).length ) {
685                        $('> ul.mega-sub-menu > li.mega-current-menu-ancestor:visible', menu_item).first().addClass('mega-toggle-on');
686                    }
687                    
688
689                    if ($('> ul.mega-sub-menu > li.mega-toggle-on', menu_item).length == 0 ) {
690                        $('> ul.mega-sub-menu > li.mega-menu-item-has-children:visible', menu_item).first().addClass('mega-toggle-on');
691                    }
692                }
693
694                $('li.mega-menu-tabbed', menu).on('close_panel', function() {
695                    $('li.mega-menu-tabbed .mega-toggle-on', menu).removeClass('mega-toggle-on');
696                });
697            }
698
699            $('li.mega-menu-tabbed li.mega-collapse-children').on('close_panel', function() {
700                var menu_item = $(this).closest('.mega-menu-tabbed');
701
702                $("> ul.mega-sub-menu", $(this)).promise().done(function(){ // wait until slide animation has completed
703                    calculate_tabbed_sub_menu_heights( menu_item );
704                });
705            });
706        });
707    });
708})(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.