mediawiki.page.ready: Simplify logout code
authorFomafix <fomafix@googlemail.com>
Sun, 4 Aug 2019 13:10:11 +0000 (15:10 +0200)
committerKrinkle <krinklemail@gmail.com>
Mon, 5 Aug 2019 22:22:28 +0000 (22:22 +0000)
* 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

resources/src/mediawiki.page.ready.js

index 4eba81d..0e59da6 100644 (file)
 
                // 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();
                } );
        } );