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