UNPKG

native-es6-webkit

Version:
105 lines (94 loc) 4.45 kB
'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var BlueRadioButton = function (_HTMLElement) { _inherits(BlueRadioButton, _HTMLElement); function BlueRadioButton() { _classCallCheck(this, BlueRadioButton); var _this = _possibleConstructorReturn(this, (BlueRadioButton.__proto__ || Object.getPrototypeOf(BlueRadioButton)).call(this)); _this.attachShadow({ mode: 'open' }); return _this; } _createClass(BlueRadioButton, [{ key: 'attributeChangedCallback', value: function attributeChangedCallback(attrName, oldValue, newValue) { if (attrName === 'disabled') { this.disabled = newValue; } else if (attrName === 'name') { this.name = newValue; } else if (attrName === 'value') { this.value = newValue; } else if (attrName === 'checked') { this.checked = newValue; } } }, { key: 'connectedCallback', value: function connectedCallback() { this.shadowRoot.innerHTML = this.renderHTML(this._rdname, this._rdvalue, this._rdchecked); } }, { key: 'renderHTML', value: function renderHTML(_name, _value, _checked) { return '\n <input type="radio" name="' + _name + '" value="' + _value + '" checked="' + _checked + '" />\n '; } }, { key: 'disabled', get: function get() { return this.shadowRoot.querySelector('input').hasAttribute('disabled'); }, set: function set(value) { var val = Boolean(value); if (val) { this.shadowRoot.querySelector('input').setAttribute('disabled'); } else { this.shadowRoot.querySelector('input').removeAttribute('disabled'); } } }, { key: 'checked', get: function get() { return this.shadowRoot.querySelector('input').getAttribute('checked'); }, set: function set(value) { var val = Boolean(value); if (!(value === 'undefined')) { this._rdchecked = value; this.shadowRoot.innerHTML = this.renderHTML(this._rdname, this._rdvalue, this._rdchecked); } } }, { key: 'name', get: function get() { return this.shadowRoot.querySelector('input').getAttribute('name'); }, set: function set(val) { var value = val; if (!(value === 'undefined')) { this._rdname = value; this.shadowRoot.innerHTML = this.renderHTML(this._rdname, this._rdvalue, this._rdchecked); } } }, { key: 'value', get: function get() { return this.shadowRoot.querySelector('input').getAttribute('value'); }, set: function set(val) { var rd_value = val; if (!(rd_value === 'undefined')) { this._rdvalue = rd_value; this.shadowRoot.innerHTML = this.renderHTML(this._rdname, this._rdvalue, this._rdchecked); } } }], [{ key: 'observedAttributes', get: function get() { return ['name', 'value', 'disabled', 'checked']; } }]); return BlueRadioButton; }(HTMLElement); customElements.define("b-radio-button", BlueRadioButton);