From: Timo Tijhof Date: Sat, 14 Sep 2019 02:19:46 +0000 (+0100) Subject: mediawiki.page.ready: Avoid duplicate DOM query on logout click X-Git-Tag: 1.34.0-rc.0~196^2 X-Git-Url: http://git.cyclocoop.org/%22.htmlspecialchars%28%24url_syndic%29.%22?a=commitdiff_plain;h=d4a552e65bdfd7309a9b8537e9dbe69c5e2991eb;p=lhc%2Fweb%2Fwiklou.git 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 --- 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 } ); }