File indexing completed on 2024-05-05 03:41:03
0001 /*! 0002 * SPDX-License-Identifier: MIT 0003 */ 0004 0005 (function() {//switch: v1.2 0006 "use strict"; 0007 0008 // NOTE: enable more languages in dropbox selector from HTML target by disabling corresponding lines. 0009 // English is always enabled and must be the first on the list. For the rest, respect alphabetic order. 0010 // The language code can be found in this wikipedia page: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes 0011 // The description of language code must encode special character using entity reference for HTML: https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references 0012 // Other languages must be listed in locale/ sub-directory from root directory of this git repository. 0013 // All changes from this list must be also applied to the docs-digikam-org section from the JSON config file in binary-factory-tooling repository 0014 // https://invent.kde.org/sysadmin/binary-factory-tooling/-/blob/master/staticweb/custom-jobs.json 0015 // supporte_languages array in 404handler.php file from this repository needs to be also updated. 0016 var all_langs = { 0017 "en": "English", 0018 //"ar": "اَلْعَرَبِيَّةُ", 0019 "ca": "Català", 0020 "cs": "Čeština", 0021 //"da": "dansk", 0022 "de": "Deutsch", 0023 "es": "Español", 0024 //"et": "Eesti" 0025 "fi": "Suomeksi", 0026 "fr": "Français", 0027 //"id": "Bahasa Indonesia", 0028 "it": "Italiano", 0029 "ja": "日本語", 0030 //"ko": "한국어", 0031 //"nb": "Norsk Bokmål", 0032 "lt": "Lietuvių kalba", 0033 "nl": "Nederlands", 0034 //"pl": "Polski", 0035 //"pt_BR": "Português (Brazil)", 0036 "pt_PT": "Português", 0037 //"ru": "Ρусский", 0038 "sk": "Slovenčina", 0039 "sl": "Slovenščina", 0040 //"sr": "српски", 0041 //"sv": "Svenska", 0042 //"tr": "Türkçe", 0043 "uk_UA": "Українська", 0044 //"vi": "Tiếng Việt", 0045 "zh_CN": "中文(简体)", 0046 //"zh_TW": "中文(繁體)", 0047 }; 0048 0049 var Popover=function(){ 0050 function Popover(id){ 0051 this.isOpen=false; 0052 this.$btn = $('#' + id); 0053 this.$dialog = this.$btn.next(); 0054 this.$list = this.$dialog.children("ul"); 0055 this.sel = null; 0056 this.beforeInit(); 0057 } 0058 0059 Popover.prototype={ 0060 beforeInit: function() { 0061 var that=this; 0062 this.$btn.on("click", function(e){that.init();e.preventDefault();e.stopPropagation();}); 0063 this.$btn.on("keydown", function(e) { if(that.btnKeyFilter(e)){that.init();e.preventDefault();e.stopPropagation();} }); 0064 }, 0065 init: function() { 0066 this.$btn.off("click"); 0067 this.$btn.off("keydown"); 0068 0069 this.afterLoad(); 0070 }, 0071 afterLoad: function() { 0072 var release = DOCUMENTATION_OPTIONS.VERSION; 0073 const m = release.match(/\d\.\d+/g); 0074 if (m) {release = m[0];} 0075 var lang = DOCUMENTATION_OPTIONS.LANGUAGE; 0076 if(!lang || lang === "None" || lang === "") {lang = "en";} 0077 0078 var list = this.buildList(lang); 0079 0080 this.$list.children(":first-child").remove(); 0081 this.$list.append(list); 0082 var that = this; 0083 this.$list.on("keydown", function(e) {that.keyMove(e);}); 0084 0085 this.$btn.removeClass("wait"); 0086 this.btnOpenHandler(); 0087 this.$btn.on("mousedown", function(e){that.btnOpenHandler(); e.preventDefault()}); 0088 this.$btn.on("keydown", function(e){ if(that.btnKeyFilter(e)){that.btnOpenHandler();} }); 0089 }, 0090 buildList: function(l) { 0091 var url = new URL(window.location.href); 0092 let pathSplit = ["", l, url.pathname.split('/').slice(2).join('/')]; 0093 var dyn = all_langs; 0094 var cur = l; 0095 var buf = []; 0096 var that=this; 0097 $.each(dyn, function(ix, title) { 0098 buf.push("<li"); 0099 if (ix === cur) { 0100 buf.push(' class="selected" tabindex="-1" role="presentation"><span tabindex="-1" role="menuitem" aria-current="page">' + title + '</spanp></li>'); 0101 } else { 0102 pathSplit[1] = ix; 0103 var href = new URL(url); 0104 href.pathname = pathSplit.join('/'); 0105 buf.push(' tabindex="-1" role="presentation"><a href ="' + href + '" tabindex="-1">' + title + '</a></li>'); 0106 } 0107 }); 0108 return buf.join(''); 0109 }, 0110 dialogToggle: function(speed) { 0111 var wasClose = !this.isOpen; 0112 var that=this; 0113 if(!this.isOpen) { 0114 this.$btn.addClass("version-btn-open"); 0115 this.$btn.attr("aria-pressed", true); 0116 this.$dialog.attr("aria-hidden", false); 0117 this.$dialog.fadeIn(speed, function() { 0118 that.$btn.parent().on("focusout", function(e) {that.focusoutHandler(); e.stopImmediatePropagation();}) 0119 that.$btn.parent().on("mouseleave", function(e){that.mouseoutHandler(); e.stopImmediatePropagation();}); 0120 }); 0121 this.isOpen = true; 0122 } else { 0123 this.$btn.removeClass("version-btn-open"); 0124 this.$btn.attr("aria-pressed", false); 0125 this.$dialog.attr("aria-hidden", true); 0126 this.$btn.parent().off("focusout"); 0127 this.$btn.parent().off("mouseleave"); 0128 this.$dialog.fadeOut(speed, function() { 0129 if (this.$sel) {this.$sel.attr("tabindex", -1);} 0130 that.$btn.attr("tabindex", 0); 0131 if(document.activeElement !== null && document.activeElement !== document && document.activeElement !== document.body) { 0132 that.$btn.focus(); 0133 } 0134 }); 0135 this.isOpen = false; 0136 } 0137 0138 if(wasClose) { 0139 if (this.$sel) {this.$sel.attr("tabindex", -1);} 0140 if(document.activeElement !== null && document.activeElement !== document && document.activeElement !== document.body) { 0141 var $nw = this.listEnter(); 0142 $nw.attr("tabindex", 0); 0143 $nw.focus(); 0144 this.$sel = $nw; 0145 } 0146 } 0147 }, 0148 btnOpenHandler: function() { 0149 this.dialogToggle(300); 0150 }, 0151 focusoutHandler: function() { 0152 var list = this.$list; 0153 var that = this; 0154 setTimeout(function() { 0155 if (list.find(":focus").length === 0) { 0156 that.dialogToggle(200); 0157 } 0158 }, 200); 0159 }, 0160 mouseoutHandler: function() { 0161 this.dialogToggle(200); 0162 }, 0163 btnKeyFilter: function(e) { 0164 if (e.ctrlKey || e.shiftKey) {return false;} 0165 if(e.key === " " || e.key === "Enter" || (e.key === "ArrowDown" && e.altKey) || e.key === "ArrowDown" || e.key === "ArrowUp") { 0166 return true; 0167 } 0168 return false; 0169 }, 0170 keyMove: function(e) { 0171 if (e.ctrlKey || e.shiftKey) {return true;} 0172 var p = true; 0173 var $nw = $(e.target); 0174 switch(e.key) { 0175 case "ArrowUp": $nw = this.listPrev($nw); break; 0176 case "ArrowDown": $nw = this.listNext($nw); break; 0177 case "Home": $nw = this.listFirst(); break; 0178 case "End": $nw = this.listLast(); break; 0179 case "Escape": $nw = this.listExit(); break; 0180 case "ArrowLeft": $nw = this.listExit(); break; 0181 case "ArrowRight": $nw = this.listExit(); break; 0182 default: p = false; 0183 } 0184 if(p) { 0185 $nw.attr("tabindex", 0); 0186 $nw.focus(); 0187 if (this.$sel) {this.$sel.attr("tabindex", -1);} 0188 this.$sel = $nw; 0189 e.preventDefault(); 0190 e.stopPropagation(); 0191 } 0192 }, 0193 listPrev: function($nw) { 0194 if ($nw.parent().prev().length !== 0) { 0195 return $nw.parent().prev().children(":first-child"); 0196 } else { 0197 return this.listLast(); 0198 } 0199 }, 0200 listNext: function($nw) { 0201 if ($nw.parent().next().length !== 0) { 0202 return $nw.parent().next().children(":first-child"); 0203 } else { 0204 return this.listFirst(); 0205 } 0206 }, 0207 listFirst: function() { 0208 return this.$list.children(":first-child").children(":first-child"); 0209 }, 0210 listLast: function() { 0211 return this.$list.children(":last-child").children(":first-child"); 0212 }, 0213 listExit: function() { 0214 this.mouseoutHandler(); 0215 return this.$btn; 0216 }, 0217 listEnter: function() { 0218 return this.$list.children(":first-child").children(":first-child"); 0219 } 0220 }; 0221 return Popover}(); 0222 0223 $(document).ready(function() { 0224 var lang = DOCUMENTATION_OPTIONS.LANGUAGE; 0225 if(!lang || lang === "None") {lang = "en";} 0226 if(all_langs.hasOwnProperty(lang)) {$("#lang-popover").html(all_langs[lang]);} 0227 var lng_popover=new Popover("version-popover"); 0228 var vsn_popover=new Popover("lang-popover"); 0229 }); 0230 })();