/** * File navigation.js * * Handles toggling the navigation menu for small screens and enables tab * support for dropdown menus. * * @package Astra */ /** * Get all of an element's parent elements up the DOM tree * * @param {Node} elem The element. * @param {String} selector Selector to match against [optional]. * @return {Array} The parent elements. */ var getParents = function ( elem, selector ) { // Element.matches() polyfill. if ( ! Element.prototype.matches) { Element.prototype.matches = Element.prototype.matchesSelector || Element.prototype.mozMatchesSelector || Element.prototype.msMatchesSelector || Element.prototype.oMatchesSelector || Element.prototype.webkitMatchesSelector || function(s) { var matches = (this.document || this.ownerDocument).querySelectorAll( s ), i = matches.length; while (--i >= 0 && matches.item( i ) !== this) {} return i > -1; }; } // Setup parents array. var parents = []; // Get matching parent elements. for ( ; elem && elem !== document; elem = elem.parentNode ) { // Add matching parents to array. if ( selector ) { if ( elem.matches( selector ) ) { parents.push( elem ); } } else { parents.push( elem ); } } return parents; }; /** * Toggle Class funtion * * @param {Node} elem The element. * @param {String} selector Selector to match against [optional]. * @return {Array} The parent elements. */ var toggleClass = function ( el, className ) { if ( el.classList.contains( className ) ) { el.classList.remove( className ); } else { el.classList.add( className ); } }; // CustomEvent() constructor functionality in Internet Explorer 9 and higher. (function () { if (typeof window.CustomEvent === "function") return false; function CustomEvent(event, params) { params = params || { bubbles: false, cancelable: false, detail: undefined }; var evt = document.createEvent('CustomEvent'); evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); return evt; } CustomEvent.prototype = window.Event.prototype; window.CustomEvent = CustomEvent; })(); /** * Trigget custom JS Event. * * @since 1.4.6 * * @link https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent * @param {Node} el Dom Node element on which the event is to be triggered. * @param {Node} typeArg A DOMString representing the name of the event. * @param {String} A CustomEventInit dictionary, having the following fields: * "detail", optional and defaulting to null, of type any, that is an event-dependent value associated with the event. */ var astraTriggerEvent = function astraTriggerEvent( el, typeArg ) { var customEventInit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; var event = new CustomEvent(typeArg, customEventInit); el.dispatchEvent(event); }; ( function() { var menu_toggle_all = document.querySelectorAll( '.main-header-menu-toggle' ); /* Add break point Class and related trigger */ var updateHeaderBreakPoint = function () { var break_point = astra.break_point, headerWrap = document.querySelectorAll( '.main-header-bar-wrap' ); if ( headerWrap.length > 0 ) { for ( var i = 0; i < headerWrap.length; i++ ) { if ( headerWrap[i].tagName == 'DIV' && headerWrap[i].classList.contains( 'main-header-bar-wrap' ) ) { if ( window.innerWidth > break_point ) { //remove menu toggled class. if ( null != menu_toggle_all[i] ) { menu_toggle_all[i].classList.remove( 'toggled' ); } document.body.classList.remove( "ast-header-break-point" ); document.body.classList.add("ast-desktop"); astraTriggerEvent( document.body, "astra-header-responsive-enabled" ); } else { document.body.classList.add( "ast-header-break-point" ); document.body.classList.remove("ast-desktop"); astraTriggerEvent( document.body, "astra-header-responsive-disabled" ) } } } } } updateHeaderBreakPoint(); AstraNavigationMenu = function( parentList ) { for (var i = 0; i < parentList.length; i++) { if ( null != parentList[i].querySelector( '.sub-menu, .children' ) ) { // Insert Toggle Button. var toggleButton = document.createElement("BUTTON"); // Create a