jenkins-bot has submitted this change and it was merged.

Change subject: Allow language widget to filter on available languages
......................................................................


Allow language widget to filter on available languages

Use this in the demo to only show languages we have json files for.

Change-Id: Ia094e55d854f50af8b1831815d9cc1891753542e
---
M .docs/eg-iframe.html
M build/tasks/buildloader.js
M demos/ve/demo.js
M demos/ve/desktop-dist.html
M demos/ve/desktop.html
M demos/ve/mobile-dist.html
M demos/ve/mobile.html
M src/ui/dialogs/ve.ui.LanguageSearchDialog.js
M src/ui/widgets/ve.ui.LanguageInputWidget.js
M src/ui/widgets/ve.ui.LanguageSearchWidget.js
10 files changed, 57 insertions(+), 4 deletions(-)

Approvals:
  Jforrester: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/.docs/eg-iframe.html b/.docs/eg-iframe.html
index c6170a1..7a97533 100644
--- a/.docs/eg-iframe.html
+++ b/.docs/eg-iframe.html
@@ -353,6 +353,7 @@
                <script>
                        ve.init.platform.addMessagePath( '../i18n/' );
                        ve.init.platform.addMessagePath( '../lib/oojs-ui/i18n/' 
);
+                       ve.availableLanguages = 
["ace","af","am","ar","arc","arq","as","ast","av","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en-gb","en","eo","es","et","eu","fa","fi","fo","fr","frp","frr","fur","fy","ga","gd","gl","gsw","gu","gv","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kri","ksh","kw","ky","lb","lez","lmo","lrc","lt","lv","lzh","lzz","mg","min","mk","ml","mn","mr","ms","mt","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","os","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","rm","ro","roa-tara","ru","rue","sah","sc","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","tzm","ug-arab","uk","ur","uz","vec","vi","vo","wuu","yi","yue","zh-hans","zh-hant","ace","af","am","ar","arc","arq","ast","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","crh-cyrl","crh-latn","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en","eo","es","et","eu","fa","fi","fo","fr","frr","fur","fy","gd","gl","gu","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kw","ky","lb","lmo","lt","lv","lzh","mg","min","mk","ml","mr","ms","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","ro","roa-tara","ru","sah","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","ug-arab","uk","uz","vec","vi","vo","wuu","yi","yo","yue","zh-hans","zh-hant"];
                </script>
 
                <!-- example scripts -->
diff --git a/build/tasks/buildloader.js b/build/tasks/buildloader.js
index ce41d2b..bea7dd4 100644
--- a/build/tasks/buildloader.js
+++ b/build/tasks/buildloader.js
@@ -96,6 +96,15 @@
                        for ( i = 0, len = i18n.length; i < len; i++ ) {
                                i18nScript += indent + 
'\tve.init.platform.addMessagePath( \'' + pathPrefix + i18n[i] + '\' );\n';
                        }
+                       i18nScript += indent + '\tve.availableLanguages = ' +
+                               JSON.stringify(
+                                       grunt.file.expand(
+                                               i18n.map( function ( path ) { 
return path + '*.json'; } )
+                                       ).map( function ( file ) {
+                                               return file.split( '/' 
).pop().slice( 0, -5 );
+                                       } )
+                               ) +
+                               ';\n';
                        i18nScript += indent + '</script>';
                        scripts.push( i18nScript );
                }
diff --git a/demos/ve/demo.js b/demos/ve/demo.js
index 363d1c9..5ffc6e8 100644
--- a/demos/ve/demo.js
+++ b/demos/ve/demo.js
@@ -50,8 +50,12 @@
                                new OO.ui.ButtonOptionWidget( { data: 'edit', 
label: 'Edit HTML' } ),
                                new OO.ui.ButtonOptionWidget( { data: 'read', 
label: 'Read' } )
                        ] ),
+                       messageKeyButton = new OO.ui.ButtonWidget( {
+                               label: 'Lang keys'
+                       } ),
                        languageInput = new ve.ui.LanguageInputWidget( {
                                requireDir: true,
+                               availableLanguages: ve.availableLanguages,
                                dialogManager: new OO.ui.WindowManager( { 
factory: ve.ui.windowFactory, classes: ['ve-demo-languageSearchDialogManager'] 
} )
                        } ),
                        sourceTextInput = new OO.ui.TextInputWidget( {
@@ -72,10 +76,16 @@
                        switchPage( 've', page );
                } );
 
+               messageKeyButton.on( 'click', function () {
+                       languageInput.setLangAndDir( 'qqx', currentDir );
+               } );
+
+               languageInput.languageCodeField.$element.hide();
+
                languageInput.setLangAndDir( currentLang, currentDir );
 
                languageInput.on( 'change', function ( lang, dir ) {
-                       if ( dir === currentDir && ve.indexOf( lang, 
ve.init.platform.getLanguageCodes() ) === -1 ) {
+                       if ( dir === currentDir && lang !== 'qqx' && 
ve.indexOf( lang, ve.availableLanguages ) === -1 ) {
                                return;
                        }
 
@@ -180,6 +190,7 @@
                                $( '<span 
class="ve-demo-menu-divider">&nbsp;</span>' ),
                                modeSelect.$element,
                                $( '<span 
class="ve-demo-menu-divider">&nbsp;</span>' ),
+                               messageKeyButton.$element,
                                languageInput.$element
                        )
                );
diff --git a/demos/ve/desktop-dist.html b/demos/ve/desktop-dist.html
index 2b37fce..ff983b9 100644
--- a/demos/ve/desktop-dist.html
+++ b/demos/ve/desktop-dist.html
@@ -86,6 +86,7 @@
                <script>
                        ve.init.platform.addMessagePath( '../../dist/i18n/' );
                        ve.init.platform.addMessagePath( 
'../../lib/oojs-ui/i18n/' );
+                       ve.availableLanguages = 
["ace","af","am","ar","arc","arq","as","ast","av","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en-gb","en","eo","es","et","eu","fa","fi","fo","fr","frp","frr","fur","fy","ga","gd","gl","gsw","gu","gv","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kri","ksh","kw","ky","lb","lez","lmo","lrc","lt","lv","lzh","lzz","mg","min","mk","ml","mn","mr","ms","mt","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","os","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","rm","ro","roa-tara","ru","rue","sah","sc","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","tzm","ug-arab","uk","ur","uz","vec","vi","vo","wuu","yi","yue","zh-hans","zh-hant","ace","af","am","ar","arc","arq","ast","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","crh-cyrl","crh-latn","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en","eo","es","et","eu","fa","fi","fo","fr","frr","fur","fy","gd","gl","gu","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kw","ky","lb","lmo","lt","lv","lzh","mg","min","mk","ml","mr","ms","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","ro","roa-tara","ru","sah","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","ug-arab","uk","uz","vec","vi","vo","wuu","yi","yo","yue","zh-hans","zh-hant"];
                </script>
 
                <script>
diff --git a/demos/ve/desktop.html b/demos/ve/desktop.html
index 31e8a72..889276b 100644
--- a/demos/ve/desktop.html
+++ b/demos/ve/desktop.html
@@ -372,6 +372,7 @@
                <script>
                        ve.init.platform.addMessagePath( '../../i18n/' );
                        ve.init.platform.addMessagePath( 
'../../lib/oojs-ui/i18n/' );
+                       ve.availableLanguages = 
["ace","af","am","ar","arc","arq","as","ast","av","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en-gb","en","eo","es","et","eu","fa","fi","fo","fr","frp","frr","fur","fy","ga","gd","gl","gsw","gu","gv","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kri","ksh","kw","ky","lb","lez","lmo","lrc","lt","lv","lzh","lzz","mg","min","mk","ml","mn","mr","ms","mt","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","os","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","rm","ro","roa-tara","ru","rue","sah","sc","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","tzm","ug-arab","uk","ur","uz","vec","vi","vo","wuu","yi","yue","zh-hans","zh-hant","ace","af","am","ar","arc","arq","ast","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","crh-cyrl","crh-latn","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en","eo","es","et","eu","fa","fi","fo","fr","frr","fur","fy","gd","gl","gu","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kw","ky","lb","lmo","lt","lv","lzh","mg","min","mk","ml","mr","ms","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","ro","roa-tara","ru","sah","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","ug-arab","uk","uz","vec","vi","vo","wuu","yi","yo","yue","zh-hans","zh-hant"];
                </script>
 
                <script>
diff --git a/demos/ve/mobile-dist.html b/demos/ve/mobile-dist.html
index 0bb36e4..1bc19ee 100644
--- a/demos/ve/mobile-dist.html
+++ b/demos/ve/mobile-dist.html
@@ -86,6 +86,7 @@
                <script>
                        ve.init.platform.addMessagePath( '../../dist/i18n/' );
                        ve.init.platform.addMessagePath( 
'../../lib/oojs-ui/i18n/' );
+                       ve.availableLanguages = 
["ace","af","am","ar","arc","arq","as","ast","av","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en-gb","en","eo","es","et","eu","fa","fi","fo","fr","frp","frr","fur","fy","ga","gd","gl","gsw","gu","gv","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kri","ksh","kw","ky","lb","lez","lmo","lrc","lt","lv","lzh","lzz","mg","min","mk","ml","mn","mr","ms","mt","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","os","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","rm","ro","roa-tara","ru","rue","sah","sc","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","tzm","ug-arab","uk","ur","uz","vec","vi","vo","wuu","yi","yue","zh-hans","zh-hant","ace","af","am","ar","arc","arq","ast","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","crh-cyrl","crh-latn","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en","eo","es","et","eu","fa","fi","fo","fr","frr","fur","fy","gd","gl","gu","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kw","ky","lb","lmo","lt","lv","lzh","mg","min","mk","ml","mr","ms","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","ro","roa-tara","ru","sah","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","ug-arab","uk","uz","vec","vi","vo","wuu","yi","yo","yue","zh-hans","zh-hant"];
                </script>
 
                <script>
diff --git a/demos/ve/mobile.html b/demos/ve/mobile.html
index 501b96b..2911cd8 100644
--- a/demos/ve/mobile.html
+++ b/demos/ve/mobile.html
@@ -374,6 +374,7 @@
                <script>
                        ve.init.platform.addMessagePath( '../../i18n/' );
                        ve.init.platform.addMessagePath( 
'../../lib/oojs-ui/i18n/' );
+                       ve.availableLanguages = 
["ace","af","am","ar","arc","arq","as","ast","av","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en-gb","en","eo","es","et","eu","fa","fi","fo","fr","frp","frr","fur","fy","ga","gd","gl","gsw","gu","gv","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kri","ksh","kw","ky","lb","lez","lmo","lrc","lt","lv","lzh","lzz","mg","min","mk","ml","mn","mr","ms","mt","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","os","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","rm","ro","roa-tara","ru","rue","sah","sc","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","tzm","ug-arab","uk","ur","uz","vec","vi","vo","wuu","yi","yue","zh-hans","zh-hant","ace","af","am","ar","arc","arq","ast","az","ba","bcc","bcl","be-tarask","be","bg","bn","br","bs","ca","ce","ckb","co","crh-cyrl","crh-latn","cs","cu","cy","da","de","diq","dsb","egl","el","eml","en","eo","es","et","eu","fa","fi","fo","fr","frr","fur","fy","gd","gl","gu","he","hi","hr","hsb","hu","hy","ia","id","ie","ilo","is","it","ja","jv","ka","kk-cyrl","km","kn","ko","krc","kw","ky","lb","lmo","lt","lv","lzh","mg","min","mk","ml","mr","ms","nap","nb","nds-nl","nds","ne","nl","nn","oc","om","or","pa","pfl","pl","pms","ps","pt-br","pt","qqq","qu","ro","roa-tara","ru","sah","scn","sco","sh","si","sk","sl","sq","sr-ec","sr-el","sv","sw","ta","te","tg-cyrl","th","tl","tr","tt-cyrl","ug-arab","uk","uz","vec","vi","vo","wuu","yi","yo","yue","zh-hans","zh-hant"];
                </script>
 
                <script>
diff --git a/src/ui/dialogs/ve.ui.LanguageSearchDialog.js 
b/src/ui/dialogs/ve.ui.LanguageSearchDialog.js
index d5c3ea3..143c5e0 100644
--- a/src/ui/dialogs/ve.ui.LanguageSearchDialog.js
+++ b/src/ui/dialogs/ve.ui.LanguageSearchDialog.js
@@ -79,6 +79,7 @@
 ve.ui.LanguageSearchDialog.prototype.getSetupProcess = function ( data ) {
        return ve.ui.LanguageSearchDialog.super.prototype.getSetupProcess.call( 
this, data )
                .next( function () {
+                       this.searchWidget.setAvailableLanguages( 
data.availableLanguages );
                        this.searchWidget.addResults();
                }, this );
 };
diff --git a/src/ui/widgets/ve.ui.LanguageInputWidget.js 
b/src/ui/widgets/ve.ui.LanguageInputWidget.js
index 37bf97c..cd5bf5d 100644
--- a/src/ui/widgets/ve.ui.LanguageInputWidget.js
+++ b/src/ui/widgets/ve.ui.LanguageInputWidget.js
@@ -14,6 +14,7 @@
  * @param {Object} [config] Configuration options
  * @cfg {boolean} [requireDir] Require directionality to be set (no 'auto' 
value)
  * @cfg {ve.ui.WindowManager} [dialogManager] Window manager to launch the 
language search dialog in
+ * @cfg {string[]} [availableLanguages] Available language codes to show in 
search dialog
  */
 ve.ui.LanguageInputWidget = function VeUiLanguageInputWidget( config ) {
        // Configuration initialization
@@ -27,6 +28,7 @@
        this.dir = null;
        this.overlay = new ve.ui.Overlay( { classes: ['ve-ui-overlay-global'] } 
);
        this.dialogs = config.dialogManager || new ve.ui.WindowManager( { 
factory: ve.ui.windowFactory, isolate: true } );
+       this.availableLanguages = config.availableLanguages;
        this.findLanguageButton = new OO.ui.ButtonWidget( {
                $: this.$,
                classes: [ 've-ui-languageInputWidget-findLanguageButton' ],
@@ -116,7 +118,7 @@
  */
 ve.ui.LanguageInputWidget.prototype.onFindLanguageButtonClick = function () {
        var widget = this;
-       this.dialogs.openWindow( 'languageSearch' )
+       this.dialogs.openWindow( 'languageSearch', { availableLanguages: 
this.availableLanguages } )
                .then( function ( opened ) {
                        opened.then( function ( closing ) {
                                closing.then( function ( data ) {
diff --git a/src/ui/widgets/ve.ui.LanguageSearchWidget.js 
b/src/ui/widgets/ve.ui.LanguageSearchWidget.js
index a358c9c..cb42ebf 100644
--- a/src/ui/widgets/ve.ui.LanguageSearchWidget.js
+++ b/src/ui/widgets/ve.ui.LanguageSearchWidget.js
@@ -24,6 +24,7 @@
 
        // Properties
        this.languageResultWidgets = [];
+       this.filteredLanguageResultWidgets = [];
 
        var i, l, languageCode,
                languageCodes = ve.init.platform.getLanguageCodes().sort();
@@ -41,6 +42,7 @@
                        } )
                );
        }
+       this.setAvailableLanguages();
 
        // Initialization
        this.$element.addClass( 've-ui-languageSearchWidget' );
@@ -64,6 +66,29 @@
 };
 
 /**
+ * Set available languages to show
+ *
+ * @param {string[]} Available language codes to show, all if undefined
+ */
+ve.ui.LanguageSearchWidget.prototype.setAvailableLanguages = function ( 
availableLanguages ) {
+       if ( !availableLanguages ) {
+               this.filteredLanguageResultWidgets = 
this.languageResultWidgets.slice();
+               return;
+       }
+       var i, iLen, languageResult, data;
+
+       this.filteredLanguageResultWidgets = [];
+
+       for ( i = 0, iLen = this.languageResultWidgets.length; i < iLen; i++ ) {
+               languageResult = this.languageResultWidgets[i];
+               data = languageResult.getData();
+               if ( ve.indexOf( data.code, availableLanguages ) !== -1 ) {
+                       this.filteredLanguageResultWidgets.push( languageResult 
);
+               }
+       }
+};
+
+/**
  * Update search results from current query
  */
 ve.ui.LanguageSearchWidget.prototype.addResults = function () {
@@ -76,8 +101,8 @@
 
        this.results.clearItems();
 
-       for ( i = 0, iLen = this.languageResultWidgets.length; i < iLen; i++ ) {
-               languageResult = this.languageResultWidgets[i];
+       for ( i = 0, iLen = this.filteredLanguageResultWidgets.length; i < 
iLen; i++ ) {
+               languageResult = this.filteredLanguageResultWidgets[i];
                data = languageResult.getData();
                matchedProperty = null;
 

-- 
To view, visit https://gerrit.wikimedia.org/r/177260
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ia094e55d854f50af8b1831815d9cc1891753542e
Gerrit-PatchSet: 1
Gerrit-Project: VisualEditor/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Esanders <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to