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

index.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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 _createClass from 'babel-runtime/helpers/createClass';
  5. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  6. import _get from 'babel-runtime/helpers/get';
  7. import _inherits from 'babel-runtime/helpers/inherits';
  8. /*
  9. Copyright 2013-2015 ASIAL CORPORATION
  10. Licensed under the Apache License, Version 2.0 (the "License");
  11. you may not use this file except in compliance with the License.
  12. You may obtain a copy of the License at
  13. http://www.apache.org/licenses/LICENSE-2.0
  14. Unless required by applicable law or agreed to in writing, software
  15. distributed under the License is distributed on an "AS IS" BASIS,
  16. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. See the License for the specific language governing permissions and
  18. limitations under the License.
  19. */
  20. import onsElements from '../../ons/elements';
  21. import util from '../../ons/util';
  22. import ModifierUtil from '../../ons/internal/modifier-util';
  23. import AnimatorFactory from '../../ons/internal/animator-factory';
  24. import ModalAnimator from './animator';
  25. import FadeModalAnimator from './fade-animator';
  26. import LiftModalAnimator from './lift-animator';
  27. import platform from '../../ons/platform';
  28. import BaseDialogElement from '../base/base-dialog';
  29. import contentReady from '../../ons/content-ready';
  30. var scheme = {
  31. '': 'modal--*',
  32. 'modal__content': 'modal--*__content'
  33. };
  34. var defaultClassName = 'modal';
  35. var _animatorDict = {
  36. 'default': ModalAnimator,
  37. 'fade': FadeModalAnimator,
  38. 'lift': LiftModalAnimator,
  39. 'none': ModalAnimator
  40. };
  41. /**
  42. * @element ons-modal
  43. * @category dialog
  44. * @description
  45. * [en]
  46. * Modal component that masks current screen. Underlying components are not subject to any events while the modal component is shown.
  47. *
  48. * This component can be used to block user input while some operation is running or to show some information to the user.
  49. * [/en]
  50. * [ja]
  51. * 画面全体をマスクするモーダル用コンポーネントです。下側にあるコンポーネントは、
  52. * モーダルが表示されている間はイベント通知が行われません。
  53. * [/ja]
  54. * @seealso ons-dialog
  55. * [en]The `<ons-dialog>` component can be used to create a modal dialog.[/en]
  56. * [ja][/ja]
  57. * @codepen devIg
  58. * @tutorial vanilla/reference/modal
  59. * @example
  60. * <ons-modal id="modal">
  61. * Modal content
  62. * </ons-modal>
  63. * <script>
  64. * var modal = document.getElementById('modal');
  65. * modal.show();
  66. * </script>
  67. */
  68. var ModalElement = function (_BaseDialogElement) {
  69. _inherits(ModalElement, _BaseDialogElement);
  70. /**
  71. * @event preshow
  72. * @description
  73. * [en]Fired just before the modal is displayed.[/en]
  74. * [ja]モーダルが表示される直前に発火します。[/ja]
  75. * @param {Object} event [en]Event object.[/en]
  76. * @param {Object} event.modal
  77. * [en]Component object.[/en]
  78. * [ja]コンポーネントのオブジェクト。[/ja]
  79. * @param {Function} event.cancel
  80. * [en]Execute this function to stop the modal from being shown.[/en]
  81. * [ja]この関数を実行すると、ダイアログの表示がキャンセルされます。[/ja]
  82. */
  83. /**
  84. * @event postshow
  85. * @description
  86. * [en]Fired just after the modal is displayed.[/en]
  87. * [ja]モーダルが表示された直後に発火します。[/ja]
  88. * @param {Object} event [en]Event object.[/en]
  89. * @param {Object} event.modal
  90. * [en]Component object.[/en]
  91. * [ja]コンポーネントのオブジェクト。[/ja]
  92. */
  93. /**
  94. * @event prehide
  95. * @description
  96. * [en]Fired just before the modal is hidden.[/en]
  97. * [ja]モーダルが隠れる直前に発火します。[/ja]
  98. * @param {Object} event [en]Event object.[/en]
  99. * @param {Object} event.modal
  100. * [en]Component object.[/en]
  101. * [ja]コンポーネントのオブジェクト。[/ja]
  102. * @param {Function} event.cancel
  103. * [en]Execute this function to stop the modal from being hidden.[/en]
  104. * [ja]この関数を実行すると、ダイアログの非表示がキャンセルされます。[/ja]
  105. */
  106. /**
  107. * @event posthide
  108. * @description
  109. * [en]Fired just after the modal is hidden.[/en]
  110. * [ja]モーダルが隠れた後に発火します。[/ja]
  111. * @param {Object} event [en]Event object.[/en]
  112. * @param {Object} event.modal
  113. * [en]Component object.[/en]
  114. * [ja]コンポーネントのオブジェクト。[/ja]
  115. */
  116. /**
  117. * @attribute animation
  118. * @type {String}
  119. * @default default
  120. * @description
  121. * [en]The animation used when showing and hiding the modal. Can be either `"none"`, `"fade"` or `"lift"`.[/en]
  122. * [ja]モーダルを表示する際のアニメーション名を指定します。"none"もしくは"fade","lift"を指定できます。[/ja]
  123. */
  124. /**
  125. * @attribute animation-options
  126. * @type {Expression}
  127. * @description
  128. * [en]Specify the animation's duration, timing and delay with an object literal. E.g. `{duration: 0.2, delay: 1, timing: 'ease-in'}`.[/en]
  129. * [ja]アニメーション時のduration, timing, delayをオブジェクトリテラルで指定します。e.g. <code>{duration: 0.2, delay: 1, timing: 'ease-in'}</code>[/ja]
  130. */
  131. function ModalElement() {
  132. _classCallCheck(this, ModalElement);
  133. var _this = _possibleConstructorReturn(this, (ModalElement.__proto__ || _Object$getPrototypeOf(ModalElement)).call(this));
  134. _this._defaultDBB = function () {
  135. return undefined;
  136. };
  137. contentReady(_this, function () {
  138. return _this._compile();
  139. });
  140. return _this;
  141. }
  142. _createClass(ModalElement, [{
  143. key: '_updateAnimatorFactory',
  144. value: function _updateAnimatorFactory() {
  145. return new AnimatorFactory({
  146. animators: _animatorDict,
  147. baseClass: ModalAnimator,
  148. baseClassName: 'ModalAnimator',
  149. defaultAnimation: this.getAttribute('animation')
  150. });
  151. }
  152. /**
  153. * @property onDeviceBackButton
  154. * @type {Object}
  155. * @description
  156. * [en]Back-button handler.[/en]
  157. * [ja]バックボタンハンドラ。[/ja]
  158. */
  159. }, {
  160. key: '_compile',
  161. value: function _compile() {
  162. this.style.display = 'none';
  163. this.style.zIndex = 10001;
  164. this.classList.add(defaultClassName);
  165. if (!util.findChild(this, '.modal__content')) {
  166. var content = document.createElement('div');
  167. content.classList.add('modal__content');
  168. while (this.childNodes[0]) {
  169. var node = this.childNodes[0];
  170. this.removeChild(node);
  171. content.insertBefore(node, null);
  172. }
  173. this.appendChild(content);
  174. }
  175. ModifierUtil.initModifier(this, this._scheme);
  176. }
  177. }, {
  178. key: '_toggleStyle',
  179. value: function _toggleStyle(shouldShow) {
  180. this.style.display = shouldShow ? 'table' : 'none';
  181. }
  182. }, {
  183. key: 'connectedCallback',
  184. value: function connectedCallback() {
  185. _get(ModalElement.prototype.__proto__ || _Object$getPrototypeOf(ModalElement.prototype), 'connectedCallback', this).call(this);
  186. }
  187. }, {
  188. key: 'disconnectedCallback',
  189. value: function disconnectedCallback() {
  190. _get(ModalElement.prototype.__proto__ || _Object$getPrototypeOf(ModalElement.prototype), 'disconnectedCallback', this).call(this);
  191. }
  192. /**
  193. * @property visible
  194. * @readonly
  195. * @type {Boolean}
  196. * @description
  197. * [en]Whether the element is visible or not.[/en]
  198. * [ja]要素が見える場合に`true`。[/ja]
  199. */
  200. /**
  201. * @method show
  202. * @signature show([options])
  203. * @param {Object} [options]
  204. * [en]Parameter object.[/en]
  205. * [ja]オプションを指定するオブジェクト。[/ja]
  206. * @param {String} [options.animation]
  207. * [en]Animation name. Available animations are `"none"` and `"fade"`.[/en]
  208. * [ja]アニメーション名を指定します。"none", "fade"のいずれかを指定します。[/ja]
  209. * @param {String} [options.animationOptions]
  210. * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en]
  211. * [ja]アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: 'ease-in'}[/ja]
  212. * @param {Function} [options.callback]
  213. * [en]This function is called after the modal has been revealed.[/en]
  214. * [ja]モーダルが表示され終わった後に呼び出される関数オブジェクトを指定します。[/ja]
  215. * @description
  216. * [en]Show modal.[/en]
  217. * [ja]モーダルを表示します。[/ja]
  218. * @return {Promise}
  219. * [en]Resolves to the displayed element[/en]
  220. * [ja][/ja]
  221. */
  222. /**
  223. * @method toggle
  224. * @signature toggle([options])
  225. * @param {Object} [options]
  226. * [en]Parameter object.[/en]
  227. * [ja]オプションを指定するオブジェクト。[/ja]
  228. * @param {String} [options.animation]
  229. * [en]Animation name. Available animations are `"none"` and `"fade"`.[/en]
  230. * [ja]アニメーション名を指定します。"none", "fade"のいずれかを指定します。[/ja]
  231. * @param {String} [options.animationOptions]
  232. * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en]
  233. * [ja]アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: 'ease-in'}[/ja]
  234. * @param {Function} [options.callback]
  235. * [en]This function is called after the modal has been revealed.[/en]
  236. * [ja]モーダルが表示され終わった後に呼び出される関数オブジェクトを指定します。[/ja]
  237. * @description
  238. * [en]Toggle modal visibility.[/en]
  239. * [ja]モーダルの表示を切り替えます。[/ja]
  240. */
  241. /**
  242. * @method hide
  243. * @signature hide([options])
  244. * @param {Object} [options]
  245. * [en]Parameter object.[/en]
  246. * [ja]オプションを指定するオブジェクト。[/ja]
  247. * @param {String} [options.animation]
  248. * [en]Animation name. Available animations are `"none"` and `"fade"`.[/en]
  249. * [ja]アニメーション名を指定します。"none", "fade"のいずれかを指定します。[/ja]
  250. * @param {String} [options.animationOptions]
  251. * [en]Specify the animation's duration, delay and timing. E.g. `{duration: 0.2, delay: 0.4, timing: 'ease-in'}`.[/en]
  252. * [ja]アニメーション時のduration, delay, timingを指定します。e.g. {duration: 0.2, delay: 0.4, timing: 'ease-in'}[/ja]
  253. * @param {Function} [options.callback]
  254. * [en]This function is called after the modal has been revealed.[/en]
  255. * [ja]モーダルが表示され終わった後に呼び出される関数オブジェクトを指定します。[/ja]
  256. * @description
  257. * [en]Hide modal.[/en]
  258. * [ja]モーダルを非表示にします。[/ja]
  259. * @return {Promise}
  260. * [en]Resolves to the hidden element[/en]
  261. * [ja][/ja]
  262. */
  263. }, {
  264. key: 'attributeChangedCallback',
  265. value: function attributeChangedCallback(name, last, current) {
  266. if (name === 'class') {
  267. util.restoreClass(this, defaultClassName, scheme);
  268. } else {
  269. _get(ModalElement.prototype.__proto__ || _Object$getPrototypeOf(ModalElement.prototype), 'attributeChangedCallback', this).call(this, name, last, current);
  270. }
  271. }
  272. /**
  273. * @param {String} name
  274. * @param {Function} Animator
  275. */
  276. }, {
  277. key: '_scheme',
  278. get: function get() {
  279. return scheme;
  280. }
  281. }], [{
  282. key: 'registerAnimator',
  283. value: function registerAnimator(name, Animator) {
  284. if (!(Animator.prototype instanceof ModalAnimator)) {
  285. util.throwAnimator('Modal');
  286. }
  287. _animatorDict[name] = Animator;
  288. }
  289. }, {
  290. key: 'observedAttributes',
  291. get: function get() {
  292. return [].concat(_toConsumableArray(_get(ModalElement.__proto__ || _Object$getPrototypeOf(ModalElement), 'observedAttributes', this)), ['class']);
  293. }
  294. }, {
  295. key: 'animators',
  296. get: function get() {
  297. return _animatorDict;
  298. }
  299. }, {
  300. key: 'ModalAnimator',
  301. get: function get() {
  302. return ModalAnimator;
  303. }
  304. }]);
  305. return ModalElement;
  306. }(BaseDialogElement);
  307. export default ModalElement;
  308. onsElements.Modal = ModalElement;
  309. customElements.define('ons-modal', ModalElement);