Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

base-button.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import _toConsumableArray from 'babel-runtime/helpers/toConsumableArray';
  2. import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
  3. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  4. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  5. import _createClass from 'babel-runtime/helpers/createClass';
  6. import _inherits from 'babel-runtime/helpers/inherits';
  7. /*
  8. Copyright 2013-2015 ASIAL CORPORATION
  9. Licensed under the Apache License, Version 2.0 (the "License");
  10. you may not use this file except in compliance with the License.
  11. You may obtain a copy of the License at
  12. http://www.apache.org/licenses/LICENSE-2.0
  13. Unless required by applicable law or agreed to in writing, software
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. */
  19. import onsElements from '../../ons/elements';
  20. import util from '../../ons/util';
  21. import autoStyle from '../../ons/autostyle';
  22. import contentReady from '../../ons/content-ready';
  23. import ModifierUtil from '../../ons/internal/modifier-util';
  24. import BaseElement from './base-element';
  25. var BaseButtonElement = function (_BaseElement) {
  26. _inherits(BaseButtonElement, _BaseElement);
  27. _createClass(BaseButtonElement, [{
  28. key: '_scheme',
  29. get: function get() {
  30. util.throwMember();
  31. }
  32. }, {
  33. key: '_defaultClassName',
  34. get: function get() {
  35. util.throwMember();
  36. }
  37. }, {
  38. key: '_rippleOpt',
  39. get: function get() {
  40. return [this];
  41. }
  42. }]);
  43. function BaseButtonElement() {
  44. _classCallCheck(this, BaseButtonElement);
  45. var _this = _possibleConstructorReturn(this, (BaseButtonElement.__proto__ || _Object$getPrototypeOf(BaseButtonElement)).call(this));
  46. if (_this.constructor === BaseButtonElement) {
  47. util.throwAbstract();
  48. }
  49. contentReady(_this, function () {
  50. return _this._compile();
  51. });
  52. return _this;
  53. }
  54. _createClass(BaseButtonElement, [{
  55. key: '_compile',
  56. value: function _compile() {
  57. autoStyle.prepare(this);
  58. this.classList.add(this._defaultClassName);
  59. if (!this._icon && this.hasAttribute('icon')) {
  60. util.checkMissingImport('Icon');
  61. var icon = util.createElement('<ons-icon icon="' + this.getAttribute('icon') + '"></ons-icon>');
  62. icon.classList.add(this._defaultClassName.replace('button', 'icon'));
  63. this.insertBefore(icon, this.firstChild);
  64. }
  65. this._updateRipple();
  66. ModifierUtil.initModifier(this, this._scheme);
  67. }
  68. }, {
  69. key: '_updateIcon',
  70. value: function _updateIcon() {
  71. if (this._icon) {
  72. this._icon.setAttribute('icon', this.getAttribute('icon'));
  73. }
  74. }
  75. }, {
  76. key: '_updateRipple',
  77. value: function _updateRipple() {
  78. this._rippleOpt && util.updateRipple.apply(util, _toConsumableArray(this._rippleOpt));
  79. }
  80. }, {
  81. key: 'attributeChangedCallback',
  82. value: function attributeChangedCallback(name, last, current) {
  83. switch (name) {
  84. case 'class':
  85. util.restoreClass(this, this._defaultClassName, this._scheme);
  86. break;
  87. case 'modifier':
  88. ModifierUtil.onModifierChanged(last, current, this, this._scheme);
  89. break;
  90. case 'icon':
  91. this._updateIcon();
  92. break;
  93. case 'ripple':
  94. this.classList.contains(this._defaultClassName) && this._updateRipple();
  95. break;
  96. }
  97. }
  98. }, {
  99. key: 'disabled',
  100. set: function set(value) {
  101. return util.toggleAttribute(this, 'disabled', value);
  102. },
  103. get: function get() {
  104. return this.hasAttribute('disabled');
  105. }
  106. }, {
  107. key: '_icon',
  108. get: function get() {
  109. return util.findChild(this, 'ons-icon');
  110. }
  111. }], [{
  112. key: 'observedAttributes',
  113. get: function get() {
  114. return ['modifier', 'class', 'icon', 'ripple'];
  115. }
  116. }]);
  117. return BaseButtonElement;
  118. }(BaseElement);
  119. export default BaseButtonElement;