1
0
Fork 0
mirror of synced 2024-07-04 22:20:45 +12:00
appwrite/public/scripts/views/ui/highlight.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

(function(window) {
window.ls.container.get("view").add({
selector: "data-ui-highlight",
controller: function(element, expression, document) {
let check = function() {
let links = element.getElementsByTagName("a");
let selected = null;
let list = [];
2019-05-09 18:54:39 +12:00
for (let i = 0; i < links.length; i++) {
links[i].href =
links[i].href || expression.parse(links[i].dataset["lsHref"] || "");
list.push(links[i]);
}
2019-05-09 18:54:39 +12:00
list.sort(function(a, b) {
return a.pathname.length - b.pathname.length;
});
2019-05-09 18:54:39 +12:00
for (let i = 0; i < list.length; i++) {
if (
list[i].pathname ===
window.location.pathname.substring(0, list[i].pathname.length)
) {
list[i].classList.add("selected");
2019-05-09 18:54:39 +12:00
if (selected !== null) {
list[selected].classList.remove("selected");
}
selected = i;
} else {
list[i].classList.remove("selected");
}
}
};
2019-05-09 18:54:39 +12:00
document.addEventListener("state-changed", check);
2019-05-09 18:54:39 +12:00
check();
}
});
})(window);