mediawiki.action.view.rightClickEdit: Remove redundanat dom-ready handler
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 29 Mar 2018 21:33:25 +0000 (14:33 -0700)
committerKrinkle <krinklemail@gmail.com>
Thu, 29 Mar 2018 21:42:18 +0000 (21:42 +0000)
This file was wrapped in a jQuery() dom-ready callback, but it doesn't
and shouldn't have that because it needlessly delays execution.

I probably added because back then, using the first parameter of jQuery()
was a common way for aliasing it to '$', but we use closures for that
nowadays.

Change-Id: I65768564ed556828fd193dfe99d11370fa745112

resources/src/mediawiki.action/mediawiki.action.view.rightClickEdit.js

index ebd1ebc..35f948e 100644 (file)
@@ -3,11 +3,12 @@
  * When the user right-clicks in a heading, it will open the
  * edit screen.
  */
  * 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 ) {
        $( 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;
                var $edit = $( this ).find( '.mw-editsection a' );
                if ( !$edit.length ) {
                        return;
@@ -23,4 +24,4 @@ jQuery( function ( $ ) {
                        $edit.get( 0 ).click();
                }
        } );
                        $edit.get( 0 ).click();
                }
        } );
-} );
+}( jQuery ) );