});
+mkws.registerWidgetType('Lang', function() {
+ // dynamic URL or static page? /path/foo?query=test
+ /* create locale language menu */
+ if (!this.config.show_lang) return;
+
+ var lang_default = "en";
+ var lang = this.config.lang || lang_default;
+ var list = [];
+
+ /* display a list of configured languages, or all */
+ var lang_options = this.config.lang_options || [];
+ var toBeIncluded = {};
+ for (var i = 0; i < lang_options.length; i++) {
+ toBeIncluded[lang_options[i]] = true;
+ }
+
+ for (var k in mkws.locale_lang) {
+ if (toBeIncluded[k] || lang_options.length == 0)
+ list.push(k);
+ }
+
+ // add english link
+ if (lang_options.length == 0 || toBeIncluded[lang_default])
+ list.push(lang_default);
+
+ this.log("Language menu for: " + list.join(", "));
+
+ /* the HTML part */
+ var data = "";
+ for (var i = 0; i < list.length; i++) {
+ var l = list[i];
+ if (data)
+ data += ' | ';
+
+ if (lang == l) {
+ data += ' <span>' + l + '</span> ';
+ } else {
+ data += ' <a href="' + lang_url(l) + '">' + l + '</a> '
+ }
+ }
+
+ $(this.node).html(data);
+
+
+ // set or re-set "lang" URL parameter
+ function lang_url(lang) {
+ var query = location.search;
+ // no query parameters? done
+ if (!query) {
+ return "?lang=" + lang;
+ }
+
+ // parameter does not exist
+ if (!query.match(/[\?&]lang=/)) {
+ return query + "&lang=" + lang;
+ }
+
+ // replace existing parameter
+ query = query.replace(/\?lang=([^&#;]*)/, "?lang=" + lang);
+ query = query.replace(/\&lang=([^&#;]*)/, "&lang=" + lang);
+ return query;
+ }
+});