版博士V2.0程序
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

HTMLButtonElement.js 1.9 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. const BUTTON_TYPES = ['submit', 'reset', 'button', 'menu'];
  8. /**
  9. We can improve performance a bit if we make the types as a constant.
  10. * HTML Button Element.
  11. *
  12. * Reference:
  13. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLButtonElement.
  14. */
  15. class HTMLButtonElement extends HTMLElement_1.default {
  16. /**
  17. * Returns value.
  18. *
  19. * @returns Value.
  20. */
  21. get value() {
  22. return this.getAttributeNS(null, 'value');
  23. }
  24. /**
  25. * Sets value.
  26. *
  27. * @param value Value.
  28. */
  29. set value(value) {
  30. this.setAttributeNS(null, 'value', value);
  31. }
  32. /**
  33. * Returns disabled.
  34. *
  35. * @returns Disabled.
  36. */
  37. get disabled() {
  38. return this.getAttributeNS(null, 'disabled') !== null;
  39. }
  40. /**
  41. * Sets disabled.
  42. *
  43. * @param disabled Disabled.
  44. */
  45. set disabled(disabled) {
  46. if (!disabled) {
  47. this.removeAttributeNS(null, 'disabled');
  48. }
  49. else {
  50. this.setAttributeNS(null, 'disabled', '');
  51. }
  52. }
  53. /**
  54. * Returns type
  55. *
  56. * @returns Type
  57. */
  58. get type() {
  59. return this._sanitizeType(this.getAttributeNS(null, 'type'));
  60. }
  61. /**
  62. * Sets type
  63. *
  64. * @param v Type
  65. */
  66. set type(v) {
  67. this.setAttributeNS(null, 'type', this._sanitizeType(v));
  68. }
  69. /**
  70. *
  71. * @param type
  72. */
  73. _sanitizeType(type) {
  74. type = (type && type.toLowerCase()) || 'submit';
  75. if (!BUTTON_TYPES.includes(type)) {
  76. type = 'submit';
  77. }
  78. return type;
  79. }
  80. }
  81. exports.default = HTMLButtonElement;
  82. //# sourceMappingURL=HTMLButtonElement.js.map