PageSourceSearch

https://lovozero51.ru/js/custom-select.js?v=1605128400

js lovozero51.ru collected 2026-10-08 19:23:42 UTC 3,003 bytes, 82 lines download raw bytes

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

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.