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
This commit is contained in:
Abijeet
2022-03-04 01:17:41 +05:30
committed by jenkins-bot
parent 4385fbf157
commit 03cf7863ec
2 changed files with 12 additions and 4 deletions

View File

@@ -329,10 +329,13 @@
} }
} else { } else {
mw.loader.using( languageSettingsModules, function () { mw.loader.using( languageSettingsModules, function () {
$trigger.languagesettings(); $trigger.languagesettings( { autoOpen: true } );
mw.hook( 'mw.uls.settings.open' ).fire( 'personal' );
$trigger.trigger( 'click' );
} ); } );
// Stop propagating the event to avoid closing the languagesettings dialog
// when the event propagates to the document click handler inside
// languagesettings
e.stopPropagation();
} }
}; };
} else { } else {

View File

@@ -63,6 +63,10 @@
this.$applyButton = this.$window.find( '.uls-settings-apply' ); this.$applyButton = this.$window.find( '.uls-settings-apply' );
this.init(); this.init();
this.listen(); this.listen();
if ( options.autoOpen ) {
this.show();
}
} }
LanguageSettings.prototype = { LanguageSettings.prototype = {
@@ -318,7 +322,8 @@
top: null, // DEPRECATED: Top position of this window top: null, // DEPRECATED: Top position of this window
left: null, // DEPRECATED: Left position of this window left: null, // DEPRECATED: Left position of this window
onVisible: null, // A callback that runs after the ULS panel becomes visible 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; $.fn.languagesettings.Constructor = LanguageSettings;