Update tag.html

This commit is contained in:
Meekdai 2023-11-22 09:15:12 +08:00
parent 547d4137de
commit 656c97bc03

View File

@ -78,10 +78,11 @@ request.send();
request.onload=function(){
jsonData=JSON.parse(request.response);
console.log(jsonData);
showList(window.location.hash.slice(1));
showList();
setClassDisplay(decodeURI(window.location.hash.slice(1)));
}
function showList(tag){
function showList(){
let SideNav=document.getElementsByClassName("SideNav")[0];
let tagLable=document.getElementById("tagLable");
for(i in jsonData["postListJson"]){
@ -96,9 +97,9 @@ function showList(tag){
tagLable.appendChild(showLabels);
}
if(encodeURI(jsonData["postListJson"][i]['label'])==tag || tag==''){
// if(encodeURI(jsonData["postListJson"][i]['label'])==tag || tag==''){
let item=document.createElement("a");
item.setAttribute("class","SideNav-item d-flex flex-items-center flex-justify-between");
item.setAttribute("class","SideNav-item d-flex flex-items-center flex-justify-between "+jsonData["postListJson"][i]['label']);
item.setAttribute("href",jsonData["postListJson"][i]['postUrl']);
let center=document.createElement("div");
@ -134,17 +135,29 @@ function showList(tag){
item.appendChild(center);
item.appendChild(listLabels);
SideNav.appendChild(item);
}
// }
}
}
function updateShowTag(label){
if(window.location.hash.slice(1)!=encodeURI(label)){
window.location.hash="#"+(label);
showList(label);
setClassDisplay(label);
console.log("change to "+label);
}
}
function setClassDisplay(lable) {
let SideNav = document.getElementsByClassName("SideNav-item");
for(let i = 0; i < SideNav.length; i++){
SideNav[i].style.display='none';
}
let lables = document.getElementsByClassName(lable);
for(let i = 0; i < lables.length; i++){
lables[i].style.display='block';
}
}
</script>
{% endblock %}