Special:Preferences: Create flag to enable OOjs UI
[lhc/web/wiklou.git] / resources / src / mediawiki.special / mediawiki.special.preferences.confirmClose.js
index fe127eb..244154b 100644 (file)
@@ -4,7 +4,8 @@
  */
 ( function ( mw, $ ) {
        $( function () {
-               var allowCloseWindow, saveButton, restoreButton;
+               var allowCloseWindow, saveButton, restoreButton,
+                       oouiEnabled = $( '#mw-prefs-form' ).hasClass( 'mw-htmlform-ooui' );
 
                // Check if all of the form values are unchanged.
                // (This function could be changed to infuse and check OOUI widgets, but that would only make it
@@ -28,7 +29,8 @@
                                                        return true;
                                                }
                                        }
-                               } else if ( $input.is( 'input' ) ) { // <input> has defaultValue or defaultChecked
+                               } else if ( $input.is( 'input' ) || $input.is( 'textarea' ) ) {
+                                       // <input> has defaultValue or defaultChecked
                                        inputType = input.type;
                                        if ( inputType === 'radio' || inputType === 'checkbox' ) {
                                                if ( input.checked !== input.defaultChecked ) {
                        return false;
                }
 
-               saveButton = OO.ui.infuse( $( '#prefcontrol' ) );
-               restoreButton = OO.ui.infuse( $( '#mw-prefs-restoreprefs' ) );
+               if ( oouiEnabled ) {
+                       saveButton = OO.ui.infuse( $( '#prefcontrol' ) );
+                       restoreButton = OO.ui.infuse( $( '#mw-prefs-restoreprefs' ) );
 
-               // Disable the button to save preferences unless preferences have changed
-               // Check if preferences have been changed before JS has finished loading
-               if ( !isPrefsChanged() ) {
-                       saveButton.setDisabled( true );
-                       $( '#preferences .oo-ui-fieldsetLayout' ).one( 'change keydown mousedown', function () {
-                               saveButton.setDisabled( false );
+                       // Disable the button to save preferences unless preferences have changed
+                       // Check if preferences have been changed before JS has finished loading
+                       saveButton.setDisabled( !isPrefsChanged() );
+                       $( '#preferences .oo-ui-fieldsetLayout' ).on( 'change keyup mouseup', function () {
+                               saveButton.setDisabled( !isPrefsChanged() );
+                       } );
+               } else {
+                       // Disable the button to save preferences unless preferences have changed
+                       // Check if preferences have been changed before JS has finished loading
+                       $( '#prefcontrol' ).prop( 'disabled', !isPrefsChanged() );
+                       $( '#preferences > fieldset' ).on( 'change keyup mouseup', function () {
+                               $( '#prefcontrol' ).prop( 'disabled', !isPrefsChanged() );
                        } );
                }
 
                        message: mw.msg( 'prefswarning-warning', mw.msg( 'saveprefs' ) ),
                        namespace: 'prefswarning'
                } );
-               $( '#mw-prefs-form' ).submit( $.proxy( allowCloseWindow, 'release' ) );
-               restoreButton.on( 'click', function () {
-                       allowCloseWindow.release();
-                       // The default behavior of events in OOUI is always prevented. Follow the link manually.
-                       // Note that middle-click etc. still works, as it doesn't emit a OOUI 'click' event.
-                       location.href = restoreButton.getHref();
-               } );
+               $( '#mw-prefs-form' ).on( 'submit', $.proxy( allowCloseWindow, 'release' ) );
+               if ( oouiEnabled ) {
+                       restoreButton.on( 'click', function () {
+                               allowCloseWindow.release();
+                               // The default behavior of events in OOUI is always prevented. Follow the link manually.
+                               // Note that middle-click etc. still works, as it doesn't emit a OOUI 'click' event.
+                               location.href = restoreButton.getHref();
+                       } );
+               } else {
+                       $( '#mw-prefs-restoreprefs' ).on( 'click', $.proxy( allowCloseWindow, 'release' ) );
+               }
        } );
 }( mediaWiki, jQuery ) );