Merge "Add tests for WikiMap and WikiReference"
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.preferences.js
index 893db98..bad1c08 100644 (file)
@@ -1,4 +1,3 @@
-
 /*!
  * JavaScript for Special:Preferences
  */
@@ -52,8 +51,8 @@ jQuery( function ( $ ) {
         * It uses document.getElementById for security reasons (HTML injections in $()).
         *
         * @ignore
-        * @param String name: the name of a tab without the prefix ("mw-prefsection-")
-        * @param String mode: [optional] A hash will be set according to the current
+        * @param {String} name the name of a tab without the prefix ("mw-prefsection-")
+        * @param {String} [mode] A hash will be set according to the current
         *  open section. Set mode 'noHash' to surpress this.
         */
        function switchPrefTab( name, mode ) {
@@ -86,18 +85,23 @@ jQuery( function ( $ ) {
                }
        }
 
-       // If there is a #mw-preferences-success box and javascript is enabled, use a slick notification instead!
-       if ( $( '#mw-preferences-success' ).length ) {
-               notif = mediaWiki.notification.notify( mediaWiki.message( 'savedprefs' ), { autoHide: false } );
-               $( '#preftoc, .prefsection' ).one( 'change keydown mousedown', function () { // 'change' event not reliable!
-                       if ( notif ) {
-                               notif.close();
-                       }
-               } );
+       // Check for messageboxes (.successbox, .warningbox, .errorbox) to replace with notifications
+       if ( $( '.mw-preferences-messagebox' ).length ) {
+               // If there is a #mw-preferences-success box and javascript is enabled, use a slick notification instead!
+               if ( $( '#mw-preferences-success' ).length ) {
+                       notif = mediaWiki.notification.notify( mediaWiki.message( 'savedprefs' ), { autoHide: false } );
+                       // 'change' event not reliable!
+                       $( '#preftoc, .prefsection' ).one( 'change keydown mousedown', function () {
+                               if ( notif ) {
+                                       notif.close();
+                                       notif = null;
+                               }
+                       } );
 
-               // Remove now-unnecessary success=1 querystring to prevent reappearance of notification on reload
-               if ( history.replaceState ) {
-                       history.replaceState( {}, document.title, document.URL.replace( /&?success=1/, '' ) );
+                       // Remove now-unnecessary success=1 querystring to prevent reappearance of notification on reload
+                       if ( history.replaceState ) {
+                               history.replaceState( {}, document.title, location.href.replace( /&?success=1/, '' ) );
+                       }
                }
        }
 
@@ -130,7 +134,7 @@ jQuery( function ( $ ) {
        // Disable the button to save preferences unless preferences have changed
        $( '#prefcontrol' ).prop( 'disabled', true );
        $( '.prefsection' ).one( 'change keydown mousedown', function () {
-               $( '#prefcontrol' ).prop( 'disabled', false);
+               $( '#prefcontrol' ).prop( 'disabled', false );
        } );
 
        // Enable keyboard users to use left and right keys to switch tabs
@@ -206,15 +210,15 @@ jQuery( function ( $ ) {
                var minutes,
                        arr = hour.split( ':' );
 
-               arr[0] = parseInt( arr[0], 10 );
+               arr[ 0 ] = parseInt( arr[ 0 ], 10 );
 
                if ( arr.length === 1 ) {
                        // Specification is of the form [-]XX
-                       minutes = arr[0] * 60;
+                       minutes = arr[ 0 ] * 60;
                } else {
                        // Specification is of the form [-]XX:XX
-                       minutes = Math.abs( arr[0] ) * 60 + parseInt( arr[1], 10 );
-                       if ( arr[0] < 0 ) {
+                       minutes = Math.abs( arr[ 0 ] ) * 60 + parseInt( arr[ 1 ], 10 );
+                       if ( arr[ 0 ] < 0 ) {
                                minutes *= -1;
                        }
                }
@@ -241,7 +245,7 @@ jQuery( function ( $ ) {
                        minuteDiff = hoursToMinutes( $tzTextbox.val() );
                } else {
                        // Grab data from the $tzSelect value
-                       minuteDiff = parseInt( type.split( '|' )[1], 10 ) || 0;
+                       minuteDiff = parseInt( type.split( '|' )[ 1 ], 10 ) || 0;
                        $tzTextbox.val( minutesToHours( minuteDiff ) );
                }