Common.js: Difference between revisions
From WhereToday
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
window.onload = function() { | |||
sortList("sortclasses","A"); | |||
}; | |||
function sortList(id,tag) { | |||
var list, i, seq, switching, b, shouldSwitch; | |||
list = document.getElementById(id); | |||
switching = true; | |||
/* Make a loop that will continue until | |||
no switching has been done: */ | |||
while (switching) { | |||
// Start by saying: no switching is done: | |||
switching = false; | |||
b = list.getElementsByTagName(tag); | |||
// Loop through all list items: | |||
for (i = 0; i < (b.length - 1); i++) { | |||
// Start by saying there should be no switching: | |||
shouldSwitch = false; | |||
/* Check if the next item should | |||
switch place with the current item: */ | |||
if (b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase()) { | |||
/* if (b[i].id.toLowerCase() > b[i + 1].id.toLowerCase()) { */ | |||
/* If next item is alphabetically lower than current item, | |||
mark as a switch and break the loop: */ | |||
shouldSwitch = true; | |||
break; | |||
} | |||
} | |||
if (shouldSwitch) { | |||
/* If a switch has been marked, make the switch | |||
and mark the switch as done: */ | |||
/* hard coded to <a href, not sure how to copy structure */ | |||
t=b[i].innerHTML; | |||
b[i].innerHTML=b[i+1].innerHTML; | |||
b[i+1].innerHTML=t; | |||
t=b[i].href; | |||
b[i].href=b[i+1].href; | |||
b[i+1].href=t; | |||
t=b[i].title; | |||
b[i].title=b[i+1].title; | |||
b[i+1].title=t; | |||
switching = true; | |||
} | |||
} | |||
} | |||
function filterAll () { | function filterAll () { | ||
var input, filter, td, i, description, keywords, txtValue; | var input, filter, td, i, description, keywords, txtValue; | ||
var map = document.getElementsByClassName("leaflet-marker-icon"); | var map = document.getElementsByClassName("leaflet-marker-icon"); | ||
var | var items = document.getElementsByClassName("ItemLine"); | ||
var timeline = document.getElementsByClassName("TimelineLine"); | var timeline = document.getElementsByClassName("TimelineLine"); | ||
var gallery = document.getElementsByClassName("galleryline"); | var gallery = document.getElementsByClassName("galleryline"); | ||
var documents = document.getElementsByClassName(" | var documents = document.getElementsByClassName("DocumentLine"); | ||
var dplline = document.getElementsByClassName("DPLLine"); | |||
var table = document.getElementById("Table"); | var table = document.getElementById("Table"); | ||
if (table) | |||
if (table) {var tabletr = table.getElementsByTagName("tr")} | |||
if (document.getElementById("filterinput") !== null && document.getElementById("filterinput").value !== null) | if (document.getElementById("filterinput") !== null && document.getElementById("filterinput").value !== null) | ||
{ | { | ||
input = document.getElementById("filterinput"); | input = document.getElementById("filterinput"); | ||
filter = input.value.toUpperCase().replace( | filter = input.value.toUpperCase().replace(/_/g," "); | ||
filter1 = input.value.toUpperCase().replace( | filter1 = input.value.toUpperCase().replace(/ /g,"_"); | ||
if (filter.search("!") == 0) { | if (filter.search("!") == 0) { | ||
if (filter.length > 1) { | if (filter.length > 1) { | ||
Line 25: | Line 74: | ||
} | } | ||
} | } | ||
for (i = 0; i < | for (i = 0; i < items.length; i++) { | ||
if ( | if (items[i].id.toUpperCase().search(filter1.substr(1)) == -1) { | ||
items[i].style.display = 'inline-block'; | |||
} else { | } else { | ||
items[i].style.display = 'none'; | |||
} | } | ||
} | } | ||
Line 54: | Line 103: | ||
for (i = 0; i < documents.length; i++) { | for (i = 0; i < documents.length; i++) { | ||
if (documents[i].id.toUpperCase().search( | if (documents[i].id.toUpperCase().search(filter1.substr(1)) == -1) { | ||
documents[i].style.display = ''; | documents[i].style.display = ''; | ||
} else { | } else { | ||
documents[i].style.display = 'none'; | documents[i].style.display = 'none'; | ||
} | |||
} | |||
for (i = 0; i < dplline.length; i++) { | |||
if (dplline[i].id.toUpperCase().search(filter.substr(1)) == -1) { | |||
dplline[i].style.display = ''; | |||
} else { | |||
dplline[i].style.display = 'none'; | |||
} | } | ||
} | } | ||
Line 67: | Line 119: | ||
if (table) { | if (table) { | ||
for (i = 0; i < tabletr.length; i++) { | for (i = 0; i < tabletr.length; i++) { | ||
// match text in | // match text in all columns | ||
if (tabletr[i].getElementsByTagName("td")[0]) { | if (tabletr[i].getElementsByTagName("td")[0]) { | ||
txtValue = tabletr[i].getElementsByTagName("td")[0].textContent | txtValue = tabletr[i].getElementsByTagName("td")[0].textContent | ||
+ tabletr[i].getElementsByTagName("td")[1].textContent | + tabletr[i].getElementsByTagName("td")[1].textContent | ||
+ tabletr[i].getElementsByTagName("td")[2].textContent | + tabletr[i].getElementsByTagName("td")[2].textContent | ||
+ tabletr[i].getElementsByTagName("td")[3].textContent; | + tabletr[i].getElementsByTagName("td")[3].textContent | ||
+ tabletr[i].getElementsByTagName("td")[4].textContent | |||
+ tabletr[i].getElementsByTagName("td")[5].textContent; | |||
if (txtValue.toUpperCase().search(filter.substr(1)) == -1) { | if (txtValue.toUpperCase().search(filter.substr(1)) == -1) { | ||
tabletr[i].style.display = ""; | tabletr[i].style.display = ""; | ||
Line 90: | Line 144: | ||
} | } | ||
} | } | ||
for (i = 0; i < | for (i = 0; i < items.length; i++) { | ||
if ( | if (items[i].id.toUpperCase().search(filter1) > -1) { | ||
items[i].style.display = 'inline-block'; | |||
} else { | } else { | ||
items[i].style.display = 'none'; | |||
} | } | ||
} | } | ||
Line 119: | Line 173: | ||
for (i = 0; i < documents.length; i++) { | for (i = 0; i < documents.length; i++) { | ||
if (documents[i].id.toUpperCase().search( | if (documents[i].id.toUpperCase().search(filter1) > -1) { | ||
documents[i].style.display = ''; | documents[i].style.display = ''; | ||
} else { | } else { | ||
documents[i].style.display = 'none'; | documents[i].style.display = 'none'; | ||
} | |||
} | |||
for (i = 0; i < dplline.length; i++) { | |||
if (dplline[i].id.toUpperCase().search(filter) > -1) { | |||
dplline[i].style.display = ''; | |||
} else { | |||
dplline[i].style.display = 'none'; | |||
} | } | ||
} | } | ||
Line 132: | Line 190: | ||
if (table) { | if (table) { | ||
for (i = 0; i < tabletr.length; i++) { | for (i = 0; i < tabletr.length; i++) { | ||
// match text in | // match text in all columns | ||
if (tabletr[i].getElementsByTagName("td")[0]) { | if (tabletr[i].getElementsByTagName("td")[0]) { | ||
txtValue = tabletr[i].getElementsByTagName("td")[0].textContent | txtValue = tabletr[i].getElementsByTagName("td")[0].textContent | ||
+ tabletr[i].getElementsByTagName("td")[1].textContent | + tabletr[i].getElementsByTagName("td")[1].textContent | ||
+ tabletr[i].getElementsByTagName("td")[2].textContent | + tabletr[i].getElementsByTagName("td")[2].textContent | ||
+ tabletr[i].getElementsByTagName("td")[3].textContent; | + tabletr[i].getElementsByTagName("td")[3].textContent | ||
+ tabletr[i].getElementsByTagName("td")[4].textContent | |||
+ tabletr[i].getElementsByTagName("td")[5].textContent; | |||
if (txtValue !== "" && txtValue.toUpperCase().search(filter) > -1) { | if (txtValue !== "" && txtValue.toUpperCase().search(filter) > -1) { | ||
tabletr[i].style.display = ""; | tabletr[i].style.display = ""; |
Latest revision as of 09:45, 3 August 2024
/* Any JavaScript here will be loaded for all users on every page load. */ window.onload = function() { sortList("sortclasses","A"); }; function sortList(id,tag) { var list, i, seq, switching, b, shouldSwitch; list = document.getElementById(id); switching = true; /* Make a loop that will continue until no switching has been done: */ while (switching) { // Start by saying: no switching is done: switching = false; b = list.getElementsByTagName(tag); // Loop through all list items: for (i = 0; i < (b.length - 1); i++) { // Start by saying there should be no switching: shouldSwitch = false; /* Check if the next item should switch place with the current item: */ if (b[i].innerHTML.toLowerCase() > b[i + 1].innerHTML.toLowerCase()) { /* if (b[i].id.toLowerCase() > b[i + 1].id.toLowerCase()) { */ /* If next item is alphabetically lower than current item, mark as a switch and break the loop: */ shouldSwitch = true; break; } } if (shouldSwitch) { /* If a switch has been marked, make the switch and mark the switch as done: */ /* hard coded to <a href, not sure how to copy structure */ t=b[i].innerHTML; b[i].innerHTML=b[i+1].innerHTML; b[i+1].innerHTML=t; t=b[i].href; b[i].href=b[i+1].href; b[i+1].href=t; t=b[i].title; b[i].title=b[i+1].title; b[i+1].title=t; switching = true; } } } function filterAll () { var input, filter, td, i, description, keywords, txtValue; var map = document.getElementsByClassName("leaflet-marker-icon"); var items = document.getElementsByClassName("ItemLine"); var timeline = document.getElementsByClassName("TimelineLine"); var gallery = document.getElementsByClassName("galleryline"); var documents = document.getElementsByClassName("DocumentLine"); var dplline = document.getElementsByClassName("DPLLine"); var table = document.getElementById("Table"); if (table) {var tabletr = table.getElementsByTagName("tr")} if (document.getElementById("filterinput") !== null && document.getElementById("filterinput").value !== null) { input = document.getElementById("filterinput"); filter = input.value.toUpperCase().replace(/_/g," "); filter1 = input.value.toUpperCase().replace(/ /g,"_"); if (filter.search("!") == 0) { if (filter.length > 1) { for (i = 0; i < map.length; i++) { if (map[i].id !== "" && map[i].id.toUpperCase().search(filter.substr(1)) == -1) { map[i].style.opacity="1.0"; } else { map[i].style.opacity="0.05"; } } for (i = 0; i < items.length; i++) { if (items[i].id.toUpperCase().search(filter1.substr(1)) == -1) { items[i].style.display = 'inline-block'; } else { items[i].style.display = 'none'; } } for (i = 0; i < timeline.length; i++) { if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1.substr(1)) == -1) { timeline[i].style.opacity="1.0"; } else { timeline[i].style.opacity="0.1"; } } for (i = 0; i < gallery.length; i++) { if (gallery[i].id.toUpperCase().search(filter.substr(1)) == -1) { gallery[i].style.display = ''; text=gallery[i].innerHTML; gallery[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'gallery"); } else { gallery[i].style.display = 'none'; text=gallery[i].innerHTML; gallery[i].innerHTML = text.replace(/slideshowGroup:'gallery/,"slideshowGroup:'exclude"); } } for (i = 0; i < documents.length; i++) { if (documents[i].id.toUpperCase().search(filter1.substr(1)) == -1) { documents[i].style.display = ''; } else { documents[i].style.display = 'none'; } } for (i = 0; i < dplline.length; i++) { if (dplline[i].id.toUpperCase().search(filter.substr(1)) == -1) { dplline[i].style.display = ''; } else { dplline[i].style.display = 'none'; } } if (table) { for (i = 0; i < tabletr.length; i++) { // match text in all columns if (tabletr[i].getElementsByTagName("td")[0]) { txtValue = tabletr[i].getElementsByTagName("td")[0].textContent + tabletr[i].getElementsByTagName("td")[1].textContent + tabletr[i].getElementsByTagName("td")[2].textContent + tabletr[i].getElementsByTagName("td")[3].textContent + tabletr[i].getElementsByTagName("td")[4].textContent + tabletr[i].getElementsByTagName("td")[5].textContent; if (txtValue.toUpperCase().search(filter.substr(1)) == -1) { tabletr[i].style.display = ""; } else { tabletr[i].style.display = "none"; } } } } } } else { for (i = 0; i < map.length; i++) { if (map[i].id !== "" && map[i].id.toUpperCase().search(filter) > -1) { map[i].style.opacity="1.0"; } else { map[i].style.opacity="0.05"; } } for (i = 0; i < items.length; i++) { if (items[i].id.toUpperCase().search(filter1) > -1) { items[i].style.display = 'inline-block'; } else { items[i].style.display = 'none'; } } for (i = 0; i < timeline.length; i++) { if (timeline[i].id !== "" && timeline[i].id.toUpperCase().search(filter1) > -1) { timeline[i].style.opacity="1.0"; } else { timeline[i].style.opacity="0.1"; } } for (i = 0; i < gallery.length; i++) { if (gallery[i].id.toUpperCase().search(filter) > -1) { gallery[i].style.display = ''; text=gallery[i].innerHTML; gallery[i].innerHTML = text.replace(/slideshowGroup:'exclude/,"slideshowGroup:'gallery"); } else { gallery[i].style.display = 'none'; text=gallery[i].innerHTML; gallery[i].innerHTML = text.replace(/slideshowGroup:'gallery/,"slideshowGroup:'exclude"); } } for (i = 0; i < documents.length; i++) { if (documents[i].id.toUpperCase().search(filter1) > -1) { documents[i].style.display = ''; } else { documents[i].style.display = 'none'; } } for (i = 0; i < dplline.length; i++) { if (dplline[i].id.toUpperCase().search(filter) > -1) { dplline[i].style.display = ''; } else { dplline[i].style.display = 'none'; } } if (table) { for (i = 0; i < tabletr.length; i++) { // match text in all columns if (tabletr[i].getElementsByTagName("td")[0]) { txtValue = tabletr[i].getElementsByTagName("td")[0].textContent + tabletr[i].getElementsByTagName("td")[1].textContent + tabletr[i].getElementsByTagName("td")[2].textContent + tabletr[i].getElementsByTagName("td")[3].textContent + tabletr[i].getElementsByTagName("td")[4].textContent + tabletr[i].getElementsByTagName("td")[5].textContent; if (txtValue !== "" && txtValue.toUpperCase().search(filter) > -1) { tabletr[i].style.display = ""; } else { tabletr[i].style.display = "none"; } } } } } } } $('#filterbox').html('<input type="text" id="filterinput" onkeyup="filterAll()" value="" placeholder="Filter" title="Filter">');