51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
|
window.onload = function () {
|
||
|
catList = document.getElementById("categories_list")
|
||
|
categories = sortCategories(global_categories)
|
||
|
for(var key in categories) {
|
||
|
var a = document.createElement("a")
|
||
|
var li = document.createElement("li")
|
||
|
li.setAttribute("role", "presentation")
|
||
|
li.addEventListener("click", function(){fillSubCategorie(this.children[0].text); setDropdownText(this)})
|
||
|
a.setAttribute("role", "menuitem")
|
||
|
a.tabIndex = "-1"
|
||
|
a.href = "#"
|
||
|
a.innerHTML = getLocalString("english", categories[key])
|
||
|
li.appendChild(a)
|
||
|
catList.appendChild(li)
|
||
|
a = undefined
|
||
|
li = undefined
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function sortCategories(categories) {
|
||
|
var sortedCategories = []
|
||
|
for(var key in categories) {
|
||
|
sortedCategories.push(key)
|
||
|
}
|
||
|
sortedCategories.sort()
|
||
|
return sortedCategories
|
||
|
}
|
||
|
|
||
|
function setDropdownText(liElement) {
|
||
|
liElement.parentNode.parentNode.childNodes[1].childNodes[0].textContent = liElement.children[0].text + " "
|
||
|
}
|
||
|
|
||
|
function fillSubCategorie(categorie) {
|
||
|
subCategory = getDescriptorByLocalString("english", categorie)
|
||
|
catList = document.getElementById("subcategory_list")
|
||
|
catList.innerHTML = ""
|
||
|
categories = global_categories[subCategory].sort()
|
||
|
for(var key in categories) {
|
||
|
var a = document.createElement("a")
|
||
|
var li = document.createElement("li")
|
||
|
li.setAttribute("role", "presentation")
|
||
|
li.addEventListener("click", function(){setDropdownText(this)})
|
||
|
a.setAttribute("role", "menuitem")
|
||
|
a.tabIndex = "-1"
|
||
|
a.href = "#"
|
||
|
a.innerHTML = getLocalString("english", categories[key])
|
||
|
li.appendChild(a)
|
||
|
catList.appendChild(li)
|
||
|
}
|
||
|
}
|