(function(define){define(function(require,exports,module){ /*jshint esnext:true*/ 'use strict'; /** * Dependencies */ var component = require('gaia-component'); require('gaia-icons'); // Load gaia-icons /** * Exports */ module.exports = component.register('gaia-text-input', { extends: HTMLInputElement, rtl: true, created: function() { this.setupShadowRoot(); this.els = { inner: this.shadowRoot.querySelector('.inner'), input: this.shadowRoot.querySelector('input'), clear: this.shadowRoot.querySelector('.clear') }; this.type = this.getAttribute('type'); this.disabled = this.hasAttribute('disabled'); this.clearable = this.hasAttribute('clearable'); this.placeholder = this.getAttribute('placeholder'); this.required = this.getAttribute('required'); this.value = this.getAttribute('value'); // Don't take focus from the input field this.els.clear.addEventListener('mousedown', (e) => e.preventDefault()); this.els.clear.addEventListener('click', e => this.clear(e)); // Set dir initially and listen for changes document.addEventListener('dirchanged', e => this.updateDir()); this.updateDir(); }, clear: function(e) { this.value = ''; }, focus: function() { this.els.input.focus(); }, updateDir: function() { this.els.inner.setAttribute('dir', document.dir); }, /** * Attributes */ attrs: { type: { get: function() { return this.els.input.getAttribute('type'); }, set: function(value) { if (!value) { return; } this.els.inner.setAttribute('type', value); this.els.input.setAttribute('type', value); } }, placeholder: { get: function() { return this.field.placeholder; }, set: function(value) { if (!value && value !== '') { return; } this.els.input.placeholder = value; } }, clearable: { get: function() { return this._clearable; }, set: function(value) { var clearable = !!(value === '' || value); if (clearable === this.clearable) { return; } if (clearable) { this.els.inner.setAttribute('clearable', ''); this.setAttribute('clearable', ''); } else { this.els.inner.removeAttribute('clearable'); this.removeAttribute('clearable'); } this._clearable = clearable; } }, value: { get: function() { return this.els.input.value; }, set: function(value) { this.els.input.value = value; } }, required: { get: function() { return this.els.input.required; }, set: function(value) { this.els.input.required = value; } }, maxlength: { get: function() { return this.els.input.getAttribute('maxlength'); }, set: function(value) { this.els.input.setAttribute('maxlength', value); } }, disabled: { get: function() { return this.els.input.disabled; }, set: function(value) { value = !!(value === '' || value); this.els.input.disabled = value; } } }, template: `
` }); });})((function(n,w){return typeof define=='function'&&define.amd? define:typeof module=='object'?function(c){c(require,exports,module);}:function(c){ var m={exports:{}},r=function(n){return w[n];};w[n]=c(r,m.exports,m)||m.exports;};})('gaia-text-input',this));