From: jenkins-bot Date: Fri, 30 Mar 2018 15:15:38 +0000 (+0000) Subject: Merge "mediawiki.action.view.rightClickEdit: Remove redundanat dom-ready handler" X-Git-Tag: 1.31.0-rc.0~241 X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=commitdiff_plain;h=b5fe7fbbed00c402c53e45912140ee2090e5c60a;hp=28f57e9ef44cc3028e19a5c0aae84472e80f2519 Merge "mediawiki.action.view.rightClickEdit: Remove redundanat dom-ready handler" --- diff --git a/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js index ebd1ebccdf..35f948ebab 100644 --- a/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js +++ b/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js @@ -3,11 +3,12 @@ * When the user right-clicks in a heading, it will open the * edit screen. */ -jQuery( function ( $ ) { - // Select all h1-h6 elements that contain editsection links - // Don't use the ":has:(.mw-editsection a)" selector because it performs very bad. - // http://jsperf.com/jq-1-7-2-vs-jq-1-8-1-performance-of-mw-has/2 +( function ( $ ) { + // Trigger this when a contextmenu click on the page targets an h1-h6 element. + // This uses a delegate handler which 1) starts immediately instead of blocking + // response on dom-ready, and 2) selects and binds once instead of N times. $( document ).on( 'contextmenu', 'h1, h2, h3, h4, h5, h6', function ( e ) { + // Don't use ":has:(.mw-editsection a)" in the selector because it's slow. var $edit = $( this ).find( '.mw-editsection a' ); if ( !$edit.length ) { return; @@ -23,4 +24,4 @@ jQuery( function ( $ ) { $edit.get( 0 ).click(); } } ); -} ); +}( jQuery ) );