|
|
@@ -6,27 +6,39 @@ const document = window.document;
|
|
|
// add check if it is supported by the browser
|
|
|
// integrate shadowroot into maskcope
|
|
|
if (document && document.head && document.head.attachShadow && window.customElements && window.customElements.get("input-mask") === undefined) {
|
|
|
- class InputmaskElement extends HTMLElement {
|
|
|
- constructor() {
|
|
|
- super();
|
|
|
- var attributeNames = this.getAttributeNames(),
|
|
|
- shadow = this.attachShadow({mode: "closed"}),
|
|
|
- input = document.createElement("input");
|
|
|
- input.type = "text";
|
|
|
- shadow.appendChild(input);
|
|
|
+ class InputmaskElement extends HTMLElement {
|
|
|
+ constructor() {
|
|
|
+ super();
|
|
|
+ var attributeNames = this.getAttributeNames(),
|
|
|
+ shadow = this.attachShadow({mode: "closed"});
|
|
|
+ this.input = document.createElement("input");
|
|
|
+ this.input.type = "text";
|
|
|
+ shadow.appendChild(this.input);
|
|
|
|
|
|
- for (var attr in attributeNames) {
|
|
|
- if (Object.prototype.hasOwnProperty.call(attributeNames, attr)) {
|
|
|
- input.setAttribute(attributeNames[attr], this.getAttribute(attributeNames[attr]));
|
|
|
- }
|
|
|
- }
|
|
|
+ for (var attr in attributeNames) {
|
|
|
+ if (Object.prototype.hasOwnProperty.call(attributeNames, attr)) {
|
|
|
+ this.input.setAttribute(attributeNames[attr], this.getAttribute(attributeNames[attr]));
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var im = new Inputmask();
|
|
|
- im.dataAttribute = "";
|
|
|
- im.mask(input);
|
|
|
- input.inputmask.shadowRoot = shadow; //make the shadowRoot available
|
|
|
- }
|
|
|
- }
|
|
|
+ var im = new Inputmask();
|
|
|
+ im.dataAttribute = "";
|
|
|
+ im.mask(this.input);
|
|
|
+ im.shadowRoot = shadow; //make the shadowRoot available
|
|
|
+ }
|
|
|
|
|
|
- window.customElements.define("input-mask", InputmaskElement);
|
|
|
+ attributeChangedCallback(attrName, oldVal, newVal) {
|
|
|
+ this.input.setAttribute(attrName, newVal);
|
|
|
+ }
|
|
|
+
|
|
|
+ //bind value
|
|
|
+ get value() {
|
|
|
+ return this.input.value;
|
|
|
+ }
|
|
|
+ set value(value) {
|
|
|
+ this.input.value = value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ window.customElements.define("input-mask", InputmaskElement);
|
|
|
}
|