-
Notifications
You must be signed in to change notification settings - Fork 5
/
multisite-superlist.js
37 lines (34 loc) · 1.26 KB
/
multisite-superlist.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function siteSearchBox() {
const parentNode = document.querySelector(
"#wp-admin-bar-my-sites .ab-sub-wrapper"
)
const referenceNode = document.querySelector("#wp-admin-bar-my-sites-list")
const newNode = document.createElement("ul")
newNode.id = "search"
parentNode.insertBefore(newNode, referenceNode)
const search = document.createElement("li")
search.className = "search"
search.innerHTML =
'<div><input type="search" id="sites-search" name="sites-search" onkeyup="sitesFilter()" placeholder="Search"></div>'
newNode.appendChild(search)
}
siteSearchBox()
function sitesFilter() {
// Declare variables
var input, filter, ul, li, a, i, txtValue
input = document.querySelector("#sites-search")
filter = input.value.toUpperCase()
ul = document.querySelector("#wp-admin-bar-my-sites-list")
li = ul.querySelectorAll("li")
// Loop through all list items, and hide those who don't match the search query
for (i = 0; i < li.length; i++) {
a = li[i].getElementsByTagName("a")[0]
txtValue = a.innerText
if (txtValue.toUpperCase().indexOf(filter) > -1) {
li[i].style.display = ""
} else {
li[i].style.display = "none"
}
}
}
sitesFilter()