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

ons-progress-bar.js 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
  2. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  3. import _createClass from 'babel-runtime/helpers/createClass';
  4. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  5. import _inherits from 'babel-runtime/helpers/inherits';
  6. /*
  7. Copyright 2013-2015 ASIAL CORPORATION
  8. Licensed under the Apache License, Version 2.0 (the "License");
  9. you may not use this file except in compliance with the License.
  10. You may obtain a copy of the License at
  11. http://www.apache.org/licenses/LICENSE-2.0
  12. Unless required by applicable law or agreed to in writing, software
  13. distributed under the License is distributed on an "AS IS" BASIS,
  14. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. See the License for the specific language governing permissions and
  16. limitations under the License.
  17. */
  18. import onsElements from '../ons/elements';
  19. import util from '../ons/util';
  20. import autoStyle from '../ons/autostyle';
  21. import ModifierUtil from '../ons/internal/modifier-util';
  22. import BaseElement from './base/base-element';
  23. import contentReady from '../ons/content-ready';
  24. var scheme = {
  25. '.progress-bar': 'progress-bar--*',
  26. '.progress-bar__primary': 'progress-bar--*__primary',
  27. '.progress-bar__secondary': 'progress-bar--*__secondary'
  28. };
  29. var template = util.createElement('\n <div class="progress-bar">\n <div class="progress-bar__secondary"></div>\n <div class="progress-bar__primary"></div>\n </div>\n');
  30. var INDET = 'indeterminate';
  31. /**
  32. * @element ons-progress-bar
  33. * @category visual
  34. * @modifier material
  35. * [en]Display a Material Design progress bar.[/en]
  36. * [ja]マテリアルデザインのスタイルでプログレスバーを表示します。[/ja]
  37. * @description
  38. * [en]
  39. * The component is used to display a linear progress bar. It can either display a progress bar that shows the user how much of a task has been completed. In the case where the percentage is not known it can be used to display an animated progress bar so the user can see that an operation is in progress.
  40. * [/en]
  41. * [ja][/ja]
  42. * @codepen zvQbGj
  43. * @tutorial vanilla/Reference/progress
  44. * @seealso ons-progress-circular
  45. * [en]The `<ons-progress-circular>` component displays a circular progress indicator.[/en]
  46. * [ja][/ja]
  47. * @example
  48. * <ons-progress-bar
  49. * value="55"
  50. * secondary-value="87">
  51. * </ons-progress-bar>
  52. *
  53. * <ons-progress-bar
  54. * indeterminate>
  55. * </ons-progress-bar>
  56. */
  57. var ProgressBarElement = function (_BaseElement) {
  58. _inherits(ProgressBarElement, _BaseElement);
  59. /**
  60. * @attribute modifier
  61. * @type {String}
  62. * @description
  63. * [en]Change the appearance of the progress indicator.[/en]
  64. * [ja]プログレスインジケータの見た目を変更します。[/ja]
  65. */
  66. /**
  67. * @attribute value
  68. * @type {Number}
  69. * @description
  70. * [en]Current progress. Should be a value between 0 and 100.[/en]
  71. * [ja]現在の進行状況の値を指定します。0から100の間の値を指定して下さい。[/ja]
  72. */
  73. /**
  74. * @attribute secondary-value
  75. * @type {Number}
  76. * @description
  77. * [en]Current secondary progress. Should be a value between 0 and 100.[/en]
  78. * [ja]現在の2番目の進行状況の値を指定します。0から100の間の値を指定して下さい。[/ja]
  79. */
  80. /**
  81. * @attribute indeterminate
  82. * @description
  83. * [en]If this attribute is set, an infinite looping animation will be shown.[/en]
  84. * [ja]この属性が設定された場合、ループするアニメーションが表示されます。[/ja]
  85. */
  86. function ProgressBarElement() {
  87. _classCallCheck(this, ProgressBarElement);
  88. var _this = _possibleConstructorReturn(this, (ProgressBarElement.__proto__ || _Object$getPrototypeOf(ProgressBarElement)).call(this));
  89. contentReady(_this, function () {
  90. return _this._compile();
  91. });
  92. return _this;
  93. }
  94. _createClass(ProgressBarElement, [{
  95. key: '_compile',
  96. value: function _compile() {
  97. if (!this._isCompiled()) {
  98. this._template = template.cloneNode(true);
  99. } else {
  100. this._template = util.findChild(this, '.progress-bar');
  101. }
  102. this._primary = util.findChild(this._template, '.progress-bar__primary');
  103. this._secondary = util.findChild(this._template, '.progress-bar__secondary');
  104. this._updateDeterminate();
  105. this._updateValue();
  106. this.appendChild(this._template);
  107. autoStyle.prepare(this);
  108. ModifierUtil.initModifier(this, scheme);
  109. }
  110. }, {
  111. key: '_isCompiled',
  112. value: function _isCompiled() {
  113. if (!util.findChild(this, '.progress-bar')) {
  114. return false;
  115. }
  116. var barElement = util.findChild(this, '.progress-bar');
  117. if (!util.findChild(barElement, '.progress-bar__secondary')) {
  118. return false;
  119. }
  120. if (!util.findChild(barElement, '.progress-bar__primary')) {
  121. return false;
  122. }
  123. return true;
  124. }
  125. }, {
  126. key: 'attributeChangedCallback',
  127. value: function attributeChangedCallback(name, last, current) {
  128. if (name === 'modifier') {
  129. ModifierUtil.onModifierChanged(last, current, this, scheme);
  130. this.hasAttribute(INDET) && this._updateDeterminate();
  131. } else if (name === 'value' || name === 'secondary-value') {
  132. this._updateValue();
  133. } else if (name === INDET) {
  134. this._updateDeterminate();
  135. }
  136. }
  137. }, {
  138. key: '_updateDeterminate',
  139. value: function _updateDeterminate() {
  140. var _this2 = this;
  141. contentReady(this, function () {
  142. return util.toggleModifier(_this2, INDET, { force: _this2.hasAttribute(INDET) });
  143. });
  144. }
  145. }, {
  146. key: '_updateValue',
  147. value: function _updateValue() {
  148. var _this3 = this;
  149. contentReady(this, function () {
  150. _this3._primary.style.width = _this3.hasAttribute('value') ? _this3.getAttribute('value') + '%' : '0%';
  151. _this3._secondary.style.width = _this3.hasAttribute('secondary-value') ? _this3.getAttribute('secondary-value') + '%' : '0%';
  152. });
  153. }
  154. /**
  155. * @property value
  156. * @type {Number}
  157. * @description
  158. * [en]Current progress. Should be a value between 0 and 100.[/en]
  159. * [ja]現在の進行状況の値を指定します。0から100の間の値を指定して下さい。[/ja]
  160. */
  161. }, {
  162. key: 'value',
  163. set: function set(value) {
  164. if (typeof value !== 'number' || value < 0 || value > 100) {
  165. util.throw('Invalid value');
  166. }
  167. this.setAttribute('value', Math.floor(value));
  168. },
  169. get: function get() {
  170. return parseInt(this.getAttribute('value') || '0');
  171. }
  172. /**
  173. * @property secondaryValue
  174. * @type {Number}
  175. * @description
  176. * [en]Current secondary progress. Should be a value between 0 and 100.[/en]
  177. * [ja]現在の2番目の進行状況の値を指定します。0から100の間の値を指定して下さい。[/ja]
  178. */
  179. }, {
  180. key: 'secondaryValue',
  181. set: function set(value) {
  182. if (typeof value !== 'number' || value < 0 || value > 100) {
  183. util.throw('Invalid value');
  184. }
  185. this.setAttribute('secondary-value', Math.floor(value));
  186. },
  187. get: function get() {
  188. return parseInt(this.getAttribute('secondary-value') || '0');
  189. }
  190. /**
  191. * @property indeterminate
  192. * @type {Boolean}
  193. * @description
  194. * [en]If this property is `true`, an infinite looping animation will be shown.[/en]
  195. * [ja]この属性が設定された場合、ループするアニメーションが表示されます。[/ja]
  196. */
  197. }, {
  198. key: 'indeterminate',
  199. set: function set(value) {
  200. if (value) {
  201. this.setAttribute(INDET, '');
  202. } else {
  203. this.removeAttribute(INDET);
  204. }
  205. },
  206. get: function get() {
  207. return this.hasAttribute(INDET);
  208. }
  209. }], [{
  210. key: 'observedAttributes',
  211. get: function get() {
  212. return ['modifier', 'value', 'secondary-value', INDET];
  213. }
  214. }]);
  215. return ProgressBarElement;
  216. }(BaseElement);
  217. export default ProgressBarElement;
  218. onsElements.ProgressBar = ProgressBarElement;
  219. customElements.define('ons-progress-bar', ProgressBarElement);