Drop ES5 compatible code

Drop usages of $.closest in favor of ES6 closest

We also no longer need to check for whether closest is available
now that we do not need to worry about ES5 code.

Change-Id: I2442a4f69f8181dd761ca7ac418839cfca26a36f
This commit is contained in:
Jon Robson 2023-04-12 15:27:28 -07:00 committed by Jdlrobson
parent 2499e834bb
commit 10033b294e
3 changed files with 9 additions and 20 deletions

View file

@ -123,8 +123,12 @@ function addPortletLinkHandler( item, data ) {
// assign variables after early return.
const link = item.querySelector( 'a' );
const $menu = $( item ).parents( '.vector-menu' );
const menuElement = $menu.length && $menu.get( 0 ) || null;
const menuElement = /** @type {HTMLElement} */(
item.closest( '.vector-menu' )
);
if ( !menuElement ) {
return;
}
if ( data.id ) {
iconElement = createIconElement( menuElement, link, data.id );
@ -132,7 +136,7 @@ function addPortletLinkHandler( item, data ) {
// The views menu has limited space so we need to decide whether there is space
// to accommodate the new item and if not to redirect to the more dropdown.
if ( $menu.prop( 'id' ) === 'p-views' ) {
if ( menuElement.id === 'p-views' ) {
const availableWidth = getAvailableViewMenuWidth();
const moreDropdown = document.querySelector( '#p-cactions ul' );
@ -143,8 +147,7 @@ function addPortletLinkHandler( item, data ) {
}
}
// Check link.prepend exists for older browser since this is ES5 code
if ( link && iconElement && link.prepend ) {
if ( link && iconElement ) {
link.prepend( iconElement );
}
}

View file

@ -24,16 +24,7 @@ function init() {
toggle.addEventListener( 'click', function () {
features.toggle( LIMITED_WIDTH_FEATURE_NAME );
setDataAttribute( toggle );
// Fire a simulated window resize event (T328121)
let event;
if ( typeof Event === 'function' ) {
event = new Event( 'resize' );
} else {
// IE11
event = window.document.createEvent( 'UIEvents' );
event.initUIEvent( 'resize', true, false, window, 0 );
}
window.dispatchEvent( event );
window.dispatchEvent( new Event( 'resize' ) );
} );
}

View file

@ -14,11 +14,6 @@ function addNoIconClass( item ) {
}
function init() {
// Feature detect whether the `.closest` api is supported. If not, return early.
if ( !document.body.closest ) {
return;
}
// Enhance previously added items.
Array.prototype.forEach.call(
document.querySelectorAll( TABS_SELECTOR + ' ' + LIST_ITEM_JS_SELECTOR ),