mw.special.preferences/confirmClose: Catch clicks inside OOUI dropdowns
authorBartosz Dziewoński <matma.rex@gmail.com>
Fri, 7 Sep 2018 17:58:34 +0000 (19:58 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Fri, 7 Sep 2018 18:27:38 +0000 (20:27 +0200)
I did what needed to be done. I am not proud of it.

Bug: T203825
Change-Id: I57d6177cfb50641d8e085a48258e321e4d028712

resources/src/mediawiki.special.preferences/confirmClose.js

index bf65ae9..c092682 100644 (file)
                        // 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