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