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

index.js 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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 AnimatorFactory from '../../ons/internal/animator-factory';
  23. import ToastAnimator from './animator';
  24. import FadeToastAnimator from './fade-animator';
  25. import AscendToastAnimator from './ascend-animator';
  26. import LiftToastAnimator from './lift-animator';
  27. import FallToastAnimator from './fall-animator';
  28. import platform from '../../ons/platform';
  29. import BaseDialogElement from '../base/base-dialog';
  30. import contentReady from '../../ons/content-ready';
  31. var scheme = {
  32. '.toast': 'toast--*',
  33. '.toast__message': 'toast--*__message',
  34. '.toast__button': 'toast--*__button'
  35. };
  36. var defaultClassName = 'toast';
  37. var _animatorDict = {
  38. 'default': platform.isAndroid() ? AscendToastAnimator : LiftToastAnimator,
  39. 'fade': FadeToastAnimator,
  40. 'ascend': AscendToastAnimator,
  41. 'lift': LiftToastAnimator,
  42. 'fall': FallToastAnimator,
  43. 'none': ToastAnimator
  44. };
  45. /**
  46. * @element ons-toast
  47. * @category dialog
  48. * @description
  49. * [en]
  50. * The Toast or Snackbar component is useful for displaying dismissable information or simple actions at (normally) the bottom of the page.
  51. *
  52. * This component does not block user input, allowing the app to continue its flow. For simple toasts, consider `ons.notification.toast` instead.
  53. * [/en]
  54. * [ja][/ja]
  55. * @tutorial vanilla/Reference/toast
  56. * @seealso ons-alert-dialog
  57. * [en]The `<ons-alert-dialog>` component is preferred for displaying undismissable information.[/en]
  58. * [ja][/ja]
  59. */
  60. var ToastElement = function (_BaseDialogElement) {
  61. _inherits(ToastElement, _BaseDialogElement);
  62. /**
  63. * @attribute animation
  64. * @type {String}
  65. * @default default
  66. * @description
  67. * [en]The animation used when showing and hiding the toast. Can be either `"default"`, `"ascend"` (Android), `"lift"` (iOS), `"fall"`, `"fade"` or `"none"`.[/en]
  68. * [ja][/ja]
  69. */
  70. /**
  71. * @attribute animation-options
  72. * @type {Expression}
  73. * @description
  74. * [en]Specify the animation's duration, timing and delay with an object literal. E.g. `{duration: 0.2, delay: 1, timing: 'ease-in'}`.[/en]
  75. * [ja]アニメーション時のduration, timing, delayをオブジェクトリテラルで指定します。e.g. <code>{duration: 0.2, delay: 1, timing: 'ease-in'}</code>[/ja]
  76. */
  77. function ToastElement() {
  78. _classCallCheck(this, ToastElement);
  79. var _this = _possibleConstructorReturn(this, (ToastElement.__proto__ || _Object$getPrototypeOf(ToastElement)).call(this));
  80. _this._defaultDBB = null;
  81. contentReady(_this, function () {
  82. return _this._compile();
  83. });
  84. return _this;
  85. }
  86. _createClass(ToastElement, [{
  87. key: '_updateAnimatorFactory',
  88. value: function _updateAnimatorFactory() {
  89. // Reset position style
  90. this._toast && (this._toast.style.top = this._toast.style.bottom = '');
  91. return new AnimatorFactory({
  92. animators: _animatorDict,
  93. baseClass: ToastAnimator,
  94. baseClassName: 'ToastAnimator',
  95. defaultAnimation: this.getAttribute('animation')
  96. });
  97. }
  98. /**
  99. * @property onDeviceBackButton
  100. * @type {Object}
  101. * @description
  102. * [en]Back-button handler.[/en]
  103. * [ja]バックボタンハンドラ。[/ja]
  104. */
  105. }, {
  106. key: '_compile',
  107. value: function _compile() {
  108. autoStyle.prepare(this);
  109. this.style.display = 'none';
  110. this.style.zIndex = 10000; // Lower than dialogs
  111. var messageClassName = 'toast__message';
  112. var buttonClassName = 'toast__button';
  113. var toast = util.findChild(this, '.' + defaultClassName);
  114. if (!toast) {
  115. toast = document.createElement('div');
  116. toast.classList.add(defaultClassName);
  117. while (this.childNodes[0]) {
  118. toast.appendChild(this.childNodes[0]);
  119. }
  120. }
  121. var button = util.findChild(toast, '.' + buttonClassName);
  122. if (!button) {
  123. button = util.findChild(toast, function (e) {
  124. return util.match(e, '.button') || util.match(e, 'button');
  125. });
  126. if (button) {
  127. button.classList.remove('button');
  128. button.classList.add(buttonClassName);
  129. toast.appendChild(button);
  130. }
  131. }
  132. if (!util.findChild(toast, '.' + messageClassName)) {
  133. var message = util.findChild(toast, '.message');
  134. if (!message) {
  135. message = document.createElement('div');
  136. for (var i = toast.childNodes.length - 1; i >= 0; i--) {
  137. if (toast.childNodes[i] !== button) {
  138. message.insertBefore(toast.childNodes[i], message.firstChild);
  139. }
  140. }
  141. }
  142. message.classList.add(messageClassName);
  143. toast.insertBefore(message, toast.firstChild);
  144. }
  145. if (toast.parentNode !== this) {
  146. this.appendChild(toast);
  147. }
  148. ModifierUtil.initModifier(this, this._scheme);
  149. }
  150. /**
  151. * @property visible
  152. * @readonly
  153. * @type {Boolean}
  154. * @description
  155. * [en]Whether the element is visible or not.[/en]
  156. * [ja]要素が見える場合に`true`。[/ja]
  157. */
  158. /**
  159. * @method show
  160. * @signature show([options])
  161. * @param {Object} [options]
  162. * [en]Parameter object.[/en]
  163. * [ja]オプションを指定するオブジェクト。[/ja]
  164. * @param {String} [options.animation]
  165. * [en]Animation name. Available animations are `"default"`, `"ascend"` (Android), `"lift"` (iOS), `"fall"`, `"fade"` or `"none"`.[/en]
  166. * [ja][/ja]
  167. * @param {String} [options.animationOptions]
  168. * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en]
  169. * [ja]アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: 'ease-in'}[/ja]
  170. * @description
  171. * [en]Show the element.[/en]
  172. * [ja][/ja]
  173. * @return {Promise}
  174. * [en]Resolves to the displayed element[/en]
  175. * [ja][/ja]
  176. */
  177. /**
  178. * @method toggle
  179. * @signature toggle([options])
  180. * @param {Object} [options]
  181. * [en]Parameter object.[/en]
  182. * [ja]オプションを指定するオブジェクト。[/ja]
  183. * @param {String} [options.animation]
  184. * [en]Animation name. Available animations are `"default"`, `"ascend"` (Android), `"lift"` (iOS), `"fall"`, `"fade"` or `"none"`.[/en]
  185. * [ja][/ja]
  186. * @param {String} [options.animationOptions]
  187. * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en]
  188. * [ja]アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: 'ease-in'}[/ja]
  189. * @description
  190. * [en]Toggle toast visibility.[/en]
  191. * [ja][/ja]
  192. */
  193. /**
  194. * @method hide
  195. * @signature hide([options])
  196. * @param {Object} [options]
  197. * [en]Parameter object.[/en]
  198. * [ja]オプションを指定するオブジェクト。[/ja]
  199. * @param {String} [options.animation]
  200. * [en]Animation name. Available animations are `"default"`, `"ascend"` (Android), `"lift"` (iOS), `"fall"`, `"fade"` or `"none"`.[/en]
  201. * [ja][/ja]
  202. * @param {String} [options.animationOptions]
  203. * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en]
  204. * [ja]アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: 'ease-in'}[/ja]
  205. * @description
  206. * [en]Hide toast.[/en]
  207. * [ja][/ja]
  208. * @return {Promise}
  209. * [en]Resolves to the hidden element[/en]
  210. * [ja][/ja]
  211. */
  212. /**
  213. * @param {String} name
  214. * @param {Function} Animator
  215. */
  216. }, {
  217. key: '_scheme',
  218. get: function get() {
  219. return scheme;
  220. }
  221. }, {
  222. key: '_toast',
  223. get: function get() {
  224. return util.findChild(this, '.' + defaultClassName);
  225. }
  226. }], [{
  227. key: 'registerAnimator',
  228. value: function registerAnimator(name, Animator) {
  229. if (!(Animator.prototype instanceof ToastAnimator)) {
  230. util.throw('"Animator" param must inherit OnsToastElement.ToastAnimator');
  231. }
  232. _animatorDict[name] = Animator;
  233. }
  234. }, {
  235. key: 'animators',
  236. get: function get() {
  237. return _animatorDict;
  238. }
  239. }, {
  240. key: 'ToastAnimator',
  241. get: function get() {
  242. return ToastAnimator;
  243. }
  244. }]);
  245. return ToastElement;
  246. }(BaseDialogElement);
  247. export default ToastElement;
  248. onsElements.Toast = ToastElement;
  249. customElements.define('ons-toast', ToastElement);