版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

82 строки
2.2 KiB

  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const DOMException_1 = __importDefault(require("../../exception/DOMException"));
  7. const HTMLCollection_1 = __importDefault(require("../element/HTMLCollection"));
  8. /**
  9. * HTML Options Collection.
  10. *
  11. * Reference:
  12. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionsCollection.
  13. */
  14. class HTMLOptionsCollection extends HTMLCollection_1.default {
  15. /**
  16. *
  17. * @param selectElement
  18. */
  19. constructor(selectElement) {
  20. super();
  21. this._selectElement = selectElement;
  22. }
  23. /**
  24. * Returns selectedIndex.
  25. *
  26. * @returns SelectedIndex.
  27. */
  28. get selectedIndex() {
  29. return this._selectElement.selectedIndex;
  30. }
  31. /**
  32. * Sets selectedIndex.
  33. *
  34. * @param selectedIndex SelectedIndex.
  35. */
  36. set selectedIndex(selectedIndex) {
  37. this._selectElement.selectedIndex = selectedIndex;
  38. }
  39. /**
  40. * Returns item by index.
  41. *
  42. * @param index Index.
  43. */
  44. item(index) {
  45. return this[index];
  46. }
  47. /**
  48. *
  49. * @param element
  50. * @param before
  51. */
  52. add(element, before) {
  53. if (!before && before !== 0) {
  54. this._selectElement.appendChild(element);
  55. return;
  56. }
  57. if (!Number.isNaN(Number(before))) {
  58. if (before < 0) {
  59. return;
  60. }
  61. this._selectElement.insertBefore(element, this[before]);
  62. return;
  63. }
  64. const index = this.indexOf(before);
  65. if (index === -1) {
  66. throw new DOMException_1.default("Failed to execute 'add' on 'DOMException': The node before which the new node is to be inserted is not a child of this node.");
  67. }
  68. this._selectElement.insertBefore(element, this[index]);
  69. }
  70. /**
  71. * Removes indexed element from collection.
  72. *
  73. * @param index Index.
  74. */
  75. remove(index) {
  76. if (this[index]) {
  77. this._selectElement.removeChild(this[index]);
  78. }
  79. }
  80. }
  81. exports.default = HTMLOptionsCollection;
  82. //# sourceMappingURL=HTMLOptionsCollection.js.map