Fixes in admin-bar.js
:
- Silence errors when a node doesn't exist similarly to jQuery. - Add "feature testing" and fallbacks for old browsers as this may run on the front-end. - Improve inline docs. Props dinhtungdu, azaozz. Fixes #47069. git-svn-id: https://develop.svn.wordpress.org/trunk@46883 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
b73180da85
commit
c85e33c28f
@ -4,45 +4,54 @@
|
|||||||
/**
|
/**
|
||||||
* Admin bar with Vanilla JS, no external dependencies.
|
* Admin bar with Vanilla JS, no external dependencies.
|
||||||
*
|
*
|
||||||
|
* @since 5.3.1
|
||||||
|
*
|
||||||
* @param {Object} document The document object.
|
* @param {Object} document The document object.
|
||||||
* @param {Object} window The window object.
|
* @param {Object} window The window object.
|
||||||
* @param {Object} navigator The navigator object.
|
* @param {Object} navigator The navigator object.
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
/* global hoverintent */
|
|
||||||
( function( document, window, navigator ) {
|
( function( document, window, navigator ) {
|
||||||
document.addEventListener( 'DOMContentLoaded', function() {
|
document.addEventListener( 'DOMContentLoaded', function() {
|
||||||
var adminBar = document.getElementById( 'wpadminbar' ),
|
var adminBar = document.getElementById( 'wpadminbar' ),
|
||||||
topMenuItems = adminBar.querySelectorAll( 'li.menupop' ),
|
topMenuItems,
|
||||||
allMenuItems = adminBar.querySelectorAll( '.ab-item' ),
|
allMenuItems,
|
||||||
adminBarLogout = document.getElementById( 'wp-admin-bar-logout' ),
|
adminBarLogout,
|
||||||
adminBarSearchForm = document.getElementById( 'adminbarsearch' ),
|
adminBarSearchForm,
|
||||||
shortlink = document.getElementById( 'wp-admin-bar-get-shortlink' ),
|
shortlink,
|
||||||
skipLink = adminBar.querySelector( '.screen-reader-shortcut' ),
|
skipLink,
|
||||||
mobileEvent = /Mobile\/.+Safari/.test( navigator.userAgent ) ? 'touchstart' : 'click',
|
mobileEvent,
|
||||||
|
fontFaceRegex,
|
||||||
adminBarSearchInput,
|
adminBarSearchInput,
|
||||||
i;
|
i;
|
||||||
|
|
||||||
/**
|
if ( ! adminBar || ! ( 'querySelectorAll' in adminBar ) ) {
|
||||||
* Remove nojs class after the DOM is loaded.
|
return;
|
||||||
*/
|
}
|
||||||
adminBar.classList.remove( 'nojs' );
|
|
||||||
|
topMenuItems = adminBar.querySelectorAll( 'li.menupop' );
|
||||||
|
allMenuItems = adminBar.querySelectorAll( '.ab-item' );
|
||||||
|
adminBarLogout = document.getElementById( 'wp-admin-bar-logout' );
|
||||||
|
adminBarSearchForm = document.getElementById( 'adminbarsearch' );
|
||||||
|
shortlink = document.getElementById( 'wp-admin-bar-get-shortlink' );
|
||||||
|
skipLink = adminBar.querySelector( '.screen-reader-shortcut' );
|
||||||
|
mobileEvent = /Mobile\/.+Safari/.test( navigator.userAgent ) ? 'touchstart' : 'click';
|
||||||
|
fontFaceRegex = /Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/;
|
||||||
|
|
||||||
|
// Remove nojs class after the DOM is loaded.
|
||||||
|
removeClass( adminBar, 'nojs' );
|
||||||
|
|
||||||
if ( 'ontouchstart' in window ) {
|
if ( 'ontouchstart' in window ) {
|
||||||
/**
|
// Remove hover class when the user touches outside the menu items.
|
||||||
* Remove hover class when the user touches outside the menu items.
|
|
||||||
*/
|
|
||||||
document.body.addEventListener( mobileEvent, function( e ) {
|
document.body.addEventListener( mobileEvent, function( e ) {
|
||||||
if ( ! getClosest( e.target, 'li.menupop' ) ) {
|
if ( ! getClosest( e.target, 'li.menupop' ) ) {
|
||||||
removeAllHoverClass( topMenuItems );
|
removeAllHoverClass( topMenuItems );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
/**
|
// Add listener for menu items to toggle hover class by touches.
|
||||||
* Add listener for menu items to toggle hover class by touches.
|
// Remove the callback later for better performance.
|
||||||
* Remove the callback later for better performance.
|
|
||||||
*/
|
|
||||||
adminBar.addEventListener( 'touchstart', function bindMobileEvents() {
|
adminBar.addEventListener( 'touchstart', function bindMobileEvents() {
|
||||||
for ( var i = 0; i < topMenuItems.length; i++ ) {
|
for ( var i = 0; i < topMenuItems.length; i++ ) {
|
||||||
topMenuItems[i].addEventListener( 'click', mobileHover.bind( null, topMenuItems ) );
|
topMenuItems[i].addEventListener( 'click', mobileHover.bind( null, topMenuItems ) );
|
||||||
@ -52,32 +61,24 @@
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Scroll page to top when clicking on the admin bar.
|
||||||
* Scroll page to top when clicking on the admin bar.
|
|
||||||
*/
|
|
||||||
adminBar.addEventListener( 'click', scrollToTop );
|
adminBar.addEventListener( 'click', scrollToTop );
|
||||||
|
|
||||||
for ( i = 0; i < topMenuItems.length; i++ ) {
|
for ( i = 0; i < topMenuItems.length; i++ ) {
|
||||||
/**
|
// Adds or removes the hover class based on the hover intent.
|
||||||
* Adds or removes the hover class based on the hover intent.
|
window.hoverintent(
|
||||||
*/
|
|
||||||
hoverintent(
|
|
||||||
topMenuItems[i],
|
topMenuItems[i],
|
||||||
addHoverClass.bind( null, topMenuItems[i] ),
|
addClass.bind( null, topMenuItems[i], 'hover' ),
|
||||||
removeHoverClass.bind( null, topMenuItems[i] )
|
removeClass.bind( null, topMenuItems[i], 'hover' )
|
||||||
).options( {
|
).options( {
|
||||||
timeout: 180
|
timeout: 180
|
||||||
} );
|
} );
|
||||||
|
|
||||||
/**
|
// Toggle hover class if the enter key is pressed.
|
||||||
* Toggle hover class if the enter key is pressed.
|
|
||||||
*/
|
|
||||||
topMenuItems[i].addEventListener( 'keydown', toggleHoverIfEnter );
|
topMenuItems[i].addEventListener( 'keydown', toggleHoverIfEnter );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Remove hover class if the escape key is pressed.
|
||||||
* Remove hover class if the escape key is pressed.
|
|
||||||
*/
|
|
||||||
for ( i = 0; i < allMenuItems.length; i++ ) {
|
for ( i = 0; i < allMenuItems.length; i++ ) {
|
||||||
allMenuItems[i].addEventListener( 'keydown', removeHoverIfEscape );
|
allMenuItems[i].addEventListener( 'keydown', removeHoverIfEscape );
|
||||||
}
|
}
|
||||||
@ -85,131 +86,128 @@
|
|||||||
if ( adminBarSearchForm ) {
|
if ( adminBarSearchForm ) {
|
||||||
adminBarSearchInput = document.getElementById( 'adminbar-search' );
|
adminBarSearchInput = document.getElementById( 'adminbar-search' );
|
||||||
|
|
||||||
/**
|
// Adds the adminbar-focused class on focus.
|
||||||
* Adds the adminbar-focused class on focus.
|
|
||||||
*/
|
|
||||||
adminBarSearchInput.addEventListener( 'focus', function() {
|
adminBarSearchInput.addEventListener( 'focus', function() {
|
||||||
adminBarSearchForm.classList.add( 'adminbar-focused' );
|
addClass( adminBarSearchForm, 'adminbar-focused' );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
/**
|
// Removes the adminbar-focused class on blur.
|
||||||
* Removes the adminbar-focused class on blur.
|
|
||||||
*/
|
|
||||||
adminBarSearchInput.addEventListener( 'blur', function() {
|
adminBarSearchInput.addEventListener( 'blur', function() {
|
||||||
adminBarSearchForm.classList.remove( 'adminbar-focused' );
|
removeClass( adminBarSearchForm, 'adminbar-focused' );
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if ( skipLink ) {
|
||||||
* Focus the target of skip link after pressing Enter.
|
// Focus the target of skip link after pressing Enter.
|
||||||
*/
|
|
||||||
skipLink.addEventListener( 'keydown', focusTargetAfterEnter );
|
skipLink.addEventListener( 'keydown', focusTargetAfterEnter );
|
||||||
|
}
|
||||||
|
|
||||||
if ( shortlink ) {
|
if ( shortlink ) {
|
||||||
shortlink.addEventListener( 'click', clickShortlink );
|
shortlink.addEventListener( 'click', clickShortlink );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Prevents the toolbar from covering up content when a hash is present in the URL.
|
||||||
* Prevents the toolbar from covering up content when a hash is present
|
|
||||||
* in the URL.
|
|
||||||
*/
|
|
||||||
if ( window.location.hash ) {
|
if ( window.location.hash ) {
|
||||||
window.scrollBy( 0, -32 );
|
window.scrollBy( 0, -32 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Add no-font-face class to body if needed.
|
||||||
* Add no-font-face class to body if needed.
|
if (
|
||||||
*/
|
navigator.userAgent &&
|
||||||
if ( navigator.userAgent && document.body.className.indexOf( 'no-font-face' ) === -1 &&
|
fontFaceRegex.test( navigator.userAgent ) &&
|
||||||
/Android (1.0|1.1|1.5|1.6|2.0|2.1)|Nokia|Opera Mini|w(eb)?OSBrowser|webOS|UCWEB|Windows Phone OS 7|XBLWP7|ZuneWP7|MSIE 7/.test( navigator.userAgent ) ) {
|
! hasClass( document.body, 'no-font-face' )
|
||||||
document.body.className += ' no-font-face';
|
) {
|
||||||
|
addClass( document.body, 'no-font-face' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Clear sessionStorage on logging out.
|
||||||
* Clear sessionStorage on logging out.
|
if ( adminBarLogout ) {
|
||||||
*/
|
|
||||||
adminBarLogout.addEventListener( 'click', emptySessionStorage );
|
adminBarLogout.addEventListener( 'click', emptySessionStorage );
|
||||||
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove hover class for top level menu item when escape is pressed.
|
* Remove hover class for top level menu item when escape is pressed.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {Event} e The keydown event.
|
* @param {Event} event The keydown event.
|
||||||
*/
|
*/
|
||||||
function removeHoverIfEscape( e ) {
|
function removeHoverIfEscape( event ) {
|
||||||
var wrapper;
|
var wrapper;
|
||||||
|
|
||||||
if ( e.which != 27 ) {
|
if ( event.which !== 27 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper = getClosest( e.target, '.menupop' );
|
wrapper = getClosest( event.target, '.menupop' );
|
||||||
|
|
||||||
if ( ! wrapper ) {
|
if ( ! wrapper ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper.querySelector( '.menupop > .ab-item' ).focus();
|
wrapper.querySelector( '.menupop > .ab-item' ).focus();
|
||||||
removeHoverClass( wrapper );
|
removeClass( wrapper, 'hover' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle hover class for top level menu item when enter is pressed.
|
* Toggle hover class for top level menu item when enter is pressed.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {Event} e The keydown event.
|
* @param {Event} event The keydown event.
|
||||||
*/
|
*/
|
||||||
function toggleHoverIfEnter( e ) {
|
function toggleHoverIfEnter( event ) {
|
||||||
var wrapper;
|
var wrapper;
|
||||||
|
|
||||||
if ( e.which != 13 ) {
|
if ( event.which !== 13 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !! getClosest( e.target, '.ab-sub-wrapper' ) ) {
|
if ( !! getClosest( event.target, '.ab-sub-wrapper' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
wrapper = getClosest( e.target, '.menupop' );
|
wrapper = getClosest( event.target, '.menupop' );
|
||||||
|
|
||||||
if ( ! wrapper ) {
|
if ( ! wrapper ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
event.preventDefault();
|
||||||
if ( hasHoverClass( wrapper ) ) {
|
|
||||||
removeHoverClass( wrapper );
|
if ( hasClass( wrapper, 'hover' ) ) {
|
||||||
|
removeClass( wrapper, 'hover' );
|
||||||
} else {
|
} else {
|
||||||
addHoverClass( wrapper );
|
addClass( wrapper, 'hover' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Focus the target of skip link after pressing Enter.
|
* Focus the target of skip link after pressing Enter.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {Event} e The keydown event.
|
* @param {Event} event The keydown event.
|
||||||
*/
|
*/
|
||||||
function focusTargetAfterEnter( e ) {
|
function focusTargetAfterEnter( event ) {
|
||||||
var id, userAgent;
|
var id, userAgent;
|
||||||
|
|
||||||
if ( 13 !== e.which ) {
|
if ( event.which !== 13 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
id = e.target.getAttribute( 'href' );
|
id = event.target.getAttribute( 'href' );
|
||||||
userAgent = navigator.userAgent.toLowerCase();
|
userAgent = navigator.userAgent.toLowerCase();
|
||||||
|
|
||||||
if ( userAgent.indexOf( 'applewebkit' ) != -1 && id && id.charAt( 0 ) == '#' ) {
|
if ( userAgent.indexOf( 'applewebkit' ) > -1 && id && id.charAt( 0 ) === '#' ) {
|
||||||
setTimeout( function() {
|
setTimeout( function() {
|
||||||
var target = document.getElementById( id.replace( '#', '' ) );
|
var target = document.getElementById( id.replace( '#', '' ) );
|
||||||
|
|
||||||
|
if ( target ) {
|
||||||
target.setAttribute( 'tabIndex', '0' );
|
target.setAttribute( 'tabIndex', '0' );
|
||||||
target.focus();
|
target.focus();
|
||||||
|
}
|
||||||
}, 100 );
|
}, 100 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -217,31 +215,31 @@
|
|||||||
/**
|
/**
|
||||||
* Toogle hover class for mobile devices.
|
* Toogle hover class for mobile devices.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {NodeList} topMenuItems All menu items.
|
* @param {NodeList} topMenuItems All menu items.
|
||||||
* @param {Event} e The click event.
|
* @param {Event} event The click event.
|
||||||
*/
|
*/
|
||||||
function mobileHover( topMenuItems, e ) {
|
function mobileHover( topMenuItems, event ) {
|
||||||
var wrapper;
|
var wrapper;
|
||||||
|
|
||||||
if ( !! getClosest( e.target, '.ab-sub-wrapper' ) ) {
|
if ( !! getClosest( event.target, '.ab-sub-wrapper' ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
e.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
wrapper = getClosest( e.target, '.menupop' );
|
wrapper = getClosest( event.target, '.menupop' );
|
||||||
|
|
||||||
if ( ! wrapper ) {
|
if ( ! wrapper ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( hasHoverClass( wrapper ) ) {
|
if ( hasClass( wrapper, 'hover' ) ) {
|
||||||
removeHoverClass( wrapper );
|
removeClass( wrapper, 'hover' );
|
||||||
} else {
|
} else {
|
||||||
removeAllHoverClass( topMenuItems );
|
removeAllHoverClass( topMenuItems );
|
||||||
addHoverClass( wrapper );
|
addClass( wrapper, 'hover' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,27 +247,36 @@
|
|||||||
* Handles the click on the Shortlink link in the adminbar.
|
* Handles the click on the Shortlink link in the adminbar.
|
||||||
*
|
*
|
||||||
* @since 3.1.0
|
* @since 3.1.0
|
||||||
* @since 5.3.0 Use querySelector to clean up the function.
|
* @since 5.3.1 Use querySelector to clean up the function.
|
||||||
*
|
|
||||||
* @param {Event} e The click event.
|
|
||||||
*
|
*
|
||||||
|
* @param {Event} event The click event.
|
||||||
* @return {boolean} Returns false to prevent default click behavior.
|
* @return {boolean} Returns false to prevent default click behavior.
|
||||||
*/
|
*/
|
||||||
function clickShortlink( e ) {
|
function clickShortlink( event ) {
|
||||||
var wrapper = e.target.parentNode,
|
var wrapper = event.target.parentNode,
|
||||||
|
input;
|
||||||
|
|
||||||
|
if ( wrapper ) {
|
||||||
input = wrapper.querySelector( '.shortlink-input' );
|
input = wrapper.querySelector( '.shortlink-input' );
|
||||||
|
|
||||||
// IE doesn't support preventDefault, and does support returnValue
|
|
||||||
if ( e.preventDefault ) {
|
|
||||||
e.preventDefault();
|
|
||||||
}
|
}
|
||||||
e.returnValue = false;
|
|
||||||
|
|
||||||
wrapper.classList.add( 'selected' );
|
if ( ! input ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// (Old) IE doesn't support preventDefault, and does support returnValue
|
||||||
|
if ( event.preventDefault ) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.returnValue = false;
|
||||||
|
|
||||||
|
addClass( wrapper, 'selected' );
|
||||||
|
|
||||||
input.focus();
|
input.focus();
|
||||||
input.select();
|
input.select();
|
||||||
input.onblur = function() {
|
input.onblur = function() {
|
||||||
wrapper.classList.remove( 'selected' );
|
removeClass( wrapper, 'selected' );
|
||||||
};
|
};
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -278,64 +285,111 @@
|
|||||||
/**
|
/**
|
||||||
* Clear sessionStorage on logging out.
|
* Clear sessionStorage on logging out.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*/
|
*/
|
||||||
function emptySessionStorage() {
|
function emptySessionStorage() {
|
||||||
if ( 'sessionStorage' in window ) {
|
if ( 'sessionStorage' in window ) {
|
||||||
try {
|
try {
|
||||||
for ( var key in sessionStorage ) {
|
for ( var key in sessionStorage ) {
|
||||||
if ( key.indexOf( 'wp-autosave-' ) != -1 ) {
|
if ( key.indexOf( 'wp-autosave-' ) > -1 ) {
|
||||||
sessionStorage.removeItem( key );
|
sessionStorage.removeItem( key );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch ( e ) {}
|
} catch ( er ) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if menu item has hover class.
|
* Check if element has class.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} item Menu item Element.
|
* @param {HTMLElement} element The HTML element.
|
||||||
|
* @param {String} className The class name.
|
||||||
|
* @return {bool} Whether the element has the className.
|
||||||
*/
|
*/
|
||||||
function hasHoverClass( item ) {
|
function hasClass( element, className ) {
|
||||||
return item.classList.contains( 'hover' );
|
var classNames;
|
||||||
|
|
||||||
|
if ( ! element ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( element.classList && element.classList.contains ) {
|
||||||
|
return element.classList.contains( className );
|
||||||
|
} else if ( element.className ) {
|
||||||
|
classNames = element.className.split( ' ' );
|
||||||
|
return classNames.indexOf( className ) > -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add hover class for menu item.
|
* Add class to an element.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} item Menu item Element.
|
* @param {HTMLElement} element The HTML element.
|
||||||
|
* @param {String} className The class name.
|
||||||
*/
|
*/
|
||||||
function addHoverClass( item ) {
|
function addClass( element, className ) {
|
||||||
item.classList.add( 'hover' );
|
if ( ! element ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( element.classList && element.classList.add ) {
|
||||||
|
element.classList.add( className );
|
||||||
|
} else if ( ! hasClass( element, className ) ) {
|
||||||
|
if ( element.className ) {
|
||||||
|
element.className += ' ';
|
||||||
|
}
|
||||||
|
|
||||||
|
element.className += className;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove hover class for menu item.
|
* Remove class from an element.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} item Menu item Element.
|
* @param {HTMLElement} element The HTML element.
|
||||||
|
* @param {String} className The class name.
|
||||||
*/
|
*/
|
||||||
function removeHoverClass( item ) {
|
function removeClass( element, className ) {
|
||||||
item.classList.remove( 'hover' );
|
var testName,
|
||||||
|
classes;
|
||||||
|
|
||||||
|
if ( ! element || ! hasClass( element, className ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( element.classList && element.classList.remove ) {
|
||||||
|
element.classList.remove( className );
|
||||||
|
} else {
|
||||||
|
testName = ' ' + className + ' ';
|
||||||
|
classes = ' ' + element.className + ' ';
|
||||||
|
|
||||||
|
while ( classes.indexOf( testName ) > -1 ) {
|
||||||
|
classes = classes.replace( testName, '' );
|
||||||
|
}
|
||||||
|
|
||||||
|
element.className = classes.replace( /^[\s]+|[\s]+$/g, '' );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove hover class for all menu items.
|
* Remove hover class for all menu items.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {NodeList} topMenuItems All menu items.
|
* @param {NodeList} topMenuItems All menu items.
|
||||||
*/
|
*/
|
||||||
function removeAllHoverClass( topMenuItems ) {
|
function removeAllHoverClass( topMenuItems ) {
|
||||||
|
if ( topMenuItems && topMenuItems.length ) {
|
||||||
for ( var i = 0; i < topMenuItems.length; i++ ) {
|
for ( var i = 0; i < topMenuItems.length; i++ ) {
|
||||||
if ( hasHoverClass( topMenuItems[i] ) ) {
|
removeClass( topMenuItems[i], 'hover' );
|
||||||
removeHoverClass( topMenuItems[i] );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -345,7 +399,7 @@
|
|||||||
*
|
*
|
||||||
* @since 3.4.0
|
* @since 3.4.0
|
||||||
*
|
*
|
||||||
* @param {Event} e The Click event.
|
* @param {Event} event The Click event.
|
||||||
*
|
*
|
||||||
* @return {void}
|
* @return {void}
|
||||||
*/
|
*/
|
||||||
@ -353,9 +407,8 @@
|
|||||||
// Only scroll when clicking on the wpadminbar, not on menus or submenus.
|
// Only scroll when clicking on the wpadminbar, not on menus or submenus.
|
||||||
if (
|
if (
|
||||||
event.target &&
|
event.target &&
|
||||||
event.target.id &&
|
event.target.id !== 'wpadminbar' &&
|
||||||
event.target.id != 'wpadminbar' &&
|
event.target.id !== 'wp-admin-bar-top-secondary'
|
||||||
event.target.id != 'wp-admin-bar-top-secondary'
|
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -374,23 +427,26 @@
|
|||||||
/**
|
/**
|
||||||
* Get closest Element.
|
* Get closest Element.
|
||||||
*
|
*
|
||||||
* @since 5.3.0
|
* @since 5.3.1
|
||||||
*
|
*
|
||||||
* @param {HTMLElement} el Element to get parent.
|
* @param {HTMLElement} el Element to get parent.
|
||||||
* @param {string} selector CSS selector to match.
|
* @param {string} selector CSS selector to match.
|
||||||
*/
|
*/
|
||||||
function getClosest( el, selector ) {
|
function getClosest( el, selector ) {
|
||||||
if ( ! Element.prototype.matches ) {
|
if ( ! window.Element.prototype.matches ) {
|
||||||
Element.prototype.matches =
|
// Polyfill from https://developer.mozilla.org/en-US/docs/Web/API/Element/matches.
|
||||||
Element.prototype.matchesSelector ||
|
window.Element.prototype.matches =
|
||||||
Element.prototype.mozMatchesSelector ||
|
window.Element.prototype.matchesSelector ||
|
||||||
Element.prototype.msMatchesSelector ||
|
window.Element.prototype.mozMatchesSelector ||
|
||||||
Element.prototype.oMatchesSelector ||
|
window.Element.prototype.msMatchesSelector ||
|
||||||
Element.prototype.webkitMatchesSelector ||
|
window.Element.prototype.oMatchesSelector ||
|
||||||
|
window.Element.prototype.webkitMatchesSelector ||
|
||||||
function( s ) {
|
function( s ) {
|
||||||
var matches = ( this.document || this.ownerDocument ).querySelectorAll( s ),
|
var matches = ( this.document || this.ownerDocument ).querySelectorAll( s ),
|
||||||
i = matches.length;
|
i = matches.length;
|
||||||
|
|
||||||
while ( --i >= 0 && matches.item( i ) !== this ) { }
|
while ( --i >= 0 && matches.item( i ) !== this ) { }
|
||||||
|
|
||||||
return i > -1;
|
return i > -1;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -401,6 +457,8 @@
|
|||||||
return el;
|
return el;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
} )( document, window, navigator );
|
} )( document, window, navigator );
|
||||||
|
Loading…
Reference in New Issue
Block a user