From: Fomafix Date: Sun, 4 Aug 2019 13:10:11 +0000 (+0200) Subject: mediawiki.page.ready: Simplify logout code X-Git-Tag: 1.34.0-rc.0~775^2 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/supprimer.php?a=commitdiff_plain;h=d41fe82a23a2e48afd8be099b45a7dde8696e6d0;p=lhc%2Fweb%2Fwiklou.git mediawiki.page.ready: Simplify logout code * Use location.href instead of window.location. (Better static analysis, and theoretically quicker lookup) * Initialize variable on declaration. * Use .then() instead of .done().fail(). Change-Id: If007ae9bad37461cf1a1b51bd4d21281d7778254 --- diff --git a/resources/src/mediawiki.page.ready.js b/resources/src/mediawiki.page.ready.js index 4eba81d5ca..0e59da624b 100644 --- a/resources/src/mediawiki.page.ready.js +++ b/resources/src/mediawiki.page.ready.js @@ -56,22 +56,25 @@ // Turn logout to a POST action $( '#pt-logout a' ).on( 'click', function ( e ) { - var api = new mw.Api(), returnUrl; - returnUrl = $( '#pt-logout a' ).attr( 'href' ); + var api = new mw.Api(), + returnUrl = $( '#pt-logout a' ).attr( 'href' ); mw.notify( mw.message( 'logging-out-notify' ), { tag: 'logout', autoHide: false } ); api.postWithToken( 'csrf', { action: 'logout' - } ).done( function () { - window.location = returnUrl; - } ).fail( function ( e ) { - mw.notify( - mw.message( 'logout-failed', e ), - { type: 'error', tag: 'logout', autoHide: false } - ); - } ); + } ).then( + function () { + location.href = returnUrl; + }, + function ( e ) { + mw.notify( + mw.message( 'logout-failed', e ), + { type: 'error', tag: 'logout', autoHide: false } + ); + } + ); e.preventDefault(); } ); } );