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

159 строки
3.9 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 HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
  7. /**
  8. * HTML Option Element.
  9. *
  10. * Reference:
  11. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
  12. */
  13. class HTMLOptionElement extends HTMLElement_1.default {
  14. constructor() {
  15. super(...arguments);
  16. this._selectedness = false;
  17. this._dirtyness = false;
  18. }
  19. /**
  20. * Returns inner text, which is the rendered appearance of text.
  21. *
  22. * @returns Inner text.
  23. */
  24. get text() {
  25. return this.innerText;
  26. }
  27. /**
  28. * Sets the inner text, which is the rendered appearance of text.
  29. *
  30. * @param innerText Inner text.
  31. */
  32. set text(text) {
  33. this.innerText = text;
  34. }
  35. /**
  36. * Returns index.
  37. *
  38. * @returns Index.
  39. */
  40. get index() {
  41. return this._index;
  42. }
  43. /**
  44. * Returns the parent form element.
  45. *
  46. * @returns Form.
  47. */
  48. get form() {
  49. let parent = this.parentNode;
  50. while (parent && parent.tagName !== 'FORM') {
  51. parent = parent.parentNode;
  52. }
  53. return parent;
  54. }
  55. /**
  56. * Returns selected.
  57. *
  58. * @returns Selected.
  59. */
  60. get selected() {
  61. return this._selectedness;
  62. }
  63. /**
  64. * Sets selected.
  65. *
  66. * @param selected Selected.
  67. */
  68. set selected(selected) {
  69. const selectElement = this._getSelectElement();
  70. this._dirtyness = true;
  71. this._selectedness = Boolean(selected);
  72. if (selectElement) {
  73. selectElement._resetOptionSelectednes(this._selectedness ? this : null);
  74. }
  75. }
  76. /**
  77. * Returns disabled.
  78. *
  79. * @returns Disabled.
  80. */
  81. get disabled() {
  82. return this.getAttributeNS(null, 'disabled') !== null;
  83. }
  84. /**
  85. * Sets disabled.
  86. *
  87. * @param disabled Disabled.
  88. */
  89. set disabled(disabled) {
  90. if (!disabled) {
  91. this.removeAttributeNS(null, 'disabled');
  92. }
  93. else {
  94. this.setAttributeNS(null, 'disabled', '');
  95. }
  96. }
  97. /**
  98. * Returns value.
  99. *
  100. * @returns Value.
  101. */
  102. get value() {
  103. return this.getAttributeNS(null, 'value') || this.textContent;
  104. }
  105. /**
  106. * Sets value.
  107. *
  108. * @param value Value.
  109. */
  110. set value(value) {
  111. this.setAttributeNS(null, 'value', value);
  112. }
  113. /**
  114. * @override
  115. */
  116. setAttributeNode(attribute) {
  117. const replacedAttribute = super.setAttributeNode(attribute);
  118. if (!this._dirtyness &&
  119. attribute.name === 'selected' &&
  120. replacedAttribute?.value !== attribute.value) {
  121. const selectElement = this._getSelectElement();
  122. this._selectedness = true;
  123. if (selectElement) {
  124. selectElement._resetOptionSelectednes(this);
  125. }
  126. }
  127. return replacedAttribute;
  128. }
  129. /**
  130. * @override
  131. */
  132. removeAttributeNode(attribute) {
  133. super.removeAttributeNode(attribute);
  134. if (!this._dirtyness && attribute.name === 'selected') {
  135. const selectElement = this._getSelectElement();
  136. this._selectedness = false;
  137. if (selectElement) {
  138. selectElement._resetOptionSelectednes();
  139. }
  140. }
  141. return attribute;
  142. }
  143. /**
  144. * Returns select element.
  145. *
  146. * @returns Select element.
  147. */
  148. _getSelectElement() {
  149. const parentNode = this.parentNode;
  150. if (parentNode?.tagName === 'SELECT') {
  151. return parentNode;
  152. }
  153. if (parentNode?.parentNode?.tagName === 'SELECT') {
  154. return parentNode.parentNode;
  155. }
  156. }
  157. }
  158. exports.default = HTMLOptionElement;
  159. //# sourceMappingURL=HTMLOptionElement.js.map