Merge "resourceloader: Simplify StringSet fallback"
[lhc/web/wiklou.git] / resources / src / mediawiki.special.preferences / confirmClose.js
index bf65ae9..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
@@ -83,4 +93,4 @@
                        $( '#mw-prefs-restoreprefs' ).on( 'click', allowCloseWindow.release );
                }
        } );
-}( mediaWiki, jQuery ) );
+}() );