|
- "use strict";
- var __importDefault = (this && this.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- const HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
- /**
- * HTML Option Element.
- *
- * Reference:
- * https://developer.mozilla.org/en-US/docs/Web/API/HTMLOptionElement.
- */
- class HTMLOptionElement extends HTMLElement_1.default {
- constructor() {
- super(...arguments);
- this._selectedness = false;
- this._dirtyness = false;
- }
- /**
- * Returns inner text, which is the rendered appearance of text.
- *
- * @returns Inner text.
- */
- get text() {
- return this.innerText;
- }
- /**
- * Sets the inner text, which is the rendered appearance of text.
- *
- * @param innerText Inner text.
- */
- set text(text) {
- this.innerText = text;
- }
- /**
- * Returns index.
- *
- * @returns Index.
- */
- get index() {
- return this._index;
- }
- /**
- * Returns the parent form element.
- *
- * @returns Form.
- */
- get form() {
- let parent = this.parentNode;
- while (parent && parent.tagName !== 'FORM') {
- parent = parent.parentNode;
- }
- return parent;
- }
- /**
- * Returns selected.
- *
- * @returns Selected.
- */
- get selected() {
- return this._selectedness;
- }
- /**
- * Sets selected.
- *
- * @param selected Selected.
- */
- set selected(selected) {
- const selectElement = this._getSelectElement();
- this._dirtyness = true;
- this._selectedness = Boolean(selected);
- if (selectElement) {
- selectElement._resetOptionSelectednes(this._selectedness ? this : null);
- }
- }
- /**
- * Returns disabled.
- *
- * @returns Disabled.
- */
- get disabled() {
- return this.getAttributeNS(null, 'disabled') !== null;
- }
- /**
- * Sets disabled.
- *
- * @param disabled Disabled.
- */
- set disabled(disabled) {
- if (!disabled) {
- this.removeAttributeNS(null, 'disabled');
- }
- else {
- this.setAttributeNS(null, 'disabled', '');
- }
- }
- /**
- * Returns value.
- *
- * @returns Value.
- */
- get value() {
- return this.getAttributeNS(null, 'value') || this.textContent;
- }
- /**
- * Sets value.
- *
- * @param value Value.
- */
- set value(value) {
- this.setAttributeNS(null, 'value', value);
- }
- /**
- * @override
- */
- setAttributeNode(attribute) {
- const replacedAttribute = super.setAttributeNode(attribute);
- if (!this._dirtyness &&
- attribute.name === 'selected' &&
- replacedAttribute?.value !== attribute.value) {
- const selectElement = this._getSelectElement();
- this._selectedness = true;
- if (selectElement) {
- selectElement._resetOptionSelectednes(this);
- }
- }
- return replacedAttribute;
- }
- /**
- * @override
- */
- removeAttributeNode(attribute) {
- super.removeAttributeNode(attribute);
- if (!this._dirtyness && attribute.name === 'selected') {
- const selectElement = this._getSelectElement();
- this._selectedness = false;
- if (selectElement) {
- selectElement._resetOptionSelectednes();
- }
- }
- return attribute;
- }
- /**
- * Returns select element.
- *
- * @returns Select element.
- */
- _getSelectElement() {
- const parentNode = this.parentNode;
- if (parentNode?.tagName === 'SELECT') {
- return parentNode;
- }
- if (parentNode?.parentNode?.tagName === 'SELECT') {
- return parentNode.parentNode;
- }
- }
- }
- exports.default = HTMLOptionElement;
- //# sourceMappingURL=HTMLOptionElement.js.map
|