/*! This file is auto-generated */ !function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=e(require("jquery")):jQuery&&!jQuery.fn.hoverIntent&&e(jQuery)}(function(f){"use strict";function u(e){return"function"==typeof e}var i,r,v={interval:100,sensitivity:6,timeout:0},s=0,a=function(e){i=e.pageX,r=e.pageY},p=function(e,t,n,o){if(Math.sqrt((n.pX-i)*(n.pX-i)+(n.pY-r)*(n.pY-r)) ul.mega-sub-menu > li.mega-menu-item-has-children," + "li.mega-menu-flyout li.mega-menu-item-has-children", $menu); var collapse_children_parents = $("li.mega-menu-megamenu li.mega-menu-item-has-children.mega-collapse-children > a.mega-menu-link", $menu); plugin.addAnimatingClass = function(element) { if (plugin.settings.effect === "disabled") { return; } $(".mega-animating").removeClass("mega-animating"); var timeout = plugin.settings.effect_speed + parseInt(plugin.settings.hover_intent_timeout, 10); element.addClass("mega-animating"); setTimeout(function() { element.removeClass("mega-animating"); }, timeout ); }; plugin.hideAllPanels = function() { $(".mega-toggle-on > a.mega-menu-link", $menu).each(function() { plugin.hidePanel($(this), false); }); }; plugin.expandMobileSubMenus = function() { if (plugin.settings.mobile_direction !== 'vertical') { return; } $(".mega-menu-item-has-children.mega-expand-on-mobile > a.mega-menu-link", $menu).each(function() { plugin.showPanel($(this), true); }); if ( plugin.settings.mobile_state == 'expand_all' ) { $(".mega-menu-item-has-children:not(.mega-toggle-on) > a.mega-menu-link", $menu).each(function() { plugin.showPanel($(this), true); }); } if ( plugin.settings.mobile_state == 'expand_active' ) { const activeItemSelectors = [ "li.mega-current-menu-ancestor.mega-menu-item-has-children > a.mega-menu-link", "li.mega-current-menu-item.mega-menu-item-has-children > a.mega-menu-link", "li.mega-current-menu-parent.mega-menu-item-has-children > a.mega-menu-link", "li.mega-current_page_ancestor.mega-menu-item-has-children > a.mega-menu-link", "li.mega-current_page_item.mega-menu-item-has-children > a.mega-menu-link" ]; $menu.find(activeItemSelectors.join(', ')).each(function() { plugin.showPanel($(this), true); }); } } plugin.hideSiblingPanels = function(anchor, immediate) { anchor.parent().parent().find(".mega-toggle-on").children("a.mega-menu-link").each(function() { // all open children of open siblings plugin.hidePanel($(this), immediate); }); }; plugin.isDesktopView = function() { var width = Math.max(document.documentElement.clientWidth || 0, window.innerWidth || 0); return width > plugin.settings.breakpoint; }; plugin.isMobileView = function() { return !plugin.isDesktopView(); }; plugin.showPanel = function(anchor, immediate) { if ( $.isNumeric(anchor) ) { anchor = $("li.mega-menu-item-" + anchor, $menu).find("a.mega-menu-link").first(); } else if ( anchor.is("li.mega-menu-item") ) { anchor = anchor.find("a.mega-menu-link").first(); } anchor.parent().triggerHandler("before_open_panel"); anchor.parent().find("[aria-expanded]").first().attr("aria-expanded", "true"); $(".mega-animating").removeClass("mega-animating"); if (plugin.isMobileView() && anchor.parent().hasClass("mega-hide-sub-menu-on-mobile")) { return; } if (plugin.isDesktopView() && ( $menu.hasClass("mega-menu-horizontal") || $menu.hasClass("mega-menu-vertical") ) && !anchor.parent().hasClass("mega-collapse-children")) { plugin.hideSiblingPanels(anchor, true); } if ((plugin.isMobileView() && $wrap.hasClass("mega-keyboard-navigation")) || plugin.settings.vertical_behaviour === "accordion") { plugin.hideSiblingPanels(anchor, false); } plugin.calculateDynamicSubmenuWidths(anchor); // apply jQuery transition (only if the effect is set to "slide", other transitions are CSS based) if ( plugin.shouldUseSlideAnimation(anchor, immediate) ) { var speed = plugin.isMobileView() ? plugin.settings.effect_speed_mobile : plugin.settings.effect_speed; anchor.siblings(".mega-sub-menu").css("display", "none").animate({"height":"show", "paddingTop":"show", "paddingBottom":"show", "minHeight":"show"}, speed, function() { $(this).css("display", ""); }); } anchor.parent().addClass("mega-toggle-on").triggerHandler("open_panel"); }; plugin.shouldUseSlideAnimation = function(anchor, immediate) { if (immediate == true) { return false; } if (anchor.parent().hasClass("mega-collapse-children")) { return true; } if (plugin.isDesktopView() && plugin.settings.effect === "slide") { return true; } if (plugin.isMobileView()) { if (plugin.settings.effect_mobile === "slide") { return true; } if (plugin.settings.effect_mobile === "slide_left" || plugin.settings.effect_mobile === "slide_right") { return plugin.settings.mobile_direction !== "horizontal"; } } return false; }; plugin.hidePanel = function(anchor, immediate) { if ( $.isNumeric(anchor) ) { anchor = $("li.mega-menu-item-" + anchor, $menu).find("a.mega-menu-link").first(); } else if ( anchor.is("li.mega-menu-item") ) { anchor = anchor.find("a.mega-menu-link").first(); } anchor.parent().triggerHandler("before_close_panel"); anchor.parent().find("[aria-expanded]").first().attr("aria-expanded", "false"); if ( plugin.shouldUseSlideAnimation(anchor) ) { var speed = plugin.isMobileView() ? plugin.settings.effect_speed_mobile : plugin.settings.effect_speed; anchor.siblings(".mega-sub-menu").animate({"height":"hide", "paddingTop":"hide", "paddingBottom":"hide", "minHeight":"hide"}, speed, function() { anchor.siblings(".mega-sub-menu").css("display", ""); anchor.parent().removeClass("mega-toggle-on").triggerHandler("close_panel"); }); return; } if (immediate) { anchor.siblings(".mega-sub-menu").css("display", "none").delay(plugin.settings.effect_speed).queue(function(){ $(this).css("display", "").dequeue(); }); } // pause video widget videos anchor.siblings(".mega-sub-menu").find(".widget_media_video video").each(function() { this.player.pause(); }); anchor.parent().removeClass("mega-toggle-on").triggerHandler("close_panel"); plugin.addAnimatingClass(anchor.parent()); }; plugin.calculateDynamicSubmenuWidths = function(anchor) { // apply dynamic width and sub menu position (only to top level mega menus) if (anchor.parent().hasClass("mega-menu-megamenu") && anchor.parent().parent().hasClass("max-mega-menu") && plugin.settings.panel_width ) { if (plugin.isDesktopView()) { var submenu_offset = $menu.offset(); var target_offset = $(plugin.settings.panel_width).offset(); if ( plugin.settings.panel_width == '100vw' ) { target_offset = $('body').offset(); anchor.siblings(".mega-sub-menu").css({ left: (target_offset.left - submenu_offset.left) + "px" }); } else if ( $(plugin.settings.panel_width).length > 0 ) { anchor.siblings(".mega-sub-menu").css({ width: $(plugin.settings.panel_width).outerWidth(), left: (target_offset.left - submenu_offset.left) + "px" }); } } else { anchor.siblings(".mega-sub-menu").css({ width: "", left: "" }); } } // apply inner width to sub menu by adding padding to the left and right of the mega menu if (anchor.parent().hasClass("mega-menu-megamenu") && anchor.parent().parent().hasClass("max-mega-menu") && plugin.settings.panel_inner_width && $(plugin.settings.panel_inner_width).length > 0) { var target_width = 0; if ($(plugin.settings.panel_inner_width).length) { // jQuery selector target_width = parseInt($(plugin.settings.panel_inner_width).width(), 10); } else { // we"re using a pixel width target_width = parseInt(plugin.settings.panel_inner_width, 10); } anchor.siblings(".mega-sub-menu").css({ "paddingLeft": "", "paddingRight": "" }); var submenu_width = parseInt(anchor.siblings(".mega-sub-menu").innerWidth(), 10); if (plugin.isDesktopView() && target_width > 0 && target_width < submenu_width) { anchor.siblings(".mega-sub-menu").css({ "paddingLeft": (submenu_width - target_width) / 2 + "px", "paddingRight": (submenu_width - target_width) / 2 + "px" }); } } }; plugin.bindClickEvents = function() { if ( $wrap.data('has-click-events') === true ) { return; } $wrap.data('has-click-events', true); var dragging = false; $(document).on({ "touchmove": function(e) { dragging = true; }, "touchstart": function(e) { dragging = false; } }); $(document).on("click touchend", function(e) { // hide menu when clicked away from if (!dragging && plugin.settings.document_click === "collapse" && ! $(e.target).closest(".mega-menu-wrap").length ) { plugin.hideAllPanels(); plugin.hideMobileMenu(); } dragging = false; }); var clickable_parents = $("> a.mega-menu-link", items_with_submenus).add(collapse_children_parents); clickable_parents.on("touchend.megamenu", function(e) { if (plugin.settings.event === "hover_intent") { plugin.unbindHoverIntentEvents(); } if (plugin.settings.event === "hover") { plugin.unbindHoverEvents(); } }); clickable_parents.on("click.megamenu", function(e) { if ( $(e.target).hasClass('mega-indicator') ) { return; } if (plugin.isDesktopView() && $(this).parent().hasClass("mega-toggle-on") && $(this).closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { if (plugin.settings.second_click === "go") { return; } else { e.preventDefault(); return; } } if (dragging) { return; } if (plugin.isMobileView() && $(this).parent().hasClass("mega-hide-sub-menu-on-mobile")) { return; // allow all clicks on parent items when sub menu is hidden on mobile } if ((plugin.settings.second_click === "go" || $(this).parent().hasClass("mega-click-click-go")) && $(this).attr("href") !== undefined) { // check for second click if (!$(this).parent().hasClass("mega-toggle-on")) { e.preventDefault(); plugin.showPanel($(this)); } } else { e.preventDefault(); if ($(this).parent().hasClass("mega-toggle-on")) { plugin.hidePanel($(this), false); } else { plugin.showPanel($(this)); } } }); if ( plugin.settings.second_click === "disabled" ) { clickable_parents.off("click.megamenu"); } $(".mega-close-after-click:not(.mega-menu-item-has-children) > a.mega-menu-link", $menu).on("click", function() { plugin.hideAllPanels(); plugin.hideMobileMenu(); }); $("button.mega-close", $wrap).on("click", function(e) { plugin.hideMobileMenu(); }); }; plugin.bindHoverEvents = function() { items_with_submenus.on({ "mouseenter.megamenu" : function() { plugin.unbindClickEvents(); if (! $(this).hasClass("mega-toggle-on")) { plugin.showPanel($(this).children("a.mega-menu-link")); } }, "mouseleave.megamenu" : function() { if ($(this).hasClass("mega-toggle-on") && ! $(this).hasClass("mega-disable-collapse") && ! $(this).parent().parent().hasClass("mega-menu-tabbed")) { plugin.hidePanel($(this).children("a.mega-menu-link"), false); } } }); }; plugin.bindHoverIntentEvents = function() { items_with_submenus.hoverIntent({ over: function () { plugin.unbindClickEvents(); if (! $(this).hasClass("mega-toggle-on")) { plugin.showPanel($(this).children("a.mega-menu-link")); } }, out: function () { if ($(this).hasClass("mega-toggle-on") && ! $(this).hasClass("mega-disable-collapse") && ! $(this).parent().parent().hasClass("mega-menu-tabbed")) { plugin.hidePanel($(this).children("a.mega-menu-link"), false); } }, timeout: plugin.settings.hover_intent_timeout, interval: plugin.settings.hover_intent_interval }); }; plugin.bindKeyboardEvents = function() { var tab_key = 9; var escape_key = 27; var enter_key = 13; var left_arrow_key = 37; var up_arrow_key = 38; var right_arrow_key = 39; var down_arrow_key = 40; var space_key = 32; var isMobileOffCanvasHorizontal = function() { return plugin.isMobileView() && ( plugin.settings.effect_mobile === 'slide_right' || plugin.settings.effect_mobile === '' ) && plugin.settings.mobile_direction === 'horizontal'; } var shouldTrapFocusInCurrentSubMenu = function() { return isMobileOffCanvasHorizontal() && ( keyCode === up_arrow_key || keyCode === down_arrow_key || keyCode === tab_key ); } $wrap.on("keyup.megamenu", ".max-mega-menu, .mega-menu-toggle", function(e) { var keyCode = e.keyCode || e.which; var active_link = $(e.target); if (keyCode === tab_key) { $wrap.addClass("mega-keyboard-navigation"); plugin.bindClickEvents(); // Windows Narrator ignores the Enter keypress, so ensure click events are available when pressing tab } }); $wrap.on("keydown.megamenu", "a.mega-menu-link, .mega-indicator, .mega-menu-toggle-block, .mega-menu-toggle-animated-block button", function(e) { if ( ! $wrap.hasClass("mega-keyboard-navigation") ) { return; } var keyCode = e.keyCode || e.which; var active_link = $(e.target); if ( keyCode === space_key && active_link.is(".mega-menu-link") ) { e.preventDefault(); // pressing space on a parent item will always toggle the sub menu if ( active_link.parent().is(items_with_submenus) ) { if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { plugin.hidePanel(active_link); } else { plugin.showPanel(active_link); } } } if ( keyCode === space_key && active_link.is("mega-indicator") ) { e.preventDefault(); if ( active_link.parent().parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { plugin.hidePanel(active_link.parent()); } else { plugin.showPanel(active_link.parent()); } } if ( keyCode === escape_key ) { var submenu_open = $(".mega-toggle-on", $menu).length !== 0; if ( submenu_open ) { var focused_menu_item = $menu.find(":focus"); if ( focused_menu_item.closest('.mega-menu-flyout.mega-toggle-on').length !== 0 ) { var nearest_parent_of_focused_item_li = focused_menu_item.closest('.mega-toggle-on'); var nearest_parent_of_focused_item_a = $("> a.mega-menu-link", nearest_parent_of_focused_item_li); plugin.hidePanel(nearest_parent_of_focused_item_a); nearest_parent_of_focused_item_a.focus(); } if ( focused_menu_item.closest('.mega-menu-megamenu.mega-toggle-on').length !== 0 ) { var nearest_parent_of_focused_item_li = focused_menu_item.closest('.mega-menu-megamenu.mega-toggle-on'); var nearest_parent_of_focused_item_a = $("> a.mega-menu-link", nearest_parent_of_focused_item_li); plugin.hidePanel(nearest_parent_of_focused_item_a); nearest_parent_of_focused_item_a.focus(); } } if ( plugin.isMobileView() && ! submenu_open ) { plugin.hideMobileMenu(); $(".mega-menu-toggle-block, button.mega-toggle-animated", $toggle_bar).first().focus(); } } if ( keyCode === space_key || keyCode === enter_key ) { if ( active_link.is(".mega-menu-toggle-block, .mega-menu-toggle-animated-block button") ) { e.preventDefault(); if ( $toggle_bar.hasClass("mega-menu-open") ) { plugin.hideMobileMenu(); } else { plugin.showMobileMenu(); } } } if ( keyCode === enter_key ) { // ignored by windows narrator // pressing enter on an arrow will toggle the sub menu if ( active_link.is(".mega-indicator") ) { if ( active_link.closest("li.mega-menu-item").hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { plugin.hidePanel(active_link.parent()); } else { plugin.showPanel(active_link.parent()); } return; } // pressing enter on a parent link if ( active_link.parent().is(items_with_submenus) ) { // when clicking on the parent of a hidden submenu, follow the link if ( plugin.isMobileView() && active_link.parent().is(".mega-hide-sub-menu-on-mobile") ) { return; } // pressing enter on a parent item without a link will toggle the sub menu if ( active_link.is("[href]") === false ) { if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { plugin.hidePanel(active_link); } else { plugin.showPanel(active_link); } return; } // pressing enter on a parent item will first open the sub menu, then follow the link if ( active_link.parent().hasClass("mega-toggle-on") && ! active_link.closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") ) { return; } else { e.preventDefault(); plugin.showPanel(active_link); } } } if ( shouldTrapFocusInCurrentSubMenu() ) { var focused_item = $(":focus", $menu); // if the menu doesn't have focus, focus the first menu item if ( focused_item.length === 0) { e.preventDefault(); $("> li.mega-menu-item:visible", $menu).find("> a.mega-menu-link, .mega-search span[role=button]").first().focus(); return; } // try to find the next item at the same level var next_item_to_focus = focused_item.parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first(); // can't find another item in the same level, attempt to skip back to the top if ( next_item_to_focus.length === 0 && focused_item.closest(".mega-menu-megamenu").length !== 0 ) { // are we inside a megamenu? find the 'back' button and focus on that var all_li_parents = focused_item.parentsUntil(".mega-menu-megamenu"); if ( focused_item.is(all_li_parents.find("a.mega-menu-link").last()) ) { next_item_to_focus = all_li_parents.find(".mega-back-button:visible > a.mega-menu-link").first(); } } // skip back to the top of non-megamenu menus if ( next_item_to_focus.length === 0 ) { next_item_to_focus = focused_item.parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first(); } if ( next_item_to_focus.length !== 0 ) { e.preventDefault(); next_item_to_focus.focus(); } } var shouldGoToNextTopLevelItem = function() { return ( ( keyCode === right_arrow_key && plugin.isDesktopView() ) || ( keyCode === down_arrow_key && plugin.isMobileView() ) ) && $menu.hasClass("mega-menu-horizontal"); } var shouldGoToPreviousTopLevelItem = function() { return ( ( keyCode === left_arrow_key && plugin.isDesktopView() ) || ( keyCode === up_arrow_key && plugin.isMobileView() ) ) && $menu.hasClass("mega-menu-horizontal"); } if ( shouldGoToNextTopLevelItem() ) { e.preventDefault(); var next_top_level_item = $("> .mega-toggle-on", $menu).nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first(); if (next_top_level_item.length === 0) { next_top_level_item = $(":focus", $menu).parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first(); } if (next_top_level_item.length === 0) { next_top_level_item = $(":focus", $menu).parent().parent().parent().nextAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").first(); } plugin.hideAllPanels(); next_top_level_item.focus(); } if ( shouldGoToPreviousTopLevelItem() ) { e.preventDefault(); var prev_top_level_item = $("> .mega-toggle-on", $menu).prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last(); if (prev_top_level_item.length === 0) { prev_top_level_item = $(":focus", $menu).parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last(); } if (prev_top_level_item.length === 0) { prev_top_level_item = $(":focus", $menu).parent().parent().parent().prevAll("li.mega-menu-item:visible").find("> a.mega-menu-link, .mega-search span[role=button]").last(); } plugin.hideAllPanels(); prev_top_level_item.focus(); } }); $wrap.on("focusout.megamenu", function(e) { if ( $wrap.hasClass("mega-keyboard-navigation") ) { setTimeout(function() { var menu_has_focus = $wrap.find(":focus").length > 0; if (! menu_has_focus) { $wrap.removeClass("mega-keyboard-navigation"); plugin.hideAllPanels(); plugin.hideMobileMenu(); } }, 10); } }); }; plugin.unbindAllEvents = function() { $("ul.mega-sub-menu, li.mega-menu-item, li.mega-menu-row, li.mega-menu-column, a.mega-menu-link, .mega-indicator", $menu).off().unbind(); }; plugin.unbindClickEvents = function() { if ( $wrap.hasClass('mega-keyboard-navigation') ) { return; } // collapsable parents always have a click event $("> a.mega-menu-link", items_with_submenus).not(collapse_children_parents).off("click.megamenu touchend.megamenu"); $wrap.data('has-click-events', false); }; plugin.unbindHoverEvents = function() { items_with_submenus.off("mouseenter.megamenu mouseleave.megamenu"); }; plugin.unbindHoverIntentEvents = function() { items_with_submenus.off("mouseenter mouseleave").removeProp("hoverIntent_t").removeProp("hoverIntent_s"); // hoverintent does not allow namespaced events }; plugin.unbindKeyboardEvents = function() { $wrap.off("keyup.megamenu keydown.megamenu focusout.megamenu"); }; plugin.unbindMegaMenuEvents = function() { if (plugin.settings.event === "hover_intent") { plugin.unbindHoverIntentEvents(); } if (plugin.settings.event === "hover") { plugin.unbindHoverEvents(); } plugin.unbindClickEvents(); plugin.unbindKeyboardEvents(); }; plugin.bindMegaMenuEvents = function() { plugin.unbindMegaMenuEvents(); if (plugin.isDesktopView() && plugin.settings.event === "hover_intent") { plugin.bindHoverIntentEvents(); } if (plugin.isDesktopView() && plugin.settings.event === "hover") { plugin.bindHoverEvents(); } plugin.bindClickEvents(); // always bind click events for touch screen devices plugin.bindKeyboardEvents(); }; plugin.checkWidth = function() { if ( plugin.isMobileView() && $menu.data("view") === "desktop" ) { plugin.switchToMobile(); } if ( plugin.isDesktopView() && $menu.data("view") === "mobile" ) { plugin.switchToDesktop(); } plugin.calculateDynamicSubmenuWidths($("> li.mega-menu-megamenu > a.mega-menu-link", $menu)); }; plugin.reverseRightAlignedItems = function() { if ( ! $("body").hasClass("rtl") && $menu.hasClass("mega-menu-horizontal") && $menu.css("display") !== 'flex' ) { $menu.append($menu.children("li.mega-item-align-right").get().reverse()); } }; plugin.addClearClassesToMobileItems = function() { $(".mega-menu-row", $menu).each(function() { $("> .mega-sub-menu > .mega-menu-column:not(.mega-hide-on-mobile)", $(this)).filter(":even").addClass("mega-menu-clear"); // :even is 0 based }); }; plugin.initDesktop = function() { $menu.data("view", "desktop"); plugin.bindMegaMenuEvents(); plugin.initIndicators(); }; plugin.initMobile = function() { plugin.switchToMobile(); }; plugin.switchToDesktop = function() { $menu.data("view", "desktop"); plugin.bindMegaMenuEvents(); plugin.reverseRightAlignedItems(); plugin.hideAllPanels(); plugin.hideMobileMenu(true); }; plugin.switchToMobile = function() { $menu.data("view", "mobile"); plugin.bindMegaMenuEvents(); plugin.initIndicators(); plugin.reverseRightAlignedItems(); plugin.addClearClassesToMobileItems(); plugin.hideAllPanels(); plugin.expandMobileSubMenus(); }; plugin.initToggleBar = function() { $toggle_bar.on("click", function(e) { if ( $(e.target).is(".mega-menu-toggle, .mega-menu-toggle-custom-block *, .mega-menu-toggle-block, .mega-menu-toggle-animated-block, .mega-menu-toggle-animated-block *, .mega-toggle-blocks-left, .mega-toggle-blocks-center, .mega-toggle-blocks-right, .mega-toggle-label, .mega-toggle-label span") ) { e.preventDefault(); if ($(this).hasClass("mega-menu-open")) { plugin.hideMobileMenu(); } else { plugin.showMobileMenu(); } } }); }; plugin.initIndicators = function() { $menu.off('click.megamenu', '.mega-indicator'); $menu.on('click.megamenu', '.mega-indicator', function(e) { e.preventDefault(); e.stopPropagation(); if ( $(this).closest(".mega-menu-item").hasClass("mega-toggle-on") ) { if ( ! $(this).closest("ul.mega-sub-menu").parent().hasClass("mega-menu-tabbed") || plugin.isMobileView() ) { plugin.hidePanel($(this).parent(), false); } } else { plugin.showPanel($(this).parent(), false); } }); }; plugin.hideMobileMenu = function(force) { force = force || false; if ( ! $toggle_bar.is(":visible") && ! force ) { return; } html_body_class_timeout = setTimeout(function() { $("body").removeClass($menu.attr("id") + "-mobile-open"); $("html").removeClass($menu.attr("id") + "-off-canvas-open"); }, plugin.settings.effect_speed_mobile); $(".mega-toggle-label, .mega-toggle-animated", $toggle_bar).attr("aria-expanded", "false"); if (plugin.settings.effect_mobile === "slide" && ! force ) { $menu.animate({"height":"hide"}, plugin.settings.effect_speed_mobile, function() { $menu.css({ width: "", left: "", display: "" }); $toggle_bar.removeClass("mega-menu-open"); }); } else { $menu.css({ width: "", left: "", display: "" }); $toggle_bar.removeClass("mega-menu-open"); } $menu.triggerHandler("mmm:hideMobileMenu"); }; plugin.showMobileMenu = function() { if ( ! $toggle_bar.is(":visible")) { return; } clearTimeout(html_body_class_timeout); $("body").addClass($menu.attr("id") + "-mobile-open"); plugin.expandMobileSubMenus(); if ( plugin.settings.effect_mobile === "slide_left" || plugin.settings.effect_mobile === "slide_right" ) { $("html").addClass($menu.attr("id") + "-off-canvas-open"); } $(".mega-toggle-label, .mega-toggle-animated", $toggle_bar).attr("aria-expanded", "true"); if (plugin.settings.effect_mobile === "slide") { $menu.animate({"height":"show"}, plugin.settings.effect_speed_mobile, function() { $(this).css("display", ""); }); } $toggle_bar.addClass("mega-menu-open"); plugin.toggleBarForceWidth(); $menu.triggerHandler("mmm:showMobileMenu"); }; plugin.toggleBarForceWidth = function() { if ($(plugin.settings.mobile_force_width).length && ( plugin.settings.effect_mobile === "slide" || plugin.settings.effect_mobile === "disabled" ) ) { var submenu_offset = $toggle_bar.offset(); var target_offset = $(plugin.settings.mobile_force_width).offset(); $menu.css({ width: $(plugin.settings.mobile_force_width).outerWidth(), left: (target_offset.left - submenu_offset.left) + "px" }); } }; plugin.init = function() { $menu.triggerHandler("before_mega_menu_init"); plugin.settings = $.extend({}, defaults, options); $menu.removeClass("mega-no-js"); plugin.initToggleBar(); if (plugin.settings.unbind_events === "true") { plugin.unbindAllEvents(); } $(window).on("load", function() { plugin.calculateDynamicSubmenuWidths($("> li.mega-menu-megamenu > a.mega-menu-link", $menu)); }); if ( plugin.isDesktopView() ) { plugin.initDesktop(); } else { plugin.initMobile(); } $(window).on("resize", function() { plugin.checkWidth(); }); $menu.triggerHandler("after_mega_menu_init"); }; plugin.init(); }; $.fn.maxmegamenu = function(options) { return this.each(function() { if (undefined === $(this).data("maxmegamenu")) { var plugin = new $.maxmegamenu(this, options); $(this).data("maxmegamenu", plugin); } }); }; $(function() { $(".max-mega-menu").maxmegamenu(); }); }( jQuery ));; /*jslint browser: true, white: true */ /*global console,jQuery,megamenu,window,navigator*/ /** * EDD Ajax Cart */ (function($) { "use strict"; $(function() { $('body').on('edd_cart_item_added', function(event, data) { $('.mega-menu-edd-cart-total').html(data.total); $('.mega-menu-edd-cart-count').html(data.cart_quantity); }); }); $(".max-mega-menu").on("after_mega_menu_init", function() { $('li.mega-menu-megamenu').on('open_panel', function() { // reset default var placeholder = $(this).closest(".mega-menu-megamenu").find(".widget_maxmegamenu_image_swap img.mega-placeholder"); var default_src = placeholder.attr('data-default-src'); var default_alt = placeholder.attr('data-default-alt'); placeholder.attr('src', default_src); placeholder.attr('alt', default_alt); // preload $('.mega-sub-menu [data-image-swap-url]', $(this) ).not(['data-preloaded']).each( function() { $('')[0].src = $(this).attr('data-image-swap-url'); $(this).attr('data-preloaded', 'true'); }); }); if ( ! $.isFunction($.fn.hoverIntent) ) { return; } $('.mega-sub-menu [data-image-swap-url]').hoverIntent({ over: function () { var placeholder = $(this).closest(".mega-menu-megamenu").find(".widget_maxmegamenu_image_swap img.mega-placeholder"); var new_src = $(this).attr('data-image-swap-url'); var new_alt = $(this).is("[data-image-swap-alt]") ? $(this).attr('data-image-swap-alt') : ""; placeholder.attr('src', new_src); placeholder.attr('alt', new_alt); }, out: function() {} }); }); })(jQuery); /** * Searchbox jQuery plugin */ (function($) { "use strict"; $.maxmegamenu_searchbox = function(form, options) { var plugin = this; var form = $(form); var $menu = form.parents('.max-mega-menu'); var $wrap = $menu.parent(); var breakpoint = $menu.attr('data-breakpoint'); var input = $('input[type=text]', form); var icon = $('.search-icon', form); plugin.isDesktopView = function() { return Math.max(window.outerWidth, $(window).width()) >= breakpoint; // account for scrollbars }; plugin.monitorView = function() { if (typeof $menu.data("view") === 'undefined') { if (plugin.isDesktopView()) { $menu.data("view", "desktop"); } else { $menu.data("view", "mobile"); } } plugin.checkWidth(); $(window).resize(function() { plugin.checkWidth(); }); }; plugin.checkWidth = function() { 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); if ( $menu.data("view") === "mobile" ) { var placeholder = expanding_search.attr('data-placeholder'); expanding_search.attr('placeholder', placeholder); } if ( $menu.data("view") === "desktop" ) { expanding_search.attr('placeholder', ''); } }; plugin.close_search = function() { $menu.triggerHandler("mmm:closeSearch"); input.val(""); input.attr('placeholder', ''); form.removeClass('mega-search-open'); form.addClass('mega-search-closed'); } plugin.open_search = function() { $menu.triggerHandler("mmm:openSearch"); input.attr('placeholder', input.attr('data-placeholder')); form.removeClass('mega-search-closed'); form.addClass('mega-search-open'); } plugin.detect_background_click = function() { var dragging = false; $(document).on({ "touchmove": function(e) { dragging = true; }, "touchstart": function(e) { dragging = false; } }); $(document).on("click touchend", function(e) { // hide menu when clicked away from if ( form.parent().hasClass('mega-static') ) { return; } if ( ! dragging && ! $(e.target).closest(".max-mega-menu li").length && ! $(e.target).closest(".mega-menu-toggle").length ) { plugin.close_search(); } dragging = false; }); } plugin.init_replacements_search = function() { input.val(""); if ( $menu.data("view") === "mobile" ) { $(".search-icon", $menu).on('click', function(e) { $(this).parents(".mega-search").submit(); }); } if ( $menu.data("view") === "desktop" ) { input.on('focus', function(e) { if (! form.parent().hasClass('mega-static') && form.hasClass('mega-search-closed') ) { plugin.open_search(); } }); input.on('blur', function(e) { if (! form.parent().hasClass('mega-static') && form.hasClass('mega-search-open') ) { plugin.close_search(); } }); icon.on('click', function(e) { if (form.parent().hasClass('mega-static') ) { form.submit(); return; } if (form.hasClass('mega-search-closed')) { plugin.open_search(); input.focus(); } else if ( input.val() == '' ) { plugin.close_search(); } else { form.submit(); } }); } }; plugin.monitorView(); plugin.init_replacements_search(); plugin.detect_background_click(); }; $.fn.maxmegamenu_searchbox = function(options) { return this.each(function() { if (undefined === $(this).data('maxmegamenu_searchbox')) { var plugin = new $.maxmegamenu_searchbox(this, options); $(this).data('maxmegamenu_searchbox', plugin); } }); }; $(function() { $(".max-mega-menu .mega-search").maxmegamenu_searchbox(); }); })(jQuery); /** * Searchbox jQuery plugin */ (function($) { "use strict"; $.maxmegamenu_toggle_searchbox = function(form, options) { var plugin = this; var form = $(form); var $wrap = form.parents('.mega-menu-wrap'); var input = $("input[type=text]", form); var icon = $(".search-icon", form); plugin.open_search = function() { input.attr('placeholder', input.attr('data-placeholder')); form.removeClass('mega-search-closed'); form.addClass('mega-search-open'); } plugin.close_search = function() { input.attr('placeholder', ''); form.removeClass('mega-search-open'); form.addClass('mega-search-closed'); } plugin.init_toggle_search = function() { input.val(""); input.on('focus', function(e) { if (! form.parent().hasClass('mega-static') && form.hasClass('mega-search-closed') && $wrap.hasClass('mega-keyboard-navigation') ) { plugin.open_search(); } }); input.on('blur', function(e) { if ( ! form.parent().hasClass('mega-static') && form.hasClass('mega-search-open') && $wrap.hasClass('mega-keyboard-navigation') ) { plugin.close_search(); } }); icon.on('click', function(e) { if (form.hasClass('static') ) { form.submit(); } else if (form.hasClass('mega-search-closed')) { input.focus(); plugin.open_search(); } else if ( input.val() == '' ) { plugin.close_search(); } else { form.submit(); } }); }; plugin.init_toggle_search(); }; $.fn.maxmegamenu_toggle_searchbox = function(options) { return this.each(function() { if (undefined === $(this).data('maxmegamenu_toggle_searchbox')) { var plugin = new $.maxmegamenu_toggle_searchbox(this, options); $(this).data('maxmegamenu_toggle_searchbox', plugin); } }); }; $(function() { $(".mega-menu-toggle .mega-search").maxmegamenu_toggle_searchbox(); }); })(jQuery); /** * Sticky jQuery Plugin */ (function($) { "use strict"; $.maxmegamenu_sticky = function(menu, options) { var plugin = this; var $menu = $(menu); var $wrap = $menu.parent(); var breakpoint = $menu.attr('data-breakpoint'); var sticky_on_mobile = $menu.attr('data-sticky-mobile'); var sticky_on_desktop = $menu.attr('data-sticky-desktop'); var sticky_expand = $menu.attr('data-sticky-expand'); var sticky_expand_mobile = $menu.attr('data-sticky-expand-mobile'); var sticky_offset = isNaN(parseInt($menu.attr('data-sticky-offset'))) ? 0 : parseInt($menu.attr('data-sticky-offset')); var sticky_hide_until_scroll_up = $menu.attr('data-sticky-hide'); var sticky_hide_until_scroll_up_tolerance = isNaN(parseInt($menu.attr('data-sticky-hide-tolerance'))) ? 0 : parseInt($menu.attr('data-sticky-hide-tolerance')); var sticky_hide_until_scroll_up_offset = isNaN(parseInt($menu.attr('data-sticky-hide-offset'))) ? 0 : parseInt($menu.attr('data-sticky-hide-offset')); var sticky_transition = $menu.attr('data-sticky-transition'); var sticky_menu_offset_top; var sticky_menu_offset_left; var sticky_menu_width; var sticky_menu_width_round_up; var sticky_menu_height; var is_stuck = false; var admin_bar_height = 0; var last_scroll_top = 0; var saved_scroll_top = 0; var is_vertical = $menu.hasClass('mega-menu-vertical') || $menu.hasClass('mega-menu-accordion'); plugin.isDesktopView = function() { return Math.max(window.outerWidth, $(window).width()) >= breakpoint; // account for scrollbars }; var sticky_hide_until_scroll_up_enabled = function() { return $menu.hasClass('mega-menu-horizontal') && sticky_hide_until_scroll_up == "true"; } var sticky_enabled = function() { if ( plugin.isDesktopView() ) { return sticky_on_desktop === 'true'; } else { return sticky_on_mobile === 'true'; } return false; }; plugin.calculate_menu_position = function() { sticky_menu_offset_top = $wrap.offset().top; if ($('body').hasClass('admin-bar') && $("#wpadminbar").is(":visible") && $("#wpadminbar").css('top') == '0px' && $("#wpadminbar").css('position') == 'fixed') { admin_bar_height = $('#wpadminbar').height(); sticky_menu_offset_top = sticky_menu_offset_top - admin_bar_height; } if (sticky_offset < 0) { sticky_menu_offset_top = sticky_menu_offset_top + sticky_offset; } else { sticky_menu_offset_top = sticky_menu_offset_top - sticky_offset; } sticky_menu_offset_left = $menu.parent().offset().left; sticky_menu_width = window.getComputedStyle($wrap[0]).width; sticky_menu_width_round_up = Math.ceil(parseFloat(sticky_menu_width)); sticky_menu_height = $wrap.height(); }; plugin.stick_menu = function() { is_stuck = true; var total_offset = parseInt(admin_bar_height, 10) + parseInt(sticky_offset, 10); if (sticky_offset < 0) { total_offset = parseInt(admin_bar_height, 10); } var placeholder = $("
").addClass("mega-sticky-wrapper").css({ 'height' : sticky_menu_height + 'px', 'position' :'static' }); $wrap.addClass('mega-sticky').wrap(placeholder).css({ 'margin-top' : total_offset + 'px' }); $("body").addClass($menu.attr("id") + "-mega-sticky"); $menu.css({ 'max-width' : sticky_menu_width_round_up + 'px' }); if (sticky_menu_offset_left > 0) { $menu.css({ 'margin-left' : sticky_menu_offset_left + 'px' }); } if (is_vertical || sticky_expand === 'false') { $wrap.css({ 'margin-left' : '0', 'margin-right' : '0', 'width' : sticky_menu_width_round_up + 'px', 'left' : sticky_menu_offset_left + 'px' }); $menu.css({ 'margin-left' : '0' }); } if ( $(window).width() <= breakpoint ) { $wrap.css({ 'width' : sticky_menu_width_round_up + 'px' }); if (sticky_expand_mobile === 'true') { $wrap.css({ 'margin-left' : '', 'margin-right' : '', 'width' : '', 'left' : '' }); $menu.css({ 'max-width' : '', 'margin-left' : '', 'width' : '', 'left' : '' }); } } $wrap.delay(0).queue(function(next){ $(this).addClass('mega-stuck'); next(); }); }; plugin.unstick_menu = function(doing_resize) { doing_resize = doing_resize || false; is_stuck = false; $wrap.removeClass('mega-sticky').removeClass('mega-hide').css({ 'margin' : '', 'width' : '', 'left': '' }); $("body").removeClass($menu.attr("id") + "-mega-sticky"); if ( ! doing_resize ) { // this class is used for the height transition, do not remove it if we are simply resizing the window $wrap.delay(0).queue(function(next){ $(this).removeClass('mega-stuck'); next(); }); } $menu.css({ 'margin-left' : '', 'max-width' : '', 'left' : '', 'width' : '' }); if ( $(window).width() <= breakpoint ) { $menu.data('maxmegamenu').toggleBarForceWidth(); } if (sticky_transition == 'true' && ! doing_resize ) { var delay = 250; // allows the transiton to complete before unwrapping the menu } else { var delay = 0; } $wrap.delay(delay).queue(function(next){ $(this).unwrap(); next(); }); }; plugin.mega_sticky_on_scroll = function(){ if ( ! sticky_enabled() ) { return; } var scroll_top = $(window).scrollTop(); if (scroll_top > sticky_menu_offset_top) { if (!is_stuck) { plugin.stick_menu(); } } else { if (is_stuck) { plugin.unstick_menu(); } } }; var mega_hide_on_scroll_up = function() { if (sticky_hide_until_scroll_up_enabled()) { if ( $menu.data("view") === "mobile" && $('.mega-menu-toggle', $wrap).hasClass('mega-menu-open') ) { return; } var scroll_top = $(window).scrollTop(); if ( scroll_top < sticky_hide_until_scroll_up_offset ) { $wrap.removeClass('mega-hide'); $("body").removeClass($menu.attr("id") + "-mega-hide"); } saved_scroll_top = last_scroll_top; if (scroll_top < last_scroll_top) { // scroll up if (saved_scroll_top - scroll_top > sticky_hide_until_scroll_up_tolerance) { $wrap.removeClass('mega-hide'); $("body").removeClass($menu.attr("id") + "-mega-hide"); } } else { // scroll down if (is_stuck && scroll_top - saved_scroll_top > sticky_hide_until_scroll_up_tolerance) { $wrap.addClass('mega-hide'); $("body").addClass($menu.attr("id") + "-mega-hide"); } } last_scroll_top = scroll_top; } } plugin.mega_sticky_on_resize = function() { if ($('input', $wrap).is(':focus')) { return; } if ( sticky_enabled() ) { if (is_stuck) { plugin.unstick_menu(true); plugin.calculate_menu_position(); plugin.stick_menu(); } else { plugin.calculate_menu_position(); plugin.mega_sticky_on_scroll(); } } else { if (is_stuck) { plugin.unstick_menu(); } } }; plugin.init = function() { plugin.calculate_menu_position(); plugin.mega_sticky_on_scroll(); $('.mega-menu-accordion li.mega-menu-item').on('open_panel', function() { plugin.calculate_menu_position(); }); var $window = $(window); $window.scroll(function() { plugin.mega_sticky_on_scroll(); mega_hide_on_scroll_up(); }); var windowWidth = $window.width(); var resizeTimer; $window.resize(function() { clearTimeout(resizeTimer); resizeTimer = setTimeout(function(){ windowWidth = $window.width(); plugin.mega_sticky_on_resize(); }, 100); }); }; plugin.init(); }; $.fn.maxmegamenu_sticky = function(options) { return this.each(function() { if (undefined === $(this).data('maxmegamenu_sticky')) { var plugin = new $.maxmegamenu_sticky(this, options); $(this).data('maxmegamenu_sticky', plugin); } }); }; $(window).on('load', function (e) { $(".mega-menu[data-sticky-enabled]").maxmegamenu_sticky(); }); })(jQuery); /** * Handle tabbed functionality */ (function($) { $(function() { var calculate_tabbed_sub_menu_widths = function( menu_item ) { var menu = menu_item.parents('.max-mega-menu'); if( $(menu.attr('data-panel-inner-width')).length > 0 ) { if ( menu.data("view") === "desktop" ) { $('> ul.mega-sub-menu', menu_item).each(function() { var tab_content = $(this); var parent_submenu_content_width = parseInt(tab_content.width()); var parent_submenu_left_padding = parseInt(tab_content.css('paddingLeft')); var tabs_width = $(this).find('a.mega-menu-link').first().outerWidth(); $('> li.mega-menu-item > ul.mega-sub-menu', $(this)).each(function() { $(this).css('width', parent_submenu_content_width - tabs_width + 'px'); $(this).css('left', parent_submenu_left_padding + tabs_width + 'px'); }); }); } else { $('> ul.mega-sub-menu > li.mega-menu-item > ul.mega-sub-menu', menu_item).each(function() { $(this).css('width', ''); $(this).css('left', ''); }); } } } var calculate_tabbed_sub_menu_heights = function( menu_item ) { var menu = menu_item.parents('.max-mega-menu'); var max_height = 0; if ( menu.data("view") === "desktop" ) { $('> ul.mega-sub-menu', menu_item).css('minHeight', ''); $('> ul.mega-sub-menu > li.mega-menu-item > ul.mega-sub-menu', menu_item).each(function() { var tab_content = $(this); var this_height = parseInt(tab_content.css('height')); if (this_height > max_height) { max_height = this_height; } }); var border_top_width = parseInt($('> ul.mega-sub-menu', menu_item).css('borderTopWidth'),10); var border_bottom_width = parseInt($('> ul.mega-sub-menu', menu_item).css('borderBottomWidth'),10); $('> ul.mega-sub-menu', menu_item).css('minHeight', max_height + border_bottom_width + border_top_width); } else { $('> ul.mega-sub-menu', menu_item).css('minHeight', ''); } } var $window = $(window); var windowWidth = $window.width(); $window.resize(function() { if ($window.width() != windowWidth) { calculate_tabbed_sub_menu_widths($('li.mega-menu-tabbed')); calculate_tabbed_sub_menu_heights($('li.mega-menu-tabbed')); } }); $('li.mega-menu-tabbed, li.mega-menu-tabbed li.mega-collapse-children').on('open_panel', function() { var menu = $(this).parents('.max-mega-menu'); var menu_item = $(this).closest(".mega-menu-tabbed"); calculate_tabbed_sub_menu_widths( menu_item ); $("> ul.mega-sub-menu", $(this)).promise().done(function(){ // wait until slide animation has completed calculate_tabbed_sub_menu_heights( menu_item ); }); if ( menu.data('view') == 'desktop' ) { if ($('> ul.mega-sub-menu > li.mega-menu-item-has-children.mega-toggle-on', menu_item).length == 0 ) { if ( $('> ul.mega-sub-menu > li.mega-current-menu-item:visible', menu_item).length ) { $('> ul.mega-sub-menu > li.mega-current-menu-item:visible', menu_item).first().addClass('mega-toggle-on'); } else if ( $('> ul.mega-sub-menu > li.mega-current-menu-ancestor:visible', menu_item).length ) { $('> ul.mega-sub-menu > li.mega-current-menu-ancestor:visible', menu_item).first().addClass('mega-toggle-on'); } if ($('> ul.mega-sub-menu > li.mega-toggle-on', menu_item).length == 0 ) { $('> ul.mega-sub-menu > li.mega-menu-item-has-children:visible', menu_item).first().addClass('mega-toggle-on'); } } $('li.mega-menu-tabbed', menu).on('close_panel', function() { $('li.mega-menu-tabbed .mega-toggle-on', menu).removeClass('mega-toggle-on'); }); } $('li.mega-menu-tabbed li.mega-collapse-children').on('close_panel', function() { var menu_item = $(this).closest('.mega-menu-tabbed'); $("> ul.mega-sub-menu", $(this)).promise().done(function(){ // wait until slide animation has completed calculate_tabbed_sub_menu_heights( menu_item ); }); }); }); }); })(jQuery);; /** * Observe how the user enters content into the comment form in order to determine whether it's a bot or not. * * Note that no actual input is being saved here, only counts and timings between events. */ ( function() { // Passive event listeners are guaranteed to never call e.preventDefault(), // but they're not supported in all browsers. Use this feature detection // to determine whether they're available for use. var supportsPassive = false; try { var opts = Object.defineProperty( {}, 'passive', { get : function() { supportsPassive = true; } } ); window.addEventListener( 'testPassive', null, opts ); window.removeEventListener( 'testPassive', null, opts ); } catch ( e ) {} function init() { var input_begin = ''; var keydowns = {}; var lastKeyup = null; var lastKeydown = null; var keypresses = []; var modifierKeys = []; var correctionKeys = []; var lastMouseup = null; var lastMousedown = null; var mouseclicks = []; var mousemoveTimer = null; var lastMousemoveX = null; var lastMousemoveY = null; var mousemoveStart = null; var mousemoves = []; var touchmoveCountTimer = null; var touchmoveCount = 0; var lastTouchEnd = null; var lastTouchStart = null; var touchEvents = []; var scrollCountTimer = null; var scrollCount = 0; var correctionKeyCodes = [ 'Backspace', 'Delete', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Home', 'End', 'PageUp', 'PageDown' ]; var modifierKeyCodes = [ 'Shift', 'CapsLock' ]; var forms = document.querySelectorAll( 'form[method=post]' ); for ( var i = 0; i < forms.length; i++ ) { var form = forms[i]; var formAction = form.getAttribute( 'action' ); // Ignore forms that POST directly to other domains; these could be things like payment forms. if ( formAction ) { // Check that the form is posting to an external URL, not a path. if ( formAction.indexOf( 'http://' ) == 0 || formAction.indexOf( 'https://' ) == 0 ) { if ( formAction.indexOf( 'http://' + window.location.hostname + '/' ) != 0 && formAction.indexOf( 'https://' + window.location.hostname + '/' ) != 0 ) { continue; } } } form.addEventListener( 'submit', function () { var ak_bkp = prepare_timestamp_array_for_request( keypresses ); var ak_bmc = prepare_timestamp_array_for_request( mouseclicks ); var ak_bte = prepare_timestamp_array_for_request( touchEvents ); var ak_bmm = prepare_timestamp_array_for_request( mousemoves ); var input_fields = { // When did the user begin entering any input? 'bib': input_begin, // When was the form submitted? 'bfs': Date.now(), // How many keypresses did they make? 'bkpc': keypresses.length, // How quickly did they press a sample of keys, and how long between them? 'bkp': ak_bkp, // How quickly did they click the mouse, and how long between clicks? 'bmc': ak_bmc, // How many mouseclicks did they make? 'bmcc': mouseclicks.length, // When did they press modifier keys (like Shift or Capslock)? 'bmk': modifierKeys.join( ';' ), // When did they correct themselves? e.g., press Backspace, or use the arrow keys to move the cursor back 'bck': correctionKeys.join( ';' ), // How many times did they move the mouse? 'bmmc': mousemoves.length, // How many times did they move around using a touchscreen? 'btmc': touchmoveCount, // How many times did they scroll? 'bsc': scrollCount, // How quickly did they perform touch events, and how long between them? 'bte': ak_bte, // How many touch events were there? 'btec' : touchEvents.length, // How quickly did they move the mouse, and how long between moves? 'bmm' : ak_bmm }; var akismet_field_prefix = 'ak_'; if ( this.getElementsByClassName ) { // Check to see if we've used an alternate field name prefix. We store this as an attribute of the container around some of the Akismet fields. var possible_akismet_containers = this.getElementsByClassName( 'akismet-fields-container' ); for ( var containerIndex = 0; containerIndex < possible_akismet_containers.length; containerIndex++ ) { var container = possible_akismet_containers.item( containerIndex ); if ( container.getAttribute( 'data-prefix' ) ) { akismet_field_prefix = container.getAttribute( 'data-prefix' ); break; } } } for ( var field_name in input_fields ) { var field = document.createElement( 'input' ); field.setAttribute( 'type', 'hidden' ); field.setAttribute( 'name', akismet_field_prefix + field_name ); field.setAttribute( 'value', input_fields[ field_name ] ); this.appendChild( field ); } }, supportsPassive ? { passive: true } : false ); form.addEventListener( 'keydown', function ( e ) { // If you hold a key down, some browsers send multiple keydown events in a row. // Ignore any keydown events for a key that hasn't come back up yet. if ( e.key in keydowns ) { return; } var keydownTime = ( new Date() ).getTime(); keydowns[ e.key ] = [ keydownTime ]; if ( ! input_begin ) { input_begin = keydownTime; } // In some situations, we don't want to record an interval since the last keypress -- for example, // on the first keypress, or on a keypress after focus has changed to another element. Normally, // we want to record the time between the last keyup and this keydown. But if they press a // key while already pressing a key, we want to record the time between the two keydowns. var lastKeyEvent = Math.max( lastKeydown, lastKeyup ); if ( lastKeyEvent ) { keydowns[ e.key ].push( keydownTime - lastKeyEvent ); } lastKeydown = keydownTime; }, supportsPassive ? { passive: true } : false ); form.addEventListener( 'keyup', function ( e ) { if ( ! ( e.key in keydowns ) ) { // This key was pressed before this script was loaded, or a mouseclick happened during the keypress, or... return; } var keyupTime = ( new Date() ).getTime(); if ( 'TEXTAREA' === e.target.nodeName || 'INPUT' === e.target.nodeName ) { if ( -1 !== modifierKeyCodes.indexOf( e.key ) ) { modifierKeys.push( keypresses.length - 1 ); } else if ( -1 !== correctionKeyCodes.indexOf( e.key ) ) { correctionKeys.push( keypresses.length - 1 ); } else { // ^ Don't record timings for keys like Shift or backspace, since they // typically get held down for longer than regular typing. var keydownTime = keydowns[ e.key ][0]; var keypress = []; // Keypress duration. keypress.push( keyupTime - keydownTime ); // Amount of time between this keypress and the previous keypress. if ( keydowns[ e.key ].length > 1 ) { keypress.push( keydowns[ e.key ][1] ); } keypresses.push( keypress ); } } delete keydowns[ e.key ]; lastKeyup = keyupTime; }, supportsPassive ? { passive: true } : false ); form.addEventListener( "focusin", function ( e ) { lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); form.addEventListener( "focusout", function ( e ) { lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); } document.addEventListener( 'mousedown', function ( e ) { lastMousedown = ( new Date() ).getTime(); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'mouseup', function ( e ) { if ( ! lastMousedown ) { // If the mousedown happened before this script was loaded, but the mouseup happened after... return; } var now = ( new Date() ).getTime(); var mouseclick = []; mouseclick.push( now - lastMousedown ); if ( lastMouseup ) { mouseclick.push( lastMousedown - lastMouseup ); } mouseclicks.push( mouseclick ); lastMouseup = now; // If the mouse has been clicked, don't record this time as an interval between keypresses. lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'mousemove', function ( e ) { if ( mousemoveTimer ) { clearTimeout( mousemoveTimer ); mousemoveTimer = null; } else { mousemoveStart = ( new Date() ).getTime(); lastMousemoveX = e.offsetX; lastMousemoveY = e.offsetY; } mousemoveTimer = setTimeout( function ( theEvent, originalMousemoveStart ) { var now = ( new Date() ).getTime() - 500; // To account for the timer delay. var mousemove = []; mousemove.push( now - originalMousemoveStart ); mousemove.push( Math.round( Math.sqrt( Math.pow( theEvent.offsetX - lastMousemoveX, 2 ) + Math.pow( theEvent.offsetY - lastMousemoveY, 2 ) ) ) ); if ( mousemove[1] > 0 ) { // If there was no measurable distance, then it wasn't really a move. mousemoves.push( mousemove ); } mousemoveStart = null; mousemoveTimer = null; }, 500, e, mousemoveStart ); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'touchmove', function ( e ) { if ( touchmoveCountTimer ) { clearTimeout( touchmoveCountTimer ); } touchmoveCountTimer = setTimeout( function () { touchmoveCount++; }, 500 ); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'touchstart', function ( e ) { lastTouchStart = ( new Date() ).getTime(); }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'touchend', function ( e ) { if ( ! lastTouchStart ) { // If the touchstart happened before this script was loaded, but the touchend happened after... return; } var now = ( new Date() ).getTime(); var touchEvent = []; touchEvent.push( now - lastTouchStart ); if ( lastTouchEnd ) { touchEvent.push( lastTouchStart - lastTouchEnd ); } touchEvents.push( touchEvent ); lastTouchEnd = now; // Don't record this time as an interval between keypresses. lastKeydown = null; lastKeyup = null; keydowns = {}; }, supportsPassive ? { passive: true } : false ); document.addEventListener( 'scroll', function ( e ) { if ( scrollCountTimer ) { clearTimeout( scrollCountTimer ); } scrollCountTimer = setTimeout( function () { scrollCount++; }, 500 ); }, supportsPassive ? { passive: true } : false ); } /** * For the timestamp data that is collected, don't send more than `limit` data points in the request. * Choose a random slice and send those. */ function prepare_timestamp_array_for_request( a, limit ) { if ( ! limit ) { limit = 100; } var rv = ''; if ( a.length > 0 ) { var random_starting_point = Math.max( 0, Math.floor( Math.random() * a.length - limit ) ); for ( var i = 0; i < limit && i < a.length; i++ ) { rv += a[ random_starting_point + i ][0]; if ( a[ random_starting_point + i ].length >= 2 ) { rv += "," + a[ random_starting_point + i ][1]; } rv += ";"; } } return rv; } if ( document.readyState !== 'loading' ) { init(); } else { document.addEventListener( 'DOMContentLoaded', init ); } })();;