updated theme GeneratePress
version 3.0.4
This commit is contained in:
@ -1,127 +1,127 @@
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
var body = document.body;
|
||||
|
||||
body.addEventListener( 'mousedown', function() {
|
||||
body.classList.add( 'using-mouse' );
|
||||
} );
|
||||
|
||||
body.addEventListener( 'keydown', function() {
|
||||
body.classList.remove( 'using-mouse' );
|
||||
} );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var navLinks = document.querySelectorAll( 'nav .main-nav ul a' ),
|
||||
menuBarItems = document.querySelectorAll( '.menu-bar-items .menu-bar-item > a' );
|
||||
|
||||
/**
|
||||
* Make menu items tab accessible when using the hover dropdown type
|
||||
*/
|
||||
var toggleFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'main-nav' ) ) {
|
||||
if ( 'li' === self.tagName.toLowerCase() ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make our menu bar items tab accessible.
|
||||
*/
|
||||
var toggleMenuBarItemFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'menu-bar-items' ) ) {
|
||||
if ( self.classList.contains( 'menu-bar-item' ) ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'focus', toggleFocus );
|
||||
navLinks[i].addEventListener( 'blur', toggleFocus );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < menuBarItems.length; i++ ) {
|
||||
menuBarItems[i].addEventListener( 'focus', toggleMenuBarItemFocus );
|
||||
menuBarItems[i].addEventListener( 'blur', toggleMenuBarItemFocus );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make hover dropdown touch-friendly.
|
||||
*/
|
||||
if ( 'ontouchend' in document.documentElement && document.body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var parentElements = document.querySelectorAll( '.sf-menu .menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < parentElements.length; i++ ) {
|
||||
parentElements[i].addEventListener( 'touchend', function( e ) {
|
||||
|
||||
// Bail on mobile
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( e.touches.length === 1 || e.touches.length === 0 ) {
|
||||
// Prevent touch events within dropdown bubbling down to document
|
||||
e.stopPropagation();
|
||||
|
||||
// Toggle hover
|
||||
if ( ! this.classList.contains( 'sfHover' ) ) {
|
||||
// Prevent link on first touch
|
||||
if ( e.target === this || e.target.parentNode === this || e.target.parentNode.parentNode ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
// Close other sub-menus.
|
||||
var closestLi = this.closest( 'li' ),
|
||||
siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
}
|
||||
}
|
||||
|
||||
this.classList.add( 'sfHover' );
|
||||
|
||||
// Hide dropdown on touch outside
|
||||
var closeDropdown,
|
||||
thisItem = this;
|
||||
|
||||
document.addEventListener( 'touchend', closeDropdown = function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
thisItem.classList.remove( 'sfHover' );
|
||||
document.removeEventListener( 'touchend', closeDropdown );
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} )();
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
var body = document.body;
|
||||
|
||||
body.addEventListener( 'mousedown', function() {
|
||||
body.classList.add( 'using-mouse' );
|
||||
} );
|
||||
|
||||
body.addEventListener( 'keydown', function() {
|
||||
body.classList.remove( 'using-mouse' );
|
||||
} );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var navLinks = document.querySelectorAll( 'nav .main-nav ul a' ),
|
||||
menuBarItems = document.querySelectorAll( '.menu-bar-items .menu-bar-item > a' );
|
||||
|
||||
/**
|
||||
* Make menu items tab accessible when using the hover dropdown type
|
||||
*/
|
||||
var toggleFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'main-nav' ) ) {
|
||||
if ( 'li' === self.tagName.toLowerCase() ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make our menu bar items tab accessible.
|
||||
*/
|
||||
var toggleMenuBarItemFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'menu-bar-items' ) ) {
|
||||
if ( self.classList.contains( 'menu-bar-item' ) ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'focus', toggleFocus );
|
||||
navLinks[i].addEventListener( 'blur', toggleFocus );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < menuBarItems.length; i++ ) {
|
||||
menuBarItems[i].addEventListener( 'focus', toggleMenuBarItemFocus );
|
||||
menuBarItems[i].addEventListener( 'blur', toggleMenuBarItemFocus );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make hover dropdown touch-friendly.
|
||||
*/
|
||||
if ( 'ontouchend' in document.documentElement && document.body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var parentElements = document.querySelectorAll( '.sf-menu .menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < parentElements.length; i++ ) {
|
||||
parentElements[i].addEventListener( 'touchend', function( e ) {
|
||||
|
||||
// Bail on mobile
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( e.touches.length === 1 || e.touches.length === 0 ) {
|
||||
// Prevent touch events within dropdown bubbling down to document
|
||||
e.stopPropagation();
|
||||
|
||||
// Toggle hover
|
||||
if ( ! this.classList.contains( 'sfHover' ) ) {
|
||||
// Prevent link on first touch
|
||||
if ( e.target === this || e.target.parentNode === this || e.target.parentNode.parentNode ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
// Close other sub-menus.
|
||||
var closestLi = this.closest( 'li' ),
|
||||
siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
}
|
||||
}
|
||||
|
||||
this.classList.add( 'sfHover' );
|
||||
|
||||
// Hide dropdown on touch outside
|
||||
var closeDropdown,
|
||||
thisItem = this;
|
||||
|
||||
document.addEventListener( 'touchend', closeDropdown = function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
thisItem.classList.remove( 'sfHover' );
|
||||
document.removeEventListener( 'touchend', closeDropdown );
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} )();
|
||||
|
@ -1,65 +1,65 @@
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
// Feature Test
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
|
||||
var goTopBtn = document.querySelector( '.generate-back-to-top' );
|
||||
|
||||
var trackScroll = function() {
|
||||
var scrolled = window.pageYOffset;
|
||||
var coords = goTopBtn.getAttribute( 'data-start-scroll' ) ;
|
||||
|
||||
if ( scrolled > coords ) {
|
||||
goTopBtn.style.opacity = '1';
|
||||
goTopBtn.style.visibility = 'visible';
|
||||
}
|
||||
|
||||
if (scrolled < coords) {
|
||||
goTopBtn.style.opacity = '0';
|
||||
goTopBtn.style.visibility = 'hidden';
|
||||
}
|
||||
};
|
||||
|
||||
// Function to animate the scroll
|
||||
var smoothScroll = function (anchor, duration) {
|
||||
// Calculate how far and how fast to scroll
|
||||
var startLocation = window.pageYOffset;
|
||||
var endLocation = document.body.offsetTop;
|
||||
var distance = endLocation - startLocation;
|
||||
var increments = distance/(duration/16);
|
||||
var stopAnimation;
|
||||
|
||||
// Scroll the page by an increment, and check if it's time to stop
|
||||
var animateScroll = function () {
|
||||
window.scrollBy(0, increments);
|
||||
stopAnimation();
|
||||
};
|
||||
|
||||
// Stop animation when you reach the anchor OR the top of the page
|
||||
stopAnimation = function () {
|
||||
var travelled = window.pageYOffset;
|
||||
if ( travelled <= (endLocation || 0) ) {
|
||||
clearInterval(runAnimation);
|
||||
document.activeElement.blur();
|
||||
}
|
||||
};
|
||||
|
||||
// Loop the animation function
|
||||
var runAnimation = setInterval(animateScroll, 16);
|
||||
};
|
||||
|
||||
if ( goTopBtn ) {
|
||||
// Show the button when scrolling down.
|
||||
window.addEventListener( 'scroll', trackScroll );
|
||||
|
||||
// Scroll back to top when clicked.
|
||||
goTopBtn.addEventListener( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
smoothScroll( document.body, goTopBtn.getAttribute( 'data-scroll-speed' ) || 400 );
|
||||
}, false );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} )();
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
// Feature Test
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
|
||||
var goTopBtn = document.querySelector( '.generate-back-to-top' );
|
||||
|
||||
var trackScroll = function() {
|
||||
var scrolled = window.pageYOffset;
|
||||
var coords = goTopBtn.getAttribute( 'data-start-scroll' ) ;
|
||||
|
||||
if ( scrolled > coords ) {
|
||||
goTopBtn.style.opacity = '1';
|
||||
goTopBtn.style.visibility = 'visible';
|
||||
}
|
||||
|
||||
if (scrolled < coords) {
|
||||
goTopBtn.style.opacity = '0';
|
||||
goTopBtn.style.visibility = 'hidden';
|
||||
}
|
||||
};
|
||||
|
||||
// Function to animate the scroll
|
||||
var smoothScroll = function (anchor, duration) {
|
||||
// Calculate how far and how fast to scroll
|
||||
var startLocation = window.pageYOffset;
|
||||
var endLocation = document.body.offsetTop;
|
||||
var distance = endLocation - startLocation;
|
||||
var increments = distance/(duration/16);
|
||||
var stopAnimation;
|
||||
|
||||
// Scroll the page by an increment, and check if it's time to stop
|
||||
var animateScroll = function () {
|
||||
window.scrollBy(0, increments);
|
||||
stopAnimation();
|
||||
};
|
||||
|
||||
// Stop animation when you reach the anchor OR the top of the page
|
||||
stopAnimation = function () {
|
||||
var travelled = window.pageYOffset;
|
||||
if ( travelled <= (endLocation || 0) ) {
|
||||
clearInterval(runAnimation);
|
||||
document.activeElement.blur();
|
||||
}
|
||||
};
|
||||
|
||||
// Loop the animation function
|
||||
var runAnimation = setInterval(animateScroll, 16);
|
||||
};
|
||||
|
||||
if ( goTopBtn ) {
|
||||
// Show the button when scrolling down.
|
||||
window.addEventListener( 'scroll', trackScroll );
|
||||
|
||||
// Scroll back to top when clicked.
|
||||
goTopBtn.addEventListener( 'click', function( e ) {
|
||||
e.preventDefault();
|
||||
smoothScroll( document.body, goTopBtn.getAttribute( 'data-scroll-speed' ) || 400 );
|
||||
}, false );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} )();
|
||||
|
@ -1,124 +1,124 @@
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
var body = document.body;
|
||||
/**
|
||||
* Dropdown click
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var dropdownClick = function( e, _this ) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
var closestLi = _this.closest( 'li' );
|
||||
|
||||
// Close other sub-menus
|
||||
var openedSubMenus = _this.closest( 'nav' ).querySelectorAll( 'ul.toggled-on' );
|
||||
if ( openedSubMenus && ! _this.closest( 'ul' ).classList.contains( 'toggled-on' ) && ! _this.closest( 'li' ).classList.contains( 'sfHover' ) ) {
|
||||
for ( var o = 0; o < openedSubMenus.length; o++ ) {
|
||||
openedSubMenus[o].classList.remove( 'toggled-on' );
|
||||
openedSubMenus[o].closest( 'li' ).classList.remove( 'sfHover' );
|
||||
}
|
||||
}
|
||||
|
||||
// Add sfHover class to parent li
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
|
||||
// Set aria-expanded on arrow
|
||||
var dropdownToggle = closestLi.querySelector( '.dropdown-menu-toggle' );
|
||||
if ( 'false' === dropdownToggle.getAttribute( 'aria-expanded' ) || ! dropdownToggle.getAttribute( 'aria-expanded' ) ) {
|
||||
dropdownToggle.setAttribute( 'aria-expanded', 'true' );
|
||||
} else {
|
||||
dropdownToggle.setAttribute( 'aria-expanded', 'false' );
|
||||
}
|
||||
|
||||
if ( closestLi.querySelector( '.sub-menu' ) ) {
|
||||
var subMenuSelector = '.sub-menu';
|
||||
} else {
|
||||
var subMenuSelector = '.children';
|
||||
}
|
||||
|
||||
// Open the sub-menu
|
||||
if ( body.classList.contains( 'dropdown-click-menu-item' ) ) {
|
||||
_this.parentNode.querySelector( subMenuSelector ).classList.toggle( 'toggled-on' );
|
||||
} else if ( body.classList.contains( 'dropdown-click-arrow' ) ) {
|
||||
closestLi.querySelector( subMenuSelector ).classList.toggle( 'toggled-on' );
|
||||
}
|
||||
}
|
||||
|
||||
// Do stuff if click dropdown if enabled
|
||||
var parentElementLinks = document.querySelectorAll( '.main-nav .menu-item-has-children > a' );
|
||||
|
||||
// Open the sub-menu by clicking on the entire link element
|
||||
if ( body.classList.contains( 'dropdown-click-menu-item' ) ) {
|
||||
for ( var i = 0; i < parentElementLinks.length; i++ ) {
|
||||
parentElementLinks[i].addEventListener( 'click', dropdownClick, true );
|
||||
}
|
||||
}
|
||||
|
||||
// Open the sub-menu by clicking on a dropdown arrow
|
||||
if ( body.classList.contains( 'dropdown-click-arrow' ) ) {
|
||||
// Add a class to sub-menu items that are set to #
|
||||
for ( var i = 0; i < document.querySelectorAll( '.main-nav .menu-item-has-children > a' ).length; i++ ) {
|
||||
if ( '#' == document.querySelectorAll( '.main-nav .menu-item-has-children > a' )[i].getAttribute( 'href' ) ) {
|
||||
document.querySelectorAll( '.main-nav .menu-item-has-children > a' )[i].classList.add( 'menu-item-dropdown-click' );
|
||||
}
|
||||
}
|
||||
|
||||
var dropdownToggleLinks = document.querySelectorAll( '.main-nav .menu-item-has-children > a .dropdown-menu-toggle' );
|
||||
for ( var i = 0; i < dropdownToggleLinks.length; i++ ) {
|
||||
dropdownToggleLinks[i].addEventListener( 'click', dropdownClick, false );
|
||||
|
||||
dropdownToggleLinks[i].addEventListener( 'keydown', function( e ) {
|
||||
var _this = this;
|
||||
var key = e.which || e.keyCode;
|
||||
if ( key === 13 ) { // 13 is enter
|
||||
dropdownClick( e, _this );
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < document.querySelectorAll( '.main-nav .menu-item-has-children > a.menu-item-dropdown-click' ).length; i++ ) {
|
||||
document.querySelectorAll( '.main-nav .menu-item-has-children > a.menu-item-dropdown-click' )[i].addEventListener( 'click', dropdownClick, false );
|
||||
}
|
||||
}
|
||||
|
||||
var closeSubMenus = function() {
|
||||
if ( document.querySelector( 'nav ul .toggled-on' ) ) {
|
||||
var activeSubMenus = document.querySelectorAll( 'nav ul .toggled-on' );
|
||||
var activeDropdownToggles = document.querySelectorAll( 'nav .dropdown-menu-toggle' );
|
||||
for ( var i = 0; i < activeSubMenus.length; i++ ) {
|
||||
activeSubMenus[i].classList.remove( 'toggled-on' );
|
||||
activeSubMenus[i].closest( '.sfHover' ).classList.remove( 'sfHover' );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < activeDropdownToggles.length; i++ ) {
|
||||
activeDropdownToggles[i].setAttribute( 'aria-expanded', 'false' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close sub-menus when clicking elsewhere
|
||||
document.addEventListener( 'click', function ( event ) {
|
||||
if ( ! event.target.closest( '.sfHover' ) ) {
|
||||
closeSubMenus();
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Close sub-menus on escape key
|
||||
document.addEventListener( 'keydown', function( e ) {
|
||||
var key = e.which || e.keyCode;
|
||||
if ( key === 27 ) { // 27 is esc
|
||||
closeSubMenus();
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
})();
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
var body = document.body;
|
||||
/**
|
||||
* Dropdown click
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var dropdownClick = function( e, _this ) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
var closestLi = _this.closest( 'li' );
|
||||
|
||||
// Close other sub-menus
|
||||
var openedSubMenus = _this.closest( 'nav' ).querySelectorAll( 'ul.toggled-on' );
|
||||
if ( openedSubMenus && ! _this.closest( 'ul' ).classList.contains( 'toggled-on' ) && ! _this.closest( 'li' ).classList.contains( 'sfHover' ) ) {
|
||||
for ( var o = 0; o < openedSubMenus.length; o++ ) {
|
||||
openedSubMenus[o].classList.remove( 'toggled-on' );
|
||||
openedSubMenus[o].closest( 'li' ).classList.remove( 'sfHover' );
|
||||
}
|
||||
}
|
||||
|
||||
// Add sfHover class to parent li
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
|
||||
// Set aria-expanded on arrow
|
||||
var dropdownToggle = closestLi.querySelector( '.dropdown-menu-toggle' );
|
||||
if ( 'false' === dropdownToggle.getAttribute( 'aria-expanded' ) || ! dropdownToggle.getAttribute( 'aria-expanded' ) ) {
|
||||
dropdownToggle.setAttribute( 'aria-expanded', 'true' );
|
||||
} else {
|
||||
dropdownToggle.setAttribute( 'aria-expanded', 'false' );
|
||||
}
|
||||
|
||||
if ( closestLi.querySelector( '.sub-menu' ) ) {
|
||||
var subMenuSelector = '.sub-menu';
|
||||
} else {
|
||||
var subMenuSelector = '.children';
|
||||
}
|
||||
|
||||
// Open the sub-menu
|
||||
if ( body.classList.contains( 'dropdown-click-menu-item' ) ) {
|
||||
_this.parentNode.querySelector( subMenuSelector ).classList.toggle( 'toggled-on' );
|
||||
} else if ( body.classList.contains( 'dropdown-click-arrow' ) ) {
|
||||
closestLi.querySelector( subMenuSelector ).classList.toggle( 'toggled-on' );
|
||||
}
|
||||
}
|
||||
|
||||
// Do stuff if click dropdown if enabled
|
||||
var parentElementLinks = document.querySelectorAll( '.main-nav .menu-item-has-children > a' );
|
||||
|
||||
// Open the sub-menu by clicking on the entire link element
|
||||
if ( body.classList.contains( 'dropdown-click-menu-item' ) ) {
|
||||
for ( var i = 0; i < parentElementLinks.length; i++ ) {
|
||||
parentElementLinks[i].addEventListener( 'click', dropdownClick, true );
|
||||
}
|
||||
}
|
||||
|
||||
// Open the sub-menu by clicking on a dropdown arrow
|
||||
if ( body.classList.contains( 'dropdown-click-arrow' ) ) {
|
||||
// Add a class to sub-menu items that are set to #
|
||||
for ( var i = 0; i < document.querySelectorAll( '.main-nav .menu-item-has-children > a' ).length; i++ ) {
|
||||
if ( '#' == document.querySelectorAll( '.main-nav .menu-item-has-children > a' )[i].getAttribute( 'href' ) ) {
|
||||
document.querySelectorAll( '.main-nav .menu-item-has-children > a' )[i].classList.add( 'menu-item-dropdown-click' );
|
||||
}
|
||||
}
|
||||
|
||||
var dropdownToggleLinks = document.querySelectorAll( '.main-nav .menu-item-has-children > a .dropdown-menu-toggle' );
|
||||
for ( var i = 0; i < dropdownToggleLinks.length; i++ ) {
|
||||
dropdownToggleLinks[i].addEventListener( 'click', dropdownClick, false );
|
||||
|
||||
dropdownToggleLinks[i].addEventListener( 'keydown', function( e ) {
|
||||
var _this = this;
|
||||
var key = e.which || e.keyCode;
|
||||
if ( key === 13 ) { // 13 is enter
|
||||
dropdownClick( e, _this );
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < document.querySelectorAll( '.main-nav .menu-item-has-children > a.menu-item-dropdown-click' ).length; i++ ) {
|
||||
document.querySelectorAll( '.main-nav .menu-item-has-children > a.menu-item-dropdown-click' )[i].addEventListener( 'click', dropdownClick, false );
|
||||
}
|
||||
}
|
||||
|
||||
var closeSubMenus = function() {
|
||||
if ( document.querySelector( 'nav ul .toggled-on' ) ) {
|
||||
var activeSubMenus = document.querySelectorAll( 'nav ul .toggled-on' );
|
||||
var activeDropdownToggles = document.querySelectorAll( 'nav .dropdown-menu-toggle' );
|
||||
for ( var i = 0; i < activeSubMenus.length; i++ ) {
|
||||
activeSubMenus[i].classList.remove( 'toggled-on' );
|
||||
activeSubMenus[i].closest( '.sfHover' ).classList.remove( 'sfHover' );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < activeDropdownToggles.length; i++ ) {
|
||||
activeDropdownToggles[i].setAttribute( 'aria-expanded', 'false' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close sub-menus when clicking elsewhere
|
||||
document.addEventListener( 'click', function ( event ) {
|
||||
if ( ! event.target.closest( '.sfHover' ) ) {
|
||||
closeSubMenus();
|
||||
}
|
||||
}, false);
|
||||
|
||||
// Close sub-menus on escape key
|
||||
document.addEventListener( 'keydown', function( e ) {
|
||||
var key = e.which || e.keyCode;
|
||||
if ( key === 27 ) { // 27 is esc
|
||||
closeSubMenus();
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
})();
|
||||
|
@ -1,430 +1,430 @@
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
/**
|
||||
* matches() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.matches ) {
|
||||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* closest() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.closest ) {
|
||||
Element.prototype.closest = function( s ) {
|
||||
var el = this;
|
||||
var ancestor = this;
|
||||
if ( ! document.documentElement.contains( el ) ) {
|
||||
return null;
|
||||
}
|
||||
do {
|
||||
if ( ancestor.matches( s ) ) {
|
||||
return ancestor;
|
||||
}
|
||||
ancestor = ancestor.parentElement;
|
||||
} while ( ancestor !== null );
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
var allNavToggles = document.querySelectorAll( '.menu-toggle' ),
|
||||
dropdownToggle = document.querySelectorAll( 'nav .dropdown-menu-toggle' ),
|
||||
navLinks = document.querySelectorAll( 'nav ul a' ),
|
||||
mobileMenuControls = document.querySelector( '.mobile-menu-control-wrapper' ),
|
||||
body = document.body,
|
||||
htmlEl = document.documentElement;
|
||||
|
||||
var enableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'tabindex', '0' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'button' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-expanded', 'false' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var disableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'tabindex' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'presentation' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-expanded' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-label' );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var setDropdownArrowAttributes = function( arrow ) {
|
||||
if ( 'false' === arrow.getAttribute( 'aria-expanded' ) || ! arrow.getAttribute( 'aria-expanded' ) ) {
|
||||
arrow.setAttribute( 'aria-expanded', 'true' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.closeSubMenuLabel );
|
||||
} else {
|
||||
arrow.setAttribute( 'aria-expanded', 'false' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Start mobile menu toggle.
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleNav = function( e, _this ) {
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
var parentContainer = '';
|
||||
|
||||
if ( _this.getAttribute( 'data-nav' ) ) {
|
||||
parentContainer = document.getElementById( _this.getAttribute( 'data-nav' ) );
|
||||
} else {
|
||||
parentContainer = document.getElementById( _this.closest( 'nav' ).getAttribute( 'id' ) );
|
||||
}
|
||||
|
||||
if ( ! parentContainer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var isExternalToggle = false;
|
||||
|
||||
if ( _this.closest( '.mobile-menu-control-wrapper' ) ) {
|
||||
isExternalToggle = true;
|
||||
}
|
||||
|
||||
var nav = parentContainer.getElementsByTagName( 'ul' )[0];
|
||||
|
||||
if ( parentContainer.classList.contains( 'toggled' ) ) {
|
||||
parentContainer.classList.remove( 'toggled' );
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'true' );
|
||||
_this.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
}
|
||||
|
||||
disableDropdownArrows( nav );
|
||||
} else {
|
||||
parentContainer.classList.add( 'toggled' );
|
||||
htmlEl.classList.add( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'false' );
|
||||
_this.setAttribute( 'aria-expanded', 'true' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
}
|
||||
|
||||
enableDropdownArrows( nav );
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < allNavToggles.length; i++ ) {
|
||||
allNavToggles[i].addEventListener( 'click', toggleNav, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Open sub-menus
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleSubNav = function( e, _this ) {
|
||||
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
if ( ( _this.closest( 'nav' ).classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) && ! body.classList.contains( 'dropdown-click' ) ) {
|
||||
e.preventDefault();
|
||||
var closestLi = _this.closest( 'li' );
|
||||
|
||||
setDropdownArrowAttributes( closestLi.querySelector( '.dropdown-menu-toggle' ) );
|
||||
|
||||
if ( closestLi.querySelector( '.sub-menu' ) ) {
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
} else {
|
||||
var subMenu = closestLi.querySelector( '.children' );
|
||||
}
|
||||
|
||||
if ( generatepressMenu.toggleOpenedSubMenus ) {
|
||||
var siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
siblings[i].querySelector( '.toggled-on' ).classList.remove( 'toggled-on' );
|
||||
setDropdownArrowAttributes( siblings[i].querySelector( '.dropdown-menu-toggle' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
for ( var i = 0; i < dropdownToggle.length; i++ ) {
|
||||
dropdownToggle[i].addEventListener( 'click', toggleSubNav, false );
|
||||
dropdownToggle[i].addEventListener( 'keypress', function( e ) {
|
||||
var key = e.which || e.keyCode;
|
||||
if (key === 13) { // 13 is enter
|
||||
toggleSubNav( e, this );
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the mobile menu if our toggle isn't visible.
|
||||
* Makes it possible to style mobile item with .toggled class.
|
||||
*/
|
||||
var checkMobile = function() {
|
||||
var openedMobileMenus = document.querySelectorAll( '.toggled, .has-active-search' );
|
||||
|
||||
for ( var i = 0; i < openedMobileMenus.length; i++ ) {
|
||||
var menuToggle = openedMobileMenus[i].querySelector( '.menu-toggle' );
|
||||
|
||||
if ( mobileMenuControls && ! menuToggle.closest( 'nav' ).classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
menuToggle = mobileMenuControls.querySelector( '.menu-toggle' );
|
||||
}
|
||||
|
||||
if ( menuToggle && menuToggle.offsetParent === null ) {
|
||||
if ( openedMobileMenus[i].classList.contains( 'toggled' ) ) {
|
||||
var remoteNav = false;
|
||||
|
||||
if ( openedMobileMenus[i].classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
remoteNav = true;
|
||||
}
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
// Navigation is toggled, but .menu-toggle isn't visible on the page (display: none).
|
||||
var closestNav = openedMobileMenus[i].getElementsByTagName( 'ul' )[ 0 ],
|
||||
closestNavItems = closestNav.getElementsByTagName( 'li' ),
|
||||
closestSubMenus = closestNav.getElementsByTagName( 'ul' );
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
openedMobileMenus[i].classList.remove( 'toggled' );
|
||||
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
menuToggle.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
for ( var li = 0; li < closestNavItems.length; li++ ) {
|
||||
closestNavItems[li].classList.remove( 'sfHover' );
|
||||
}
|
||||
|
||||
for ( var sm = 0; sm < closestSubMenus.length; sm++ ) {
|
||||
closestSubMenus[sm].classList.remove( 'toggled-on' );
|
||||
}
|
||||
|
||||
if ( closestNav ) {
|
||||
closestNav.removeAttribute( 'aria-hidden' );
|
||||
}
|
||||
}
|
||||
|
||||
disableDropdownArrows( openedMobileMenus[i] );
|
||||
}
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener( 'resize', checkMobile, false );
|
||||
window.addEventListener( 'orientationchange', checkMobile, false );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
/**
|
||||
* Do some essential things when menu items are clicked.
|
||||
*/
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'click', function( e ) {
|
||||
// Remove sfHover class if we're going to another site.
|
||||
if ( this.hostname !== window.location.hostname ) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
var closest_nav = this.closest( 'nav' );
|
||||
if ( closest_nav.classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) {
|
||||
var url = this.getAttribute( 'href' );
|
||||
|
||||
// Open the sub-menu if the link has no destination
|
||||
if ( '#' == url || '' == url ) {
|
||||
e.preventDefault();
|
||||
var closestLi = this.closest( 'li' );
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
|
||||
if ( subMenu ) {
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
var body = document.body;
|
||||
|
||||
body.addEventListener( 'mousedown', function() {
|
||||
body.classList.add( 'using-mouse' );
|
||||
} );
|
||||
|
||||
body.addEventListener( 'keydown', function() {
|
||||
body.classList.remove( 'using-mouse' );
|
||||
} );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var navLinks = document.querySelectorAll( 'nav .main-nav ul a' ),
|
||||
menuBarItems = document.querySelectorAll( '.menu-bar-items .menu-bar-item > a' );
|
||||
|
||||
/**
|
||||
* Make menu items tab accessible when using the hover dropdown type
|
||||
*/
|
||||
var toggleFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'main-nav' ) ) {
|
||||
if ( 'li' === self.tagName.toLowerCase() ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make our menu bar items tab accessible.
|
||||
*/
|
||||
var toggleMenuBarItemFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'menu-bar-items' ) ) {
|
||||
if ( self.classList.contains( 'menu-bar-item' ) ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'focus', toggleFocus );
|
||||
navLinks[i].addEventListener( 'blur', toggleFocus );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < menuBarItems.length; i++ ) {
|
||||
menuBarItems[i].addEventListener( 'focus', toggleMenuBarItemFocus );
|
||||
menuBarItems[i].addEventListener( 'blur', toggleMenuBarItemFocus );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make hover dropdown touch-friendly.
|
||||
*/
|
||||
if ( 'ontouchend' in document.documentElement && document.body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var parentElements = document.querySelectorAll( '.sf-menu .menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < parentElements.length; i++ ) {
|
||||
parentElements[i].addEventListener( 'touchend', function( e ) {
|
||||
|
||||
// Bail on mobile
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( e.touches.length === 1 || e.touches.length === 0 ) {
|
||||
// Prevent touch events within dropdown bubbling down to document
|
||||
e.stopPropagation();
|
||||
|
||||
// Toggle hover
|
||||
if ( ! this.classList.contains( 'sfHover' ) ) {
|
||||
// Prevent link on first touch
|
||||
if ( e.target === this || e.target.parentNode === this || e.target.parentNode.parentNode ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
// Close other sub-menus.
|
||||
var closestLi = this.closest( 'li' ),
|
||||
siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
}
|
||||
}
|
||||
|
||||
this.classList.add( 'sfHover' );
|
||||
|
||||
// Hide dropdown on touch outside
|
||||
var closeDropdown,
|
||||
thisItem = this;
|
||||
|
||||
document.addEventListener( 'touchend', closeDropdown = function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
thisItem.classList.remove( 'sfHover' );
|
||||
document.removeEventListener( 'touchend', closeDropdown );
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} )();
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
/**
|
||||
* matches() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.matches ) {
|
||||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* closest() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.closest ) {
|
||||
Element.prototype.closest = function( s ) {
|
||||
var el = this;
|
||||
var ancestor = this;
|
||||
if ( ! document.documentElement.contains( el ) ) {
|
||||
return null;
|
||||
}
|
||||
do {
|
||||
if ( ancestor.matches( s ) ) {
|
||||
return ancestor;
|
||||
}
|
||||
ancestor = ancestor.parentElement;
|
||||
} while ( ancestor !== null );
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
var allNavToggles = document.querySelectorAll( '.menu-toggle' ),
|
||||
dropdownToggle = document.querySelectorAll( 'nav .dropdown-menu-toggle' ),
|
||||
navLinks = document.querySelectorAll( 'nav ul a' ),
|
||||
mobileMenuControls = document.querySelector( '.mobile-menu-control-wrapper' ),
|
||||
body = document.body,
|
||||
htmlEl = document.documentElement;
|
||||
|
||||
var enableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'tabindex', '0' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'button' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-expanded', 'false' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var disableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'tabindex' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'presentation' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-expanded' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-label' );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var setDropdownArrowAttributes = function( arrow ) {
|
||||
if ( 'false' === arrow.getAttribute( 'aria-expanded' ) || ! arrow.getAttribute( 'aria-expanded' ) ) {
|
||||
arrow.setAttribute( 'aria-expanded', 'true' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.closeSubMenuLabel );
|
||||
} else {
|
||||
arrow.setAttribute( 'aria-expanded', 'false' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Start mobile menu toggle.
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleNav = function( e, _this ) {
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
var parentContainer = '';
|
||||
|
||||
if ( _this.getAttribute( 'data-nav' ) ) {
|
||||
parentContainer = document.getElementById( _this.getAttribute( 'data-nav' ) );
|
||||
} else {
|
||||
parentContainer = document.getElementById( _this.closest( 'nav' ).getAttribute( 'id' ) );
|
||||
}
|
||||
|
||||
if ( ! parentContainer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var isExternalToggle = false;
|
||||
|
||||
if ( _this.closest( '.mobile-menu-control-wrapper' ) ) {
|
||||
isExternalToggle = true;
|
||||
}
|
||||
|
||||
var nav = parentContainer.getElementsByTagName( 'ul' )[0];
|
||||
|
||||
if ( parentContainer.classList.contains( 'toggled' ) ) {
|
||||
parentContainer.classList.remove( 'toggled' );
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'true' );
|
||||
_this.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
}
|
||||
|
||||
disableDropdownArrows( nav );
|
||||
} else {
|
||||
parentContainer.classList.add( 'toggled' );
|
||||
htmlEl.classList.add( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'false' );
|
||||
_this.setAttribute( 'aria-expanded', 'true' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
}
|
||||
|
||||
enableDropdownArrows( nav );
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < allNavToggles.length; i++ ) {
|
||||
allNavToggles[i].addEventListener( 'click', toggleNav, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Open sub-menus
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleSubNav = function( e, _this ) {
|
||||
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
if ( ( _this.closest( 'nav' ).classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) && ! body.classList.contains( 'dropdown-click' ) ) {
|
||||
e.preventDefault();
|
||||
var closestLi = _this.closest( 'li' );
|
||||
|
||||
setDropdownArrowAttributes( closestLi.querySelector( '.dropdown-menu-toggle' ) );
|
||||
|
||||
if ( closestLi.querySelector( '.sub-menu' ) ) {
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
} else {
|
||||
var subMenu = closestLi.querySelector( '.children' );
|
||||
}
|
||||
|
||||
if ( generatepressMenu.toggleOpenedSubMenus ) {
|
||||
var siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
siblings[i].querySelector( '.toggled-on' ).classList.remove( 'toggled-on' );
|
||||
setDropdownArrowAttributes( siblings[i].querySelector( '.dropdown-menu-toggle' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
for ( var i = 0; i < dropdownToggle.length; i++ ) {
|
||||
dropdownToggle[i].addEventListener( 'click', toggleSubNav, false );
|
||||
dropdownToggle[i].addEventListener( 'keypress', function( e ) {
|
||||
var key = e.which || e.keyCode;
|
||||
if (key === 13) { // 13 is enter
|
||||
toggleSubNav( e, this );
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the mobile menu if our toggle isn't visible.
|
||||
* Makes it possible to style mobile item with .toggled class.
|
||||
*/
|
||||
var checkMobile = function() {
|
||||
var openedMobileMenus = document.querySelectorAll( '.toggled, .has-active-search' );
|
||||
|
||||
for ( var i = 0; i < openedMobileMenus.length; i++ ) {
|
||||
var menuToggle = openedMobileMenus[i].querySelector( '.menu-toggle' );
|
||||
|
||||
if ( mobileMenuControls && ! menuToggle.closest( 'nav' ).classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
menuToggle = mobileMenuControls.querySelector( '.menu-toggle' );
|
||||
}
|
||||
|
||||
if ( menuToggle && menuToggle.offsetParent === null ) {
|
||||
if ( openedMobileMenus[i].classList.contains( 'toggled' ) ) {
|
||||
var remoteNav = false;
|
||||
|
||||
if ( openedMobileMenus[i].classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
remoteNav = true;
|
||||
}
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
// Navigation is toggled, but .menu-toggle isn't visible on the page (display: none).
|
||||
var closestNav = openedMobileMenus[i].getElementsByTagName( 'ul' )[ 0 ],
|
||||
closestNavItems = closestNav.getElementsByTagName( 'li' ),
|
||||
closestSubMenus = closestNav.getElementsByTagName( 'ul' );
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
openedMobileMenus[i].classList.remove( 'toggled' );
|
||||
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
menuToggle.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
for ( var li = 0; li < closestNavItems.length; li++ ) {
|
||||
closestNavItems[li].classList.remove( 'sfHover' );
|
||||
}
|
||||
|
||||
for ( var sm = 0; sm < closestSubMenus.length; sm++ ) {
|
||||
closestSubMenus[sm].classList.remove( 'toggled-on' );
|
||||
}
|
||||
|
||||
if ( closestNav ) {
|
||||
closestNav.removeAttribute( 'aria-hidden' );
|
||||
}
|
||||
}
|
||||
|
||||
disableDropdownArrows( openedMobileMenus[i] );
|
||||
}
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener( 'resize', checkMobile, false );
|
||||
window.addEventListener( 'orientationchange', checkMobile, false );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
/**
|
||||
* Do some essential things when menu items are clicked.
|
||||
*/
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'click', function( e ) {
|
||||
// Remove sfHover class if we're going to another site.
|
||||
if ( this.hostname !== window.location.hostname ) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
var closest_nav = this.closest( 'nav' );
|
||||
if ( closest_nav.classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) {
|
||||
var url = this.getAttribute( 'href' );
|
||||
|
||||
// Open the sub-menu if the link has no destination
|
||||
if ( '#' == url || '' == url ) {
|
||||
e.preventDefault();
|
||||
var closestLi = this.closest( 'li' );
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
|
||||
if ( subMenu ) {
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
var body = document.body;
|
||||
|
||||
body.addEventListener( 'mousedown', function() {
|
||||
body.classList.add( 'using-mouse' );
|
||||
} );
|
||||
|
||||
body.addEventListener( 'keydown', function() {
|
||||
body.classList.remove( 'using-mouse' );
|
||||
} );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var navLinks = document.querySelectorAll( 'nav .main-nav ul a' ),
|
||||
menuBarItems = document.querySelectorAll( '.menu-bar-items .menu-bar-item > a' );
|
||||
|
||||
/**
|
||||
* Make menu items tab accessible when using the hover dropdown type
|
||||
*/
|
||||
var toggleFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'main-nav' ) ) {
|
||||
if ( 'li' === self.tagName.toLowerCase() ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make our menu bar items tab accessible.
|
||||
*/
|
||||
var toggleMenuBarItemFocus = function() {
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) || this.closest( 'nav' ).classList.contains( 'slideout-navigation' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var self = this;
|
||||
|
||||
while ( -1 === self.className.indexOf( 'menu-bar-items' ) ) {
|
||||
if ( self.classList.contains( 'menu-bar-item' ) ) {
|
||||
self.classList.toggle( 'sfHover' );
|
||||
}
|
||||
|
||||
self = self.parentElement;
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'focus', toggleFocus );
|
||||
navLinks[i].addEventListener( 'blur', toggleFocus );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < menuBarItems.length; i++ ) {
|
||||
menuBarItems[i].addEventListener( 'focus', toggleMenuBarItemFocus );
|
||||
menuBarItems[i].addEventListener( 'blur', toggleMenuBarItemFocus );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make hover dropdown touch-friendly.
|
||||
*/
|
||||
if ( 'ontouchend' in document.documentElement && document.body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var parentElements = document.querySelectorAll( '.sf-menu .menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < parentElements.length; i++ ) {
|
||||
parentElements[i].addEventListener( 'touchend', function( e ) {
|
||||
|
||||
// Bail on mobile
|
||||
if ( this.closest( 'nav' ).classList.contains( 'toggled' ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( e.touches.length === 1 || e.touches.length === 0 ) {
|
||||
// Prevent touch events within dropdown bubbling down to document
|
||||
e.stopPropagation();
|
||||
|
||||
// Toggle hover
|
||||
if ( ! this.classList.contains( 'sfHover' ) ) {
|
||||
// Prevent link on first touch
|
||||
if ( e.target === this || e.target.parentNode === this || e.target.parentNode.parentNode ) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
// Close other sub-menus.
|
||||
var closestLi = this.closest( 'li' ),
|
||||
siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
}
|
||||
}
|
||||
|
||||
this.classList.add( 'sfHover' );
|
||||
|
||||
// Hide dropdown on touch outside
|
||||
var closeDropdown,
|
||||
thisItem = this;
|
||||
|
||||
document.addEventListener( 'touchend', closeDropdown = function(e) {
|
||||
e.stopPropagation();
|
||||
|
||||
thisItem.classList.remove( 'sfHover' );
|
||||
document.removeEventListener( 'touchend', closeDropdown );
|
||||
} );
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
}
|
||||
} )();
|
||||
|
@ -1,302 +1,302 @@
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
/**
|
||||
* matches() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.matches ) {
|
||||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* closest() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.closest ) {
|
||||
Element.prototype.closest = function( s ) {
|
||||
var el = this;
|
||||
var ancestor = this;
|
||||
if ( ! document.documentElement.contains( el ) ) {
|
||||
return null;
|
||||
}
|
||||
do {
|
||||
if ( ancestor.matches( s ) ) {
|
||||
return ancestor;
|
||||
}
|
||||
ancestor = ancestor.parentElement;
|
||||
} while ( ancestor !== null );
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
var allNavToggles = document.querySelectorAll( '.menu-toggle' ),
|
||||
dropdownToggle = document.querySelectorAll( 'nav .dropdown-menu-toggle' ),
|
||||
navLinks = document.querySelectorAll( 'nav ul a' ),
|
||||
mobileMenuControls = document.querySelector( '.mobile-menu-control-wrapper' ),
|
||||
body = document.body,
|
||||
htmlEl = document.documentElement;
|
||||
|
||||
var enableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'tabindex', '0' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'button' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-expanded', 'false' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var disableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'tabindex' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'presentation' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-expanded' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-label' );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var setDropdownArrowAttributes = function( arrow ) {
|
||||
if ( 'false' === arrow.getAttribute( 'aria-expanded' ) || ! arrow.getAttribute( 'aria-expanded' ) ) {
|
||||
arrow.setAttribute( 'aria-expanded', 'true' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.closeSubMenuLabel );
|
||||
} else {
|
||||
arrow.setAttribute( 'aria-expanded', 'false' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Start mobile menu toggle.
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleNav = function( e, _this ) {
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
var parentContainer = '';
|
||||
|
||||
if ( _this.getAttribute( 'data-nav' ) ) {
|
||||
parentContainer = document.getElementById( _this.getAttribute( 'data-nav' ) );
|
||||
} else {
|
||||
parentContainer = document.getElementById( _this.closest( 'nav' ).getAttribute( 'id' ) );
|
||||
}
|
||||
|
||||
if ( ! parentContainer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var isExternalToggle = false;
|
||||
|
||||
if ( _this.closest( '.mobile-menu-control-wrapper' ) ) {
|
||||
isExternalToggle = true;
|
||||
}
|
||||
|
||||
var nav = parentContainer.getElementsByTagName( 'ul' )[0];
|
||||
|
||||
if ( parentContainer.classList.contains( 'toggled' ) ) {
|
||||
parentContainer.classList.remove( 'toggled' );
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'true' );
|
||||
_this.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
}
|
||||
|
||||
disableDropdownArrows( nav );
|
||||
} else {
|
||||
parentContainer.classList.add( 'toggled' );
|
||||
htmlEl.classList.add( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'false' );
|
||||
_this.setAttribute( 'aria-expanded', 'true' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
}
|
||||
|
||||
enableDropdownArrows( nav );
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < allNavToggles.length; i++ ) {
|
||||
allNavToggles[i].addEventListener( 'click', toggleNav, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Open sub-menus
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleSubNav = function( e, _this ) {
|
||||
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
if ( ( _this.closest( 'nav' ).classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) && ! body.classList.contains( 'dropdown-click' ) ) {
|
||||
e.preventDefault();
|
||||
var closestLi = _this.closest( 'li' );
|
||||
|
||||
setDropdownArrowAttributes( closestLi.querySelector( '.dropdown-menu-toggle' ) );
|
||||
|
||||
if ( closestLi.querySelector( '.sub-menu' ) ) {
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
} else {
|
||||
var subMenu = closestLi.querySelector( '.children' );
|
||||
}
|
||||
|
||||
if ( generatepressMenu.toggleOpenedSubMenus ) {
|
||||
var siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
siblings[i].querySelector( '.toggled-on' ).classList.remove( 'toggled-on' );
|
||||
setDropdownArrowAttributes( siblings[i].querySelector( '.dropdown-menu-toggle' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
for ( var i = 0; i < dropdownToggle.length; i++ ) {
|
||||
dropdownToggle[i].addEventListener( 'click', toggleSubNav, false );
|
||||
dropdownToggle[i].addEventListener( 'keypress', function( e ) {
|
||||
var key = e.which || e.keyCode;
|
||||
if (key === 13) { // 13 is enter
|
||||
toggleSubNav( e, this );
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the mobile menu if our toggle isn't visible.
|
||||
* Makes it possible to style mobile item with .toggled class.
|
||||
*/
|
||||
var checkMobile = function() {
|
||||
var openedMobileMenus = document.querySelectorAll( '.toggled, .has-active-search' );
|
||||
|
||||
for ( var i = 0; i < openedMobileMenus.length; i++ ) {
|
||||
var menuToggle = openedMobileMenus[i].querySelector( '.menu-toggle' );
|
||||
|
||||
if ( mobileMenuControls && ! menuToggle.closest( 'nav' ).classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
menuToggle = mobileMenuControls.querySelector( '.menu-toggle' );
|
||||
}
|
||||
|
||||
if ( menuToggle && menuToggle.offsetParent === null ) {
|
||||
if ( openedMobileMenus[i].classList.contains( 'toggled' ) ) {
|
||||
var remoteNav = false;
|
||||
|
||||
if ( openedMobileMenus[i].classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
remoteNav = true;
|
||||
}
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
// Navigation is toggled, but .menu-toggle isn't visible on the page (display: none).
|
||||
var closestNav = openedMobileMenus[i].getElementsByTagName( 'ul' )[ 0 ],
|
||||
closestNavItems = closestNav.getElementsByTagName( 'li' ),
|
||||
closestSubMenus = closestNav.getElementsByTagName( 'ul' );
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
openedMobileMenus[i].classList.remove( 'toggled' );
|
||||
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
menuToggle.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
for ( var li = 0; li < closestNavItems.length; li++ ) {
|
||||
closestNavItems[li].classList.remove( 'sfHover' );
|
||||
}
|
||||
|
||||
for ( var sm = 0; sm < closestSubMenus.length; sm++ ) {
|
||||
closestSubMenus[sm].classList.remove( 'toggled-on' );
|
||||
}
|
||||
|
||||
if ( closestNav ) {
|
||||
closestNav.removeAttribute( 'aria-hidden' );
|
||||
}
|
||||
}
|
||||
|
||||
disableDropdownArrows( openedMobileMenus[i] );
|
||||
}
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener( 'resize', checkMobile, false );
|
||||
window.addEventListener( 'orientationchange', checkMobile, false );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
/**
|
||||
* Do some essential things when menu items are clicked.
|
||||
*/
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'click', function( e ) {
|
||||
// Remove sfHover class if we're going to another site.
|
||||
if ( this.hostname !== window.location.hostname ) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
var closest_nav = this.closest( 'nav' );
|
||||
if ( closest_nav.classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) {
|
||||
var url = this.getAttribute( 'href' );
|
||||
|
||||
// Open the sub-menu if the link has no destination
|
||||
if ( '#' == url || '' == url ) {
|
||||
e.preventDefault();
|
||||
var closestLi = this.closest( 'li' );
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
|
||||
if ( subMenu ) {
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
/**
|
||||
* matches() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.matches ) {
|
||||
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* closest() pollyfil
|
||||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Browser_compatibility
|
||||
*/
|
||||
if ( ! Element.prototype.closest ) {
|
||||
Element.prototype.closest = function( s ) {
|
||||
var el = this;
|
||||
var ancestor = this;
|
||||
if ( ! document.documentElement.contains( el ) ) {
|
||||
return null;
|
||||
}
|
||||
do {
|
||||
if ( ancestor.matches( s ) ) {
|
||||
return ancestor;
|
||||
}
|
||||
ancestor = ancestor.parentElement;
|
||||
} while ( ancestor !== null );
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
var getSiblings = function( elem ) {
|
||||
return Array.prototype.filter.call( elem.parentNode.children, function( sibling ) {
|
||||
return sibling !== elem;
|
||||
} );
|
||||
};
|
||||
|
||||
var allNavToggles = document.querySelectorAll( '.menu-toggle' ),
|
||||
dropdownToggle = document.querySelectorAll( 'nav .dropdown-menu-toggle' ),
|
||||
navLinks = document.querySelectorAll( 'nav ul a' ),
|
||||
mobileMenuControls = document.querySelector( '.mobile-menu-control-wrapper' ),
|
||||
body = document.body,
|
||||
htmlEl = document.documentElement;
|
||||
|
||||
var enableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'tabindex', '0' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'button' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-expanded', 'false' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var disableDropdownArrows = function( nav ) {
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
var dropdownItems = nav.querySelectorAll( 'li.menu-item-has-children' );
|
||||
|
||||
for ( var i = 0; i < dropdownItems.length; i++ ) {
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'tabindex' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).setAttribute( 'role', 'presentation' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-expanded' );
|
||||
dropdownItems[i].querySelector( '.dropdown-menu-toggle' ).removeAttribute( 'aria-label' );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var setDropdownArrowAttributes = function( arrow ) {
|
||||
if ( 'false' === arrow.getAttribute( 'aria-expanded' ) || ! arrow.getAttribute( 'aria-expanded' ) ) {
|
||||
arrow.setAttribute( 'aria-expanded', 'true' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.closeSubMenuLabel );
|
||||
} else {
|
||||
arrow.setAttribute( 'aria-expanded', 'false' );
|
||||
arrow.setAttribute( 'aria-label', generatepressMenu.openSubMenuLabel );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Start mobile menu toggle.
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleNav = function( e, _this ) {
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
var parentContainer = '';
|
||||
|
||||
if ( _this.getAttribute( 'data-nav' ) ) {
|
||||
parentContainer = document.getElementById( _this.getAttribute( 'data-nav' ) );
|
||||
} else {
|
||||
parentContainer = document.getElementById( _this.closest( 'nav' ).getAttribute( 'id' ) );
|
||||
}
|
||||
|
||||
if ( ! parentContainer ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var isExternalToggle = false;
|
||||
|
||||
if ( _this.closest( '.mobile-menu-control-wrapper' ) ) {
|
||||
isExternalToggle = true;
|
||||
}
|
||||
|
||||
var nav = parentContainer.getElementsByTagName( 'ul' )[0];
|
||||
|
||||
if ( parentContainer.classList.contains( 'toggled' ) ) {
|
||||
parentContainer.classList.remove( 'toggled' );
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'true' );
|
||||
_this.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.remove( 'toggled' );
|
||||
}
|
||||
|
||||
disableDropdownArrows( nav );
|
||||
} else {
|
||||
parentContainer.classList.add( 'toggled' );
|
||||
htmlEl.classList.add( 'mobile-menu-open' );
|
||||
nav.setAttribute( 'aria-hidden', 'false' );
|
||||
_this.setAttribute( 'aria-expanded', 'true' );
|
||||
|
||||
if ( isExternalToggle ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
} else if ( mobileMenuControls && parentContainer.classList.contains( 'main-navigation' ) ) {
|
||||
mobileMenuControls.classList.add( 'toggled' );
|
||||
}
|
||||
|
||||
enableDropdownArrows( nav );
|
||||
}
|
||||
}
|
||||
|
||||
for ( var i = 0; i < allNavToggles.length; i++ ) {
|
||||
allNavToggles[i].addEventListener( 'click', toggleNav, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Open sub-menus
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleSubNav = function( e, _this ) {
|
||||
|
||||
if ( ! _this ) {
|
||||
var _this = this;
|
||||
}
|
||||
|
||||
if ( ( _this.closest( 'nav' ).classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) && ! body.classList.contains( 'dropdown-click' ) ) {
|
||||
e.preventDefault();
|
||||
var closestLi = _this.closest( 'li' );
|
||||
|
||||
setDropdownArrowAttributes( closestLi.querySelector( '.dropdown-menu-toggle' ) );
|
||||
|
||||
if ( closestLi.querySelector( '.sub-menu' ) ) {
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
} else {
|
||||
var subMenu = closestLi.querySelector( '.children' );
|
||||
}
|
||||
|
||||
if ( generatepressMenu.toggleOpenedSubMenus ) {
|
||||
var siblings = getSiblings( closestLi );
|
||||
|
||||
for ( var i = 0; i < siblings.length; i++ ) {
|
||||
if ( siblings[i].classList.contains( 'sfHover' ) ) {
|
||||
siblings[i].classList.remove( 'sfHover' );
|
||||
siblings[i].querySelector( '.toggled-on' ).classList.remove( 'toggled-on' );
|
||||
setDropdownArrowAttributes( siblings[i].querySelector( '.dropdown-menu-toggle' ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
|
||||
e.stopPropagation();
|
||||
}
|
||||
|
||||
for ( var i = 0; i < dropdownToggle.length; i++ ) {
|
||||
dropdownToggle[i].addEventListener( 'click', toggleSubNav, false );
|
||||
dropdownToggle[i].addEventListener( 'keypress', function( e ) {
|
||||
var key = e.which || e.keyCode;
|
||||
if (key === 13) { // 13 is enter
|
||||
toggleSubNav( e, this );
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable the mobile menu if our toggle isn't visible.
|
||||
* Makes it possible to style mobile item with .toggled class.
|
||||
*/
|
||||
var checkMobile = function() {
|
||||
var openedMobileMenus = document.querySelectorAll( '.toggled, .has-active-search' );
|
||||
|
||||
for ( var i = 0; i < openedMobileMenus.length; i++ ) {
|
||||
var menuToggle = openedMobileMenus[i].querySelector( '.menu-toggle' );
|
||||
|
||||
if ( mobileMenuControls && ! menuToggle.closest( 'nav' ).classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
menuToggle = mobileMenuControls.querySelector( '.menu-toggle' );
|
||||
}
|
||||
|
||||
if ( menuToggle && menuToggle.offsetParent === null ) {
|
||||
if ( openedMobileMenus[i].classList.contains( 'toggled' ) ) {
|
||||
var remoteNav = false;
|
||||
|
||||
if ( openedMobileMenus[i].classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
remoteNav = true;
|
||||
}
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
// Navigation is toggled, but .menu-toggle isn't visible on the page (display: none).
|
||||
var closestNav = openedMobileMenus[i].getElementsByTagName( 'ul' )[ 0 ],
|
||||
closestNavItems = closestNav.getElementsByTagName( 'li' ),
|
||||
closestSubMenus = closestNav.getElementsByTagName( 'ul' );
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
openedMobileMenus[i].classList.remove( 'toggled' );
|
||||
|
||||
htmlEl.classList.remove( 'mobile-menu-open' );
|
||||
menuToggle.setAttribute( 'aria-expanded', 'false' );
|
||||
|
||||
if ( ! remoteNav ) {
|
||||
for ( var li = 0; li < closestNavItems.length; li++ ) {
|
||||
closestNavItems[li].classList.remove( 'sfHover' );
|
||||
}
|
||||
|
||||
for ( var sm = 0; sm < closestSubMenus.length; sm++ ) {
|
||||
closestSubMenus[sm].classList.remove( 'toggled-on' );
|
||||
}
|
||||
|
||||
if ( closestNav ) {
|
||||
closestNav.removeAttribute( 'aria-hidden' );
|
||||
}
|
||||
}
|
||||
|
||||
disableDropdownArrows( openedMobileMenus[i] );
|
||||
}
|
||||
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ) ) {
|
||||
if ( mobileMenuControls.querySelector( '.search-item' ).classList.contains( 'active' ) ) {
|
||||
mobileMenuControls.querySelector( '.search-item' ).click();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener( 'resize', checkMobile, false );
|
||||
window.addEventListener( 'orientationchange', checkMobile, false );
|
||||
|
||||
if ( body.classList.contains( 'dropdown-hover' ) ) {
|
||||
/**
|
||||
* Do some essential things when menu items are clicked.
|
||||
*/
|
||||
for ( var i = 0; i < navLinks.length; i++ ) {
|
||||
navLinks[i].addEventListener( 'click', function( e ) {
|
||||
// Remove sfHover class if we're going to another site.
|
||||
if ( this.hostname !== window.location.hostname ) {
|
||||
document.activeElement.blur();
|
||||
}
|
||||
|
||||
var closest_nav = this.closest( 'nav' );
|
||||
if ( closest_nav.classList.contains( 'toggled' ) || htmlEl.classList.contains( 'slide-opened' ) ) {
|
||||
var url = this.getAttribute( 'href' );
|
||||
|
||||
// Open the sub-menu if the link has no destination
|
||||
if ( '#' == url || '' == url ) {
|
||||
e.preventDefault();
|
||||
var closestLi = this.closest( 'li' );
|
||||
closestLi.classList.toggle( 'sfHover' );
|
||||
var subMenu = closestLi.querySelector( '.sub-menu' );
|
||||
|
||||
if ( subMenu ) {
|
||||
subMenu.classList.toggle( 'toggled-on' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})();
|
||||
|
@ -1,128 +1,128 @@
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
/**
|
||||
* Navigation search.
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleSearch = function( e, item ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( ! item ) {
|
||||
var item = this;
|
||||
}
|
||||
|
||||
var forms = document.querySelectorAll( '.navigation-search' ),
|
||||
toggles = document.querySelectorAll( '.search-item' ),
|
||||
focusableEls = document.querySelectorAll('a[href], area[href], input:not([disabled]):not(.navigation-search), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'),
|
||||
nav = '';
|
||||
|
||||
if ( item.closest( '.mobile-menu-control-wrapper' ) ) {
|
||||
nav = document.getElementById( 'site-navigation' );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < forms.length; i++ ) {
|
||||
if ( forms[i].classList.contains( 'nav-search-active' ) ) {
|
||||
if ( forms[i].closest( '#sticky-placeholder' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
forms[i].classList.remove( 'nav-search-active' );
|
||||
|
||||
var activeSearch = document.querySelector( '.has-active-search' );;
|
||||
|
||||
if ( activeSearch ) {
|
||||
activeSearch.classList.remove( 'has-active-search' );
|
||||
}
|
||||
|
||||
for ( var t = 0; t < toggles.length; t++ ) {
|
||||
toggles[t].classList.remove( 'close-search' );
|
||||
toggles[t].classList.remove( 'active' );
|
||||
toggles[t].querySelector( 'a' ).setAttribute( 'aria-label', generatepressNavSearch.open );
|
||||
|
||||
// Allow tabindex on items again.
|
||||
for ( var f = 0; f < focusableEls.length; f++ ) {
|
||||
if ( ! focusableEls[f].closest( '.navigation-search' ) && ! focusableEls[f].closest( '.search-item' ) ) {
|
||||
focusableEls[f].removeAttribute( 'tabindex' );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
} else {
|
||||
if ( forms[i].closest( '#sticky-placeholder' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var openedMobileMenu = forms[i].closest( '.toggled' );
|
||||
|
||||
if ( openedMobileMenu ) {
|
||||
// Close the mobile menu.
|
||||
openedMobileMenu.querySelector( 'button.menu-toggle' ).click();
|
||||
}
|
||||
|
||||
if ( nav ) {
|
||||
nav.classList.add( 'has-active-search' );
|
||||
}
|
||||
|
||||
forms[i].classList.add( 'nav-search-active' );
|
||||
|
||||
var container = this.closest( 'nav' );
|
||||
|
||||
if ( container ) {
|
||||
if ( container.classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
container = nav;
|
||||
}
|
||||
|
||||
var searchField = container.querySelector( '.search-field' );
|
||||
|
||||
if ( searchField ) {
|
||||
searchField.focus();
|
||||
}
|
||||
}
|
||||
|
||||
for ( var t = 0; t < toggles.length; t++ ) {
|
||||
toggles[t].classList.add( 'active' );
|
||||
toggles[t].querySelector( 'a' ).setAttribute( 'aria-label', generatepressNavSearch.close );
|
||||
|
||||
// Trap tabindex within the search element
|
||||
for ( var f = 0; f < focusableEls.length; f++ ) {
|
||||
if ( ! focusableEls[f].closest( '.navigation-search' ) && ! focusableEls[f].closest( '.search-item' ) ) {
|
||||
focusableEls[f].setAttribute( 'tabindex', '-1' );
|
||||
}
|
||||
};
|
||||
|
||||
toggles[t].classList.add( 'close-search' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( document.body.classList.contains( 'nav-search-enabled' ) ) {
|
||||
var searchItems = document.querySelectorAll( '.search-item' );
|
||||
|
||||
for ( var i = 0; i < searchItems.length; i++ ) {
|
||||
searchItems[i].addEventListener( 'click', toggleSearch, false );
|
||||
}
|
||||
|
||||
// Close navigation search on escape key
|
||||
document.addEventListener( 'keydown', function( e ) {
|
||||
if ( document.querySelector( '.navigation-search.nav-search-active' ) ) {
|
||||
var key = e.which || e.keyCode;
|
||||
|
||||
if ( key === 27 ) { // 27 is esc
|
||||
var activeSearchItems = document.querySelectorAll( '.search-item.active' );
|
||||
|
||||
for ( var i = 0; i < activeSearchItems.length; i++ ) {
|
||||
toggleSearch( e, activeSearchItems[i] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
}
|
||||
})();
|
||||
( function() {
|
||||
'use strict';
|
||||
|
||||
if ( 'querySelector' in document && 'addEventListener' in window ) {
|
||||
/**
|
||||
* Navigation search.
|
||||
*
|
||||
* @param e The event.
|
||||
* @param _this The clicked item.
|
||||
*/
|
||||
var toggleSearch = function( e, item ) {
|
||||
e.preventDefault();
|
||||
|
||||
if ( ! item ) {
|
||||
var item = this;
|
||||
}
|
||||
|
||||
var forms = document.querySelectorAll( '.navigation-search' ),
|
||||
toggles = document.querySelectorAll( '.search-item' ),
|
||||
focusableEls = document.querySelectorAll('a[href], area[href], input:not([disabled]):not(.navigation-search), select:not([disabled]), textarea:not([disabled]), button:not([disabled]), [tabindex="0"]'),
|
||||
nav = '';
|
||||
|
||||
if ( item.closest( '.mobile-menu-control-wrapper' ) ) {
|
||||
nav = document.getElementById( 'site-navigation' );
|
||||
}
|
||||
|
||||
for ( var i = 0; i < forms.length; i++ ) {
|
||||
if ( forms[i].classList.contains( 'nav-search-active' ) ) {
|
||||
if ( forms[i].closest( '#sticky-placeholder' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
forms[i].classList.remove( 'nav-search-active' );
|
||||
|
||||
var activeSearch = document.querySelector( '.has-active-search' );;
|
||||
|
||||
if ( activeSearch ) {
|
||||
activeSearch.classList.remove( 'has-active-search' );
|
||||
}
|
||||
|
||||
for ( var t = 0; t < toggles.length; t++ ) {
|
||||
toggles[t].classList.remove( 'close-search' );
|
||||
toggles[t].classList.remove( 'active' );
|
||||
toggles[t].querySelector( 'a' ).setAttribute( 'aria-label', generatepressNavSearch.open );
|
||||
|
||||
// Allow tabindex on items again.
|
||||
for ( var f = 0; f < focusableEls.length; f++ ) {
|
||||
if ( ! focusableEls[f].closest( '.navigation-search' ) && ! focusableEls[f].closest( '.search-item' ) ) {
|
||||
focusableEls[f].removeAttribute( 'tabindex' );
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
document.activeElement.blur();
|
||||
} else {
|
||||
if ( forms[i].closest( '#sticky-placeholder' ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var openedMobileMenu = forms[i].closest( '.toggled' );
|
||||
|
||||
if ( openedMobileMenu ) {
|
||||
// Close the mobile menu.
|
||||
openedMobileMenu.querySelector( 'button.menu-toggle' ).click();
|
||||
}
|
||||
|
||||
if ( nav ) {
|
||||
nav.classList.add( 'has-active-search' );
|
||||
}
|
||||
|
||||
forms[i].classList.add( 'nav-search-active' );
|
||||
|
||||
var container = this.closest( 'nav' );
|
||||
|
||||
if ( container ) {
|
||||
if ( container.classList.contains( 'mobile-menu-control-wrapper' ) ) {
|
||||
container = nav;
|
||||
}
|
||||
|
||||
var searchField = container.querySelector( '.search-field' );
|
||||
|
||||
if ( searchField ) {
|
||||
searchField.focus();
|
||||
}
|
||||
}
|
||||
|
||||
for ( var t = 0; t < toggles.length; t++ ) {
|
||||
toggles[t].classList.add( 'active' );
|
||||
toggles[t].querySelector( 'a' ).setAttribute( 'aria-label', generatepressNavSearch.close );
|
||||
|
||||
// Trap tabindex within the search element
|
||||
for ( var f = 0; f < focusableEls.length; f++ ) {
|
||||
if ( ! focusableEls[f].closest( '.navigation-search' ) && ! focusableEls[f].closest( '.search-item' ) ) {
|
||||
focusableEls[f].setAttribute( 'tabindex', '-1' );
|
||||
}
|
||||
};
|
||||
|
||||
toggles[t].classList.add( 'close-search' );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( document.body.classList.contains( 'nav-search-enabled' ) ) {
|
||||
var searchItems = document.querySelectorAll( '.search-item' );
|
||||
|
||||
for ( var i = 0; i < searchItems.length; i++ ) {
|
||||
searchItems[i].addEventListener( 'click', toggleSearch, false );
|
||||
}
|
||||
|
||||
// Close navigation search on escape key
|
||||
document.addEventListener( 'keydown', function( e ) {
|
||||
if ( document.querySelector( '.navigation-search.nav-search-active' ) ) {
|
||||
var key = e.which || e.keyCode;
|
||||
|
||||
if ( key === 27 ) { // 27 is esc
|
||||
var activeSearchItems = document.querySelectorAll( '.search-item.active' );
|
||||
|
||||
for ( var i = 0; i < activeSearchItems.length; i++ ) {
|
||||
toggleSearch( e, activeSearchItems[i] );
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, false );
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
Reference in New Issue
Block a user