Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.special.preferences / confirmClose.js
index 244154b..03309de 100644 (file)
@@ -2,7 +2,7 @@
  * JavaScript for Special:Preferences: Enable save button and prevent the window being accidentally
  * closed when any form field is changed.
  */
-( function ( mw, $ ) {
+( function () {
        $( function () {
                var allowCloseWindow, saveButton, restoreButton,
                        oouiEnabled = $( '#mw-prefs-form' ).hasClass( 'mw-htmlform-ooui' );
                        // 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() );
+                       // Attach capturing event handlers to the document, to catch events inside OOUI dropdowns:
+                       // * Use capture because OO.ui.SelectWidget also does, and it stops event propagation,
+                       //   so the event is not fired on descendant elements
+                       // * Attach to the document because the dropdowns are in the .oo-ui-defaultOverlay element
+                       //   (and it doesn't exist yet at this point, so we can't attach them to it)
+                       [ 'change', 'keyup', 'mouseup' ].forEach( function ( eventType ) {
+                               document.addEventListener( eventType, function () {
+                                       // Make sure SelectWidget's event handlers run first
+                                       setTimeout( function () {
+                                               saveButton.setDisabled( !isPrefsChanged() );
+                                       } );
+                               }, true );
                        } );
                } else {
                        // Disable the button to save preferences unless preferences have changed
@@ -71,7 +81,7 @@
                        message: mw.msg( 'prefswarning-warning', mw.msg( 'saveprefs' ) ),
                        namespace: 'prefswarning'
                } );
-               $( '#mw-prefs-form' ).on( 'submit', $.proxy( allowCloseWindow, 'release' ) );
+               $( '#mw-prefs-form' ).on( 'submit', allowCloseWindow.release );
                if ( oouiEnabled ) {
                        restoreButton.on( 'click', function () {
                                allowCloseWindow.release();
@@ -80,7 +90,7 @@
                                location.href = restoreButton.getHref();
                        } );
                } else {
-                       $( '#mw-prefs-restoreprefs' ).on( 'click', $.proxy( allowCloseWindow, 'release' ) );
+                       $( '#mw-prefs-restoreprefs' ).on( 'click', allowCloseWindow.release );
                }
        } );
-}( mediaWiki, jQuery ) );
+}() );