1 2(function(){ 3 var x, i, j, selElmnt, a, b, c; 4 /*look for any elements with the class "custom-select":*/ 5 x = document.getElementsByClassName("custom-select"); 6 for (i = 0; i < x.length; i++) { 7 selElmnt = x[i].getElementsByTagName("select")[0]; 8 /*for each element, create a new DIV that will act as the selected item:*/ 9 a = document.createElement("DIV"); 10 a.setAttribute("class", "select-selected"); 11 a.innerHTML = selElmnt.options[selElmnt.selectedIndex].innerHTML; 12 x[i].appendChild(a); 13 /*for each element, create a new DIV that will contain the option list:*/ 14 b = document.createElement("DIV"); 15 b.setAttribute("class", "select-items select-hide"); 16 for (j = 1; j < selElmnt.length; j++) { 17 /*for each option in the original select element, 18 create a new DIV that will act as an option item:*/ 19 c = document.createElement("DIV"); 20 c.innerHTML = selElmnt.options[j].innerHTML; 21 c.addEventListener("click", function(e) { 22 /*when an item is clicked, update the original select box, 23 and the selected item:*/ 24 var y, i, k, s, h; 25 s = this.parentNode.parentNode.getElementsByTagName("select")[0]; 26 h = this.parentNode.previousSibling; 27 for (i = 0; i < s.length; i++) { 28 if (s.options[i].innerHTML == this.innerHTML) { 29 s.selectedIndex = i; 30 h.innerHTML = this.innerHTML; 31 y = this.parentNode.getElementsByClassName("same-as-selected"); 32 for (k = 0; k < y.length; k++) { 33 y[k].removeAttribute("class"); 34 } 35 this.setAttribute("class", "same-as-selected"); 36 break; 37 } 38 } 39 h.click(); 40 }); 41 b.appendChild(c); 42 } 43 x[i].appendChild(b); 44 a.addEventListener("click", function(e) { 45 /*when the select box is clicked, close any other select boxes, 46 and open/close the current select box:*/ 47 e.stopPropagation(); 48 closeAllSelect(this); 49 this.nextSibling.classList.toggle("select-hide"); 50 this.classList.toggle("select-arrow-active"); 51 }); 52 } 53 function closeAllSelect(elmnt) { 54 /*a function that will close all select boxes in the document, 55 except the current select box:*/ 56 var x, y, i, arrNo = []; 57 x = document.getElementsByClassName("select-items"); 58 y = document.getElementsByClassName("select-selected"); 59 for (i = 0; i < y.length; i++) { 60 if (elmnt == y[i]) { 61 arrNo.push(i) 62 } else { 63 y[i].classList.remove("select-arrow-active"); 64 } 65 } 66 for (i = 0; i < x.length; i++) { 67 if (arrNo.indexOf(i)) { 68 x[i].classList.add("select-hide"); 69 } 70 } 71 } 72 /*if the user clicks anywhere outside the select box, 73 then close all select boxes:*/ 74 document.addEventListener("click", closeAllSelect); 75}());
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.