From 03cf7863ec11cd0f74a4f83373b099759cfe4ee5 Mon Sep 17 00:00:00 2001 From: Abijeet Date: Fri, 4 Mar 2022 01:17:41 +0530 Subject: [PATCH] Stop propagating first click handler when loading languagesettings The languagesettings dialog does not open when clicking the uls.trigger for the first time. This issue occurs when the user is not logged in, ULSPosition is personal, and ULSAnonCanChangeLanguage is false. Without this change, the following happens: * uls.languagesettings is loaded via uls.interface * uls.languagesettings::hide is called via uls.languagesettings::init * click method is triggered immediately via script in uls.interface * uls.languagesettings::show is called * uls.languagesettings::hide is called - triggered via ::show method - $( document.documentElement ).trigger( 'click' ); but dialog is not visible yet, so this does nothing * uls.languagesettings::show displays the uls.languagesettings * hide method called again via click handler for documentElement With this change in place the hide method is not called again due to e.stopPropagation(); Additionally add a parameter autoOpen that can be set to open the dialog automatically. Bug: T301882 Change-Id: I54e8172ae017c4a9c6ab5b841d9328b2f24f97a8 --- resources/js/ext.uls.interface.js | 9 ++++++--- resources/js/ext.uls.languagesettings.js | 7 ++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/resources/js/ext.uls.interface.js b/resources/js/ext.uls.interface.js index 0cfbb8e1..3234596c 100644 --- a/resources/js/ext.uls.interface.js +++ b/resources/js/ext.uls.interface.js @@ -329,10 +329,13 @@ } } else { mw.loader.using( languageSettingsModules, function () { - $trigger.languagesettings(); - - $trigger.trigger( 'click' ); + $trigger.languagesettings( { autoOpen: true } ); + mw.hook( 'mw.uls.settings.open' ).fire( 'personal' ); } ); + // Stop propagating the event to avoid closing the languagesettings dialog + // when the event propagates to the document click handler inside + // languagesettings + e.stopPropagation(); } }; } else { diff --git a/resources/js/ext.uls.languagesettings.js b/resources/js/ext.uls.languagesettings.js index 064dbff9..b7acf5f9 100644 --- a/resources/js/ext.uls.languagesettings.js +++ b/resources/js/ext.uls.languagesettings.js @@ -63,6 +63,10 @@ this.$applyButton = this.$window.find( '.uls-settings-apply' ); this.init(); this.listen(); + + if ( options.autoOpen ) { + this.show(); + } } LanguageSettings.prototype = { @@ -318,7 +322,8 @@ top: null, // DEPRECATED: Top position of this window left: null, // DEPRECATED: Left position of this window onVisible: null, // A callback that runs after the ULS panel becomes visible - onPosition: null // A callback that allows positioning the dialog + onPosition: null, // A callback that allows positioning the dialog, + autoOpen: false // A boolean that determines if dialog should auto-open after initialization }; $.fn.languagesettings.Constructor = LanguageSettings;