123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray';
- import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
- import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
- import _createClass from 'babel-runtime/helpers/createClass';
- import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
- import _get from 'babel-runtime/helpers/get';
- import _inherits from 'babel-runtime/helpers/inherits';
-
-
- import onsElements from '../ons/elements';
- import BaseInputElement from './base/base-input';
- import contentReady from '../ons/content-ready';
- import util from '../ons/util';
-
- var scheme = {
- '.text-input': 'text-input--*',
- '.text-input__label': 'text-input--*__label'
- };
-
-
-
- var InputElement = function (_BaseInputElement) {
- _inherits(InputElement, _BaseInputElement);
-
- function InputElement() {
- _classCallCheck(this, InputElement);
-
- var _this = _possibleConstructorReturn(this, (InputElement.__proto__ || _Object$getPrototypeOf(InputElement)).call(this));
-
- _this._boundOnInput = _this._update.bind(_this);
- _this._boundOnFocusin = _this._update.bind(_this);
- return _this;
- }
-
-
-
- _createClass(InputElement, [{
- key: '_update',
- value: function _update() {
- this._updateLabel();
- this._updateLabelClass();
- }
- }, {
- key: '_updateLabel',
-
-
-
-
- value: function _updateLabel() {
- var label = this.getAttribute('placeholder') || '';
-
- if (typeof this._helper.textContent !== 'undefined') {
- this._helper.textContent = label;
- } else {
- this._helper.innerText = label;
- }
- }
- }, {
- key: '_updateLabelClass',
- value: function _updateLabelClass() {
- if (this.value === '') {
- this._helper.classList.remove('text-input--material__label--active');
- } else {
- this._helper.classList.add('text-input--material__label--active');
- }
- }
- }, {
- key: 'connectedCallback',
- value: function connectedCallback() {
- var _this2 = this;
-
- _get(InputElement.prototype.__proto__ || _Object$getPrototypeOf(InputElement.prototype), 'connectedCallback', this).call(this);
-
- contentReady(this, function () {
- _this2._input.addEventListener('input', _this2._boundOnInput);
- _this2._input.addEventListener('focusin', _this2._boundOnFocusin);
- });
-
- var type = this.getAttribute('type');
- if (['checkbox', 'radio'].indexOf(type) >= 0) {
- util.warn('Warn: <ons-input type="' + type + '"> is deprecated since v2.4.0. Use <ons-' + type + '> instead.');
- }
- }
- }, {
- key: 'disconnectedCallback',
- value: function disconnectedCallback() {
- var _this3 = this;
-
- _get(InputElement.prototype.__proto__ || _Object$getPrototypeOf(InputElement.prototype), 'disconnectedCallback', this).call(this);
-
- contentReady(this, function () {
- _this3._input.removeEventListener('input', _this3._boundOnInput);
- _this3._input.removeEventListener('focusin', _this3._boundOnFocusin);
- });
- }
- }, {
- key: 'attributeChangedCallback',
- value: function attributeChangedCallback(name, last, current) {
- var _this4 = this;
-
- switch (name) {
- case 'type':
- contentReady(this, function () {
- return _this4._input.setAttribute('type', _this4.type);
- });
- break;
- default:
- _get(InputElement.prototype.__proto__ || _Object$getPrototypeOf(InputElement.prototype), 'attributeChangedCallback', this).call(this, name, last, current);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- }, {
- key: '_scheme',
- get: function get() {
- return scheme;
- }
- }, {
- key: '_template',
- get: function get() {
- return '\n <input type="' + this.type + '" class="text-input">\n <span class="text-input__label"></span>\n ';
- }
- }, {
- key: 'type',
- get: function get() {
- var type = this.getAttribute('type');
- return ['checkbox', 'radio'].indexOf(type) < 0 && type || 'text';
- }
- }, {
- key: '_helper',
- get: function get() {
- return this.querySelector('span');
- }
- }], [{
- key: 'observedAttributes',
- get: function get() {
- return [].concat(_toConsumableArray(_get(InputElement.__proto__ || _Object$getPrototypeOf(InputElement), 'observedAttributes', this)), ['type']);
- }
- }]);
-
- return InputElement;
- }(BaseInputElement);
-
- export default InputElement;
-
-
- onsElements.Input = InputElement;
- customElements.define('ons-input', InputElement);
|