diff -r be944660c56a -r 3d72ae0968f4 wp/wp-includes/js/jquery/ui/menu.js
--- a/wp/wp-includes/js/jquery/ui/menu.js Wed Sep 21 18:19:35 2022 +0200
+++ b/wp/wp-includes/js/jquery/ui/menu.js Tue Sep 27 16:37:53 2022 +0200
@@ -1,5 +1,5 @@
/*!
- * jQuery UI Menu 1.12.1
+ * jQuery UI Menu 1.13.1
* http://jqueryui.com
*
* Copyright jQuery Foundation and other contributors
@@ -17,6 +17,8 @@
//>>css.theme: ../../themes/base/theme.css
( function( factory ) {
+ "use strict";
+
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
@@ -29,10 +31,11 @@
// Browser globals
factory( jQuery );
}
-}( function( $ ) {
+} )( function( $ ) {
+"use strict";
return $.widget( "ui.menu", {
- version: "1.12.1",
+ version: "1.13.1",
defaultElement: "
",
delay: 300,
options: {
@@ -59,6 +62,7 @@
// Flag used to prevent firing of the click handler
// as the event bubbles up through nested menus
this.mouseHandled = false;
+ this.lastMousePosition = { x: null, y: null };
this.element
.uniqueId()
.attr( {
@@ -73,6 +77,8 @@
// them (focus should always stay on UL during navigation).
"mousedown .ui-menu-item": function( event ) {
event.preventDefault();
+
+ this._activateItem( event );
},
"click .ui-menu-item": function( event ) {
var target = $( event.target );
@@ -89,7 +95,7 @@
if ( target.has( ".ui-menu" ).length ) {
this.expand( event );
} else if ( !this.element.is( ":focus" ) &&
- active.closest( ".ui-menu" ).length ) {
+ active.closest( ".ui-menu" ).length ) {
// Redirect focus to the menu
this.element.trigger( "focus", [ true ] );
@@ -102,36 +108,15 @@
}
}
},
- "mouseenter .ui-menu-item": function( event ) {
-
- // Ignore mouse events while typeahead is active, see #10458.
- // Prevents focusing the wrong item when typeahead causes a scroll while the mouse
- // is over an item in the menu
- if ( this.previousFilter ) {
- return;
- }
-
- var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
- target = $( event.currentTarget );
-
- // Ignore bubbled events on parent items, see #11641
- if ( actualTarget[ 0 ] !== target[ 0 ] ) {
- return;
- }
-
- // Remove ui-state-active class from siblings of the newly focused menu item
- // to avoid a jump caused by adjacent elements both having a class with a border
- this._removeClass( target.siblings().children( ".ui-state-active" ),
- null, "ui-state-active" );
- this.focus( event, target );
- },
+ "mouseenter .ui-menu-item": "_activateItem",
+ "mousemove .ui-menu-item": "_activateItem",
mouseleave: "collapseAll",
"mouseleave .ui-menu": "collapseAll",
focus: function( event, keepActiveItem ) {
// If there's already an active item, keep it active
// If not, activate the first item
- var item = this.active || this.element.find( this.options.items ).eq( 0 );
+ var item = this.active || this._menuItems().first();
if ( !keepActiveItem ) {
this.focus( event, item );
@@ -157,7 +142,7 @@
this._on( this.document, {
click: function( event ) {
if ( this._closeOnDocumentClick( event ) ) {
- this.collapseAll( event );
+ this.collapseAll( event, true );
}
// Reset the mouseHandled flag
@@ -166,6 +151,46 @@
} );
},
+ _activateItem: function( event ) {
+
+ // Ignore mouse events while typeahead is active, see #10458.
+ // Prevents focusing the wrong item when typeahead causes a scroll while the mouse
+ // is over an item in the menu
+ if ( this.previousFilter ) {
+ return;
+ }
+
+ // If the mouse didn't actually move, but the page was scrolled, ignore the event (#9356)
+ if ( event.clientX === this.lastMousePosition.x &&
+ event.clientY === this.lastMousePosition.y ) {
+ return;
+ }
+
+ this.lastMousePosition = {
+ x: event.clientX,
+ y: event.clientY
+ };
+
+ var actualTarget = $( event.target ).closest( ".ui-menu-item" ),
+ target = $( event.currentTarget );
+
+ // Ignore bubbled events on parent items, see #11641
+ if ( actualTarget[ 0 ] !== target[ 0 ] ) {
+ return;
+ }
+
+ // If the item is already active, there's nothing to do
+ if ( target.is( ".ui-state-active" ) ) {
+ return;
+ }
+
+ // Remove ui-state-active class from siblings of the newly focused menu item
+ // to avoid a jump caused by adjacent elements both having a class with a border
+ this._removeClass( target.siblings().children( ".ui-state-active" ),
+ null, "ui-state-active" );
+ this.focus( event, target );
+ },
+
_destroy: function() {
var items = this.element.find( ".ui-menu-item" )
.removeAttr( "role aria-disabled" ),
@@ -177,10 +202,10 @@
this.element
.removeAttr( "aria-activedescendant" )
.find( ".ui-menu" ).addBack()
- .removeAttr( "role aria-labelledby aria-expanded aria-hidden aria-disabled " +
- "tabIndex" )
- .removeUniqueId()
- .show();
+ .removeAttr( "role aria-labelledby aria-expanded aria-hidden aria-disabled " +
+ "tabIndex" )
+ .removeUniqueId()
+ .show();
submenus.children().each( function() {
var elem = $( this );
@@ -195,77 +220,77 @@
preventDefault = true;
switch ( event.keyCode ) {
- case $.ui.keyCode.PAGE_UP:
- this.previousPage( event );
- break;
- case $.ui.keyCode.PAGE_DOWN:
- this.nextPage( event );
- break;
- case $.ui.keyCode.HOME:
- this._move( "first", "first", event );
- break;
- case $.ui.keyCode.END:
- this._move( "last", "last", event );
- break;
- case $.ui.keyCode.UP:
- this.previous( event );
- break;
- case $.ui.keyCode.DOWN:
- this.next( event );
- break;
- case $.ui.keyCode.LEFT:
- this.collapse( event );
- break;
- case $.ui.keyCode.RIGHT:
- if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
- this.expand( event );
- }
- break;
- case $.ui.keyCode.ENTER:
- case $.ui.keyCode.SPACE:
- this._activate( event );
- break;
- case $.ui.keyCode.ESCAPE:
- this.collapse( event );
- break;
- default:
- preventDefault = false;
- prev = this.previousFilter || "";
- skip = false;
+ case $.ui.keyCode.PAGE_UP:
+ this.previousPage( event );
+ break;
+ case $.ui.keyCode.PAGE_DOWN:
+ this.nextPage( event );
+ break;
+ case $.ui.keyCode.HOME:
+ this._move( "first", "first", event );
+ break;
+ case $.ui.keyCode.END:
+ this._move( "last", "last", event );
+ break;
+ case $.ui.keyCode.UP:
+ this.previous( event );
+ break;
+ case $.ui.keyCode.DOWN:
+ this.next( event );
+ break;
+ case $.ui.keyCode.LEFT:
+ this.collapse( event );
+ break;
+ case $.ui.keyCode.RIGHT:
+ if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
+ this.expand( event );
+ }
+ break;
+ case $.ui.keyCode.ENTER:
+ case $.ui.keyCode.SPACE:
+ this._activate( event );
+ break;
+ case $.ui.keyCode.ESCAPE:
+ this.collapse( event );
+ break;
+ default:
+ preventDefault = false;
+ prev = this.previousFilter || "";
+ skip = false;
- // Support number pad values
- character = event.keyCode >= 96 && event.keyCode <= 105 ?
- ( event.keyCode - 96 ).toString() : String.fromCharCode( event.keyCode );
+ // Support number pad values
+ character = event.keyCode >= 96 && event.keyCode <= 105 ?
+ ( event.keyCode - 96 ).toString() : String.fromCharCode( event.keyCode );
- clearTimeout( this.filterTimer );
+ clearTimeout( this.filterTimer );
- if ( character === prev ) {
- skip = true;
- } else {
- character = prev + character;
- }
+ if ( character === prev ) {
+ skip = true;
+ } else {
+ character = prev + character;
+ }
- match = this._filterMenuItems( character );
- match = skip && match.index( this.active.next() ) !== -1 ?
- this.active.nextAll( ".ui-menu-item" ) :
- match;
+ match = this._filterMenuItems( character );
+ match = skip && match.index( this.active.next() ) !== -1 ?
+ this.active.nextAll( ".ui-menu-item" ) :
+ match;
- // If no matches on the current filter, reset to the last character pressed
- // to move down the menu to the first item that starts with that character
- if ( !match.length ) {
- character = String.fromCharCode( event.keyCode );
- match = this._filterMenuItems( character );
- }
+ // If no matches on the current filter, reset to the last character pressed
+ // to move down the menu to the first item that starts with that character
+ if ( !match.length ) {
+ character = String.fromCharCode( event.keyCode );
+ match = this._filterMenuItems( character );
+ }
- if ( match.length ) {
- this.focus( event, match );
- this.previousFilter = character;
- this.filterTimer = this._delay( function() {
+ if ( match.length ) {
+ this.focus( event, match );
+ this.previousFilter = character;
+ this.filterTimer = this._delay( function() {
+ delete this.previousFilter;
+ }, 1000 );
+ } else {
delete this.previousFilter;
- }, 1000 );
- } else {
- delete this.previousFilter;
- }
+ }
}
if ( preventDefault ) {
@@ -328,11 +353,11 @@
newItems = items.not( ".ui-menu-item, .ui-menu-divider" );
newWrappers = newItems.children()
.not( ".ui-menu" )
- .uniqueId()
- .attr( {
- tabIndex: -1,
- role: this._itemRole()
- } );
+ .uniqueId()
+ .attr( {
+ tabIndex: -1,
+ role: this._itemRole()
+ } );
this._addClass( newItems, "ui-menu-item" )
._addClass( newWrappers, "ui-menu-item-wrapper" );
@@ -388,8 +413,8 @@
// Highlight active parent menu item, if any
activeParent = this.active
.parent()
- .closest( ".ui-menu-item" )
- .children( ".ui-menu-item-wrapper" );
+ .closest( ".ui-menu-item" )
+ .children( ".ui-menu-item-wrapper" );
this._addClass( activeParent, null, "ui-state-active" );
if ( event && event.type === "keydown" ) {
@@ -497,7 +522,7 @@
this._removeClass( currentMenu.find( ".ui-state-active" ), null, "ui-state-active" );
this.activeMenu = currentMenu;
- }, this.delay );
+ }, all ? 0 : this.delay );
},
// With no arguments, closes the currently active menu - if nothing is active
@@ -533,11 +558,7 @@
},
expand: function( event ) {
- var newItem = this.active &&
- this.active
- .children( ".ui-menu " )
- .find( this.options.items )
- .first();
+ var newItem = this.active && this._menuItems( this.active.children( ".ui-menu" ) ).first();
if ( newItem && newItem.length ) {
this._open( newItem.parent() );
@@ -565,21 +586,27 @@
return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
},
+ _menuItems: function( menu ) {
+ return ( menu || this.element )
+ .find( this.options.items )
+ .filter( ".ui-menu-item" );
+ },
+
_move: function( direction, filter, event ) {
var next;
if ( this.active ) {
if ( direction === "first" || direction === "last" ) {
next = this.active
[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
- .eq( -1 );
+ .last();
} else {
next = this.active
[ direction + "All" ]( ".ui-menu-item" )
- .eq( 0 );
+ .first();
}
}
if ( !next || !next.length || !this.active ) {
- next = this.activeMenu.find( this.options.items )[ filter ]();
+ next = this._menuItems( this.activeMenu )[ filter ]();
}
this.focus( event, next );
@@ -597,7 +624,13 @@
}
if ( this._hasScroll() ) {
base = this.active.offset().top;
- height = this.element.height();
+ height = this.element.innerHeight();
+
+ // jQuery 3.2 doesn't include scrollbars in innerHeight, add it back.
+ if ( $.fn.jquery.indexOf( "3.2." ) === 0 ) {
+ height += this.element[ 0 ].offsetHeight - this.element.outerHeight();
+ }
+
this.active.nextAll( ".ui-menu-item" ).each( function() {
item = $( this );
return item.offset().top - base - height < 0;
@@ -605,7 +638,7 @@
this.focus( event, item );
} else {
- this.focus( event, this.activeMenu.find( this.options.items )
+ this.focus( event, this._menuItems( this.activeMenu )
[ !this.active ? "first" : "last" ]() );
}
},
@@ -621,7 +654,13 @@
}
if ( this._hasScroll() ) {
base = this.active.offset().top;
- height = this.element.height();
+ height = this.element.innerHeight();
+
+ // jQuery 3.2 doesn't include scrollbars in innerHeight, add it back.
+ if ( $.fn.jquery.indexOf( "3.2." ) === 0 ) {
+ height += this.element[ 0 ].offsetHeight - this.element.outerHeight();
+ }
+
this.active.prevAll( ".ui-menu-item" ).each( function() {
item = $( this );
return item.offset().top - base + height > 0;
@@ -629,7 +668,7 @@
this.focus( event, item );
} else {
- this.focus( event, this.activeMenu.find( this.options.items ).first() );
+ this.focus( event, this._menuItems( this.activeMenu ).first() );
}
},
@@ -656,13 +695,14 @@
return this.activeMenu
.find( this.options.items )
- // Only match on items, not dividers or other content (#10571)
- .filter( ".ui-menu-item" )
- .filter( function() {
- return regex.test(
- $.trim( $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
- } );
+ // Only match on items, not dividers or other content (#10571)
+ .filter( ".ui-menu-item" )
+ .filter( function() {
+ return regex.test(
+ String.prototype.trim.call(
+ $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
+ } );
}
} );
-} ) );
+} );