Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

89 linhas
3.0 KiB

  1. var x, i, j, l, ll, selElmnt, a, b, c;
  2. /* Look for any elements with the class "custom-select": */
  3. x = document.getElementsByClassName("custom-select");
  4. for(let c of x)
  5. {
  6. c.style.width = (c.children[0].scrollWidth + 35).toString() + "px";
  7. c.children[0].style.display = "none";
  8. }
  9. l = x.length;
  10. for (i = 0; i < l; i++) {
  11. selElmnt = x[i].getElementsByTagName("select")[0];
  12. ll = selElmnt.length;
  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 < ll; 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, sl, yl;
  30. s = this.parentNode.parentNode.getElementsByTagName("select")[0];
  31. sl = s.length;
  32. h = this.parentNode.previousSibling;
  33. for (i = 0; i < sl; i++) {
  34. if (s.options[i].innerHTML == this.innerHTML) {
  35. s.selectedIndex = i;
  36. h.innerHTML = this.innerHTML;
  37. y = this.parentNode.getElementsByClassName("same-as-selected");
  38. yl = y.length;
  39. for (k = 0; k < yl; k++) {
  40. y[k].removeAttribute("class");
  41. }
  42. this.setAttribute("class", "same-as-selected");
  43. break;
  44. }
  45. }
  46. SelectChange(s.id);
  47. h.click();
  48. });
  49. b.appendChild(c);
  50. }
  51. x[i].appendChild(b);
  52. a.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. }
  61. function closeAllSelect(elmnt) {
  62. /* A function that will close all select boxes in the document,
  63. except the current select box: */
  64. var x, y, i, xl, yl, arrNo = [];
  65. x = document.getElementsByClassName("select-items");
  66. y = document.getElementsByClassName("select-selected");
  67. xl = x.length;
  68. yl = y.length;
  69. for (i = 0; i < yl; i++) {
  70. if (elmnt == y[i]) {
  71. arrNo.push(i)
  72. } else {
  73. y[i].classList.remove("select-arrow-active");
  74. }
  75. }
  76. for (i = 0; i < xl; i++) {
  77. if (arrNo.indexOf(i)) {
  78. x[i].classList.add("select-hide");
  79. }
  80. }
  81. }
  82. /* If the user clicks anywhere outside the select box,
  83. then close all select boxes: */
  84. document.addEventListener("click", closeAllSelect);