diff options
author | ManeraKai <manerakai@protonmail.com> | 2022-02-12 20:40:36 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2022-02-12 20:40:36 +0300 |
commit | 531e7c5fb4c6d0bc9e15a2d04ee9e0188b11e0d0 (patch) | |
tree | 4fb12639d0ac0f1f2b360fe3169392a5f8621be2 /src/pages/options/shared.js | |
parent | Added redirecting feature #6, will improve it (diff) | |
download | libredirect-531e7c5fb4c6d0bc9e15a2d04ee9e0188b11e0d0.zip |
Rewrote Exceptions logic and design #29
Diffstat (limited to 'src/pages/options/shared.js')
-rw-r--r-- | src/pages/options/shared.js | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/src/pages/options/shared.js b/src/pages/options/shared.js index 36f2ef27..ccc29693 100644 --- a/src/pages/options/shared.js +++ b/src/pages/options/shared.js @@ -17,96 +17,6 @@ function parseURL(urlString) { return ""; } -function autocomplete(input, list) { - let currentFocus; - input.addEventListener("focus", (e) => { - showOptions(e, true); - }); - input.addEventListener("input", (e) => { - const val = e.target.value; - if (!val) { - return false; - } - currentFocus = -1; - showOptions(e); - }); - input.addEventListener("keydown", function (e) { - let x = document.getElementById(this.id + "autocomplete-list"); - if (x) x = x.getElementsByTagName("div"); - if (e.keyCode == 40) { - currentFocus++; - addActive(x); - } else if (e.keyCode == 38) { - currentFocus--; - addActive(x); - } else if (e.keyCode == 13) { - e.preventDefault(); - if (currentFocus > -1) { - if (x) x[currentFocus].click(); - } - } - }); - function showOptions(event, showAll = false) { - let div, - i, - val = event.target.value; - closeAllLists(); - div = document.createElement("div"); - div.setAttribute("id", event.target.id + "autocomplete-list"); - div.setAttribute("class", "autocomplete-items"); - event.target.parentNode.appendChild(div); - for (i = 0; i < list.length; i++) { - if (list[i].toLowerCase().indexOf(val.toLowerCase()) > -1) { - div.appendChild(getItem(list[i], val)); - } else if (showAll) { - div.appendChild(getItem(list[i], val)); - } - } - } - function getItem(item, val) { - const div = document.createElement("div"); - const strong = document.createElement("strong"); - strong.textContent = item.substr(0, val.length); - div.innerText = item.substr(val.length); - const hiddenInput = document.createElement("input"); - hiddenInput.type = "hidden"; - hiddenInput.value = item; - div.prepend(strong); - div.appendChild(hiddenInput); - div.addEventListener("click", function (e) { - input.value = div.getElementsByTagName("input")[0].value; - input.dispatchEvent(new Event("input")); - closeAllLists(); - }); - return div; - } - function addActive(x) { - if (!x) return false; - removeActive(x); - if (currentFocus >= x.length) currentFocus = 0; - if (currentFocus < 0) currentFocus = x.length - 1; - x[currentFocus].classList.add("autocomplete-active"); - } - function removeActive(x) { - for (let i = 0; i < x.length; i++) { - x[i].classList.remove("autocomplete-active"); - } - } - function closeAllLists(elmnt) { - let x = document.getElementsByClassName("autocomplete-items"); - for (let i = 0; i < x.length; i++) { - if (elmnt != x[i] && elmnt != input) { - x[i].parentNode.removeChild(x[i]); - } - } - } - document.addEventListener("click", (e) => { - if (!autocompletes.find((element) => element.id === e.target.id)) { - closeAllLists(e.target); - } - }); -} - export default { autocompletes, parseURL, |