inputmaskElement.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import window from "./global/window";
  2. import Inputmask from "./inputmask";
  3. import canUseDOM from "./canUseDOM";
  4. const document = window.document;
  5. // add check if it is supported by the browser
  6. // integrate shadowroot into maskcope
  7. if (canUseDOM && document && document.head && document.head.attachShadow && window.customElements && window.customElements.get("input-mask") === undefined) {
  8. class InputmaskElement extends HTMLElement {
  9. constructor() {
  10. super();
  11. var attributeNames = this.getAttributeNames(),
  12. shadow = this.attachShadow({mode: "closed"}),
  13. input = document.createElement("input");
  14. input.type = "text";
  15. shadow.appendChild(input);
  16. for (var attr in attributeNames) {
  17. if (Object.prototype.hasOwnProperty.call(attributeNames, attr)) {
  18. input.setAttribute(attributeNames[attr], this.getAttribute(attributeNames[attr]));
  19. }
  20. }
  21. var im = new Inputmask();
  22. im.dataAttribute = "";
  23. im.mask(input);
  24. input.inputmask.shadowRoot = shadow; //make the shadowRoot available
  25. }
  26. }
  27. window.customElements.define("input-mask", InputmaskElement);
  28. }