X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=resources%2Fsrc%2Fmediawiki.action%2Fmediawiki.action.view.rightClickEdit.js;h=35f948ebabcda5cacbaea55306f6f539296f2576;hp=ada101eb1614da80921fec70f9b2c96c90820db9;hb=7ac6ec988857322dff99b7d6b6f07d9e56f06b7e;hpb=476997b3bbfb88bbae0083cd1f882f4b97f357b7 diff --git a/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js b/resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js index ada101eb16..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; @@ -18,9 +19,9 @@ jQuery( function ( $ ) { // inside the heading (e.g. to do things like copy URL, open in new tab, ..). // e.target can be the heading, but it can also be anything inside the heading. if ( e.target.nodeName.toLowerCase() !== 'a' ) { - // Trigger native HTMLElement click instead of opening URL (bug 43052) + // Trigger native HTMLElement click instead of opening URL (T45052) e.preventDefault(); $edit.get( 0 ).click(); } } ); -} ); +}( jQuery ) );