mediawiki.page.ready: Avoid duplicate DOM query on logout click
authorTimo Tijhof <krinklemail@gmail.com>
Sat, 14 Sep 2019 02:19:46 +0000 (03:19 +0100)
committerKrinkle <krinklemail@gmail.com>
Sat, 14 Sep 2019 23:27:36 +0000 (23:27 +0000)
The result of this DOM selector query is already available
as 'this' given we're in an event handler, use that directly
instead.

Also:
* Use the 'href' property directly instead of using jQuery or attributes.
* Avoid shadow names by naming the error handler param 'err' instead
  of 'e'.

Change-Id: I94a757ca1dd782b1e138a372983b6bfa16081485

resources/src/mediawiki.page.ready/ready.js

index 3226165..48d605d 100644 (file)
@@ -21,7 +21,7 @@ mw.hook( 'wikipage.content' ).add( function ( $content ) {
        checkboxShift( $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ) );
 } );
 
-// Things outside the wikipage content
+// Handle elements outside the wikipage content
 $( function () {
        var $nodes;
 
@@ -56,7 +56,7 @@ $( function () {
        // Turn logout to a POST action
        $( '#pt-logout a' ).on( 'click', function ( e ) {
                var api = new mw.Api(),
-                       returnUrl = $( '#pt-logout a' ).attr( 'href' );
+                       url = this.href;
                mw.notify(
                        mw.message( 'logging-out-notify' ),
                        { tag: 'logout', autoHide: false }
@@ -65,11 +65,11 @@ $( function () {
                        action: 'logout'
                } ).then(
                        function () {
-                               location.href = returnUrl;
+                               location.href = url;
                        },
-                       function ( e ) {
+                       function ( err ) {
                                mw.notify(
-                                       mw.message( 'logout-failed', e ),
+                                       mw.message( 'logout-failed', err ),
                                        { type: 'error', tag: 'logout', autoHide: false }
                                );
                        }