1let xSelect, iSelect, jSelect, lSelect, ll, selElmnt, aSelect, bSelect, cSelect; 2/*look for any elements with the class "custom-select":*/ 3xSelect = document.getElementsByClassName("custom-select"); 4lSelect = xSelect.length; 5for (iSelect = 0; iSelect < lSelect; iSelect++) { 6 selElmnt = xSelect[iSelect].getElementsByTagName("select")[0]; 7 if(selElmnt){ 8 ll = selElmnt.length; 9 } 10 /*for each element, create a new DIV that will act as the selected item:*/ 11 aSelect = document.createElement("DIV"); 12 aSelect.setAttribute("class", "select-selected"); 13 if(selElmnt){ 14 aSelect.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML; 15 } 16 xSelect[iSelect].appendChild(aSelect); 17 /*for each element, create a new DIV that will contain the option list:*/ 18 bSelect = document.createElement("DIV"); 19 bSelect.setAttribute("class", "select-items select-hide"); 20 for (jSelect = 1; jSelect < ll; jSelect++) { 21 /*for each option in the original select element, 22 create a new DIV that will act as an option item:*/ 23 cSelect = document.createElement("DIV"); 24 if(selElmnt){ 25 cSelect.innerHTML = selElmnt.options[jSelect].innerHTML; 26 } 27 cSelect.addEventListener("click", function(e) { 28 /*when an item is clicked, update the original select box, 29 and the selected item:*/ 30 let ySelect, iSelect, kSelect, sSelect, hSelect, slSelect, ylSelect; 31 sSelect = this.parentNode.parentNode.getElementsByTagName("select")[0]; 32 slSelect = sSelect.length; 33 hSelect = this.parentNode.previousSibling; 34 for (iSelect = 0; iSelect < slSelect; iSelect++) { 35 if (sSelect.options[iSelect].innerHTML == this.innerHTML) { 36 sSelect.selectedIndex = iSelect; 37 hSelect.innerHTML = this.innerHTML; 38 ySelect = this.parentNode.getElementsByClassName("same-as-selected"); 39 ylSelect = ySelect.length; 40 for (kSelect = 0; kSelect < ylSelect; kSelect++) { 41 ySelect[kSelect].removeAttribute("class"); 42 } 43 this.setAttribute("class", "same-as-selected"); 44 break; 45 } 46 } 47 hSelect.click(); 48 }); 49 bSelect.appendChild(cSelect); 50 } 51 xSelect[iSelect].appendChild(bSelect); 52 aSelect.addEventListener("click", function(e) { 53 /*when the select box is clicked, close any other select boxes, 54 and open/close the current select box:*/ 55 e.stopPropagation(); 56 closeAllSelect(this); 57 this.nextSibling.classList.toggle("select-hide"); 58 this.classList.toggle("select-arrow-active"); 59 }); 60} 61function closeAllSelect(elmnt) { 62 /*a function that will close all select boxes in the document, 63 except the current select box:*/ 64 var xSelect, ySelect, iSelect, xlSelect, ylSelect, arrNo = []; 65 xSelect = document.getElementsByClassName("select-items"); 66 ySelect = document.getElementsByClassName("select-selected"); 67 xlSelect = xSelect.length; 68 ylSelect = ySelect.length; 69 for (iSelect = 0; iSelect < ylSelect; iSelect++) { 70 if (elmnt == ySelect[iSelect]) { 71 arrNo.push(iSelect) 72 } else { 73 ySelect[iSelect].classList.remove("select-arrow-active"); 74 } 75 } 76 for (iSelect = 0; iSelect < xlSelect; iSelect++) { 77 if (arrNo.indexOf(iSelect)) { 78 xSelect[iSelect].classList.add("select-hide"); 79 } 80 } 81} 82/*if the user clicks anywhere outside the select box, 83then close all select boxes:*/ 84document.addEventListener("click", closeAllSelect);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.