From d4a552e65bdfd7309a9b8537e9dbe69c5e2991eb Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Sat, 14 Sep 2019 03:19:46 +0100 Subject: [PATCH] mediawiki.page.ready: Avoid duplicate DOM query on logout click 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 | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/resources/src/mediawiki.page.ready/ready.js b/resources/src/mediawiki.page.ready/ready.js index 3226165474..48d605d455 100644 --- a/resources/src/mediawiki.page.ready/ready.js +++ b/resources/src/mediawiki.page.ready/ready.js @@ -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 } ); } -- 2.20.1