From ddb691a91814fa1f98dfbffbcb6d30d8815a3583 Mon Sep 17 00:00:00 2001 From: Amire80 Date: Sun, 4 Mar 2018 23:01:35 +0200 Subject: [PATCH] Allow identifying the context of the different ULS panels within one app Add the ulsPurpose option. Empty string by default. This is useful for web application that use ULS in several different context, and need to distinguish what was the purpose of the particular ULS panel. An example of usage can be found at https://phabricator.wikimedia.org/T179402 --- src/jquery.uls.core.js | 5 +++++ src/jquery.uls.languagefilter.js | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/jquery.uls.core.js b/src/jquery.uls.core.js index 36f30a5..98e1c76 100644 --- a/src/jquery.uls.core.js +++ b/src/jquery.uls.core.js @@ -54,6 +54,7 @@ this.$element = $( element ); this.options = $.extend( {}, $.fn.uls.defaults, options ); this.$menu = $( template ); + this.$menu.data( 'uls-purpose', this.options.ulsPurpose ); this.languages = this.options.languages; for ( code in this.languages ) { @@ -393,6 +394,10 @@ // The options are wide (4 columns), medium (2 columns), and narrow (1 column). // If not specified, it will be set automatically. menuWidth: undefined, + // What is this ULS used for. + // Should be set for distinguishing between different instances of ULS + // in the same application. + ulsPurpose: '', // Used by LCD quickList: [], // Used by LCD diff --git a/src/jquery.uls.languagefilter.js b/src/jquery.uls.languagefilter.js index edaa0e7..3a5e0af 100644 --- a/src/jquery.uls.languagefilter.js +++ b/src/jquery.uls.languagefilter.js @@ -233,7 +233,11 @@ resultHandler: function ( query, results, autofillLabel ) { if ( results.length === 0 ) { this.$suggestion.val( '' ); - this.$element.trigger( 'noresults.uls', query ); + this.$element.trigger( + 'noresults.uls', + query, + this.$element.parents( '.uls-menu' ).data( 'uls-purpose' ) + ); return; }