版博士V2.0程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

HTMLUnknownElement.js 2.3 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 Unknown Element.
  9. *
  10. * Reference:
  11. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLUnknownElement.
  12. */
  13. class HTMLUnknownElement extends HTMLElement_1.default {
  14. constructor() {
  15. super(...arguments);
  16. this._customElementDefineCallback = null;
  17. }
  18. /**
  19. * Connects this element to another element.
  20. *
  21. * @param parentNode Parent node.
  22. */
  23. _connectToNode(parentNode = null) {
  24. const tagName = this.tagName;
  25. // This element can potentially be a custom element that has not been defined yet
  26. // Therefore we need to register a callback for when it is defined in CustomElementRegistry and replace it with the registered element (see #404)
  27. if (tagName.includes('-')) {
  28. const callbacks = this.ownerDocument.defaultView.customElements._callbacks;
  29. if (parentNode && !this._customElementDefineCallback) {
  30. const callback = () => {
  31. if (this.parentNode) {
  32. const newElement = this.ownerDocument.createElement(tagName);
  33. this.parentNode.insertBefore(newElement, this);
  34. this.parentNode.removeChild(this);
  35. }
  36. };
  37. callbacks[tagName] = callbacks[tagName] || [];
  38. callbacks[tagName].push(callback);
  39. this._customElementDefineCallback = callback;
  40. }
  41. else if (!parentNode && callbacks[tagName] && this._customElementDefineCallback) {
  42. const index = callbacks[tagName].indexOf(this._customElementDefineCallback);
  43. if (index !== -1) {
  44. callbacks[tagName].splice(index, 1);
  45. }
  46. if (!callbacks[tagName].length) {
  47. delete callbacks[tagName];
  48. }
  49. this._customElementDefineCallback = null;
  50. }
  51. }
  52. super._connectToNode(parentNode);
  53. }
  54. }
  55. exports.default = HTMLUnknownElement;
  56. //# sourceMappingURL=HTMLUnknownElement.js.map