inputmaskElement.js 1.2 KB

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