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

base-dialog.js 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import _Promise from 'babel-runtime/core-js/promise';
  2. import _defineProperty from 'babel-runtime/helpers/defineProperty';
  3. import _extends from 'babel-runtime/helpers/extends';
  4. import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
  5. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  6. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  7. import _createClass from 'babel-runtime/helpers/createClass';
  8. import _inherits from 'babel-runtime/helpers/inherits';
  9. /*
  10. Copyright 2013-2015 ASIAL CORPORATION
  11. Licensed under the Apache License, Version 2.0 (the "License");
  12. you may not use this file except in compliance with the License.
  13. You may obtain a copy of the License at
  14. http://www.apache.org/licenses/LICENSE-2.0
  15. Unless required by applicable law or agreed to in writing, software
  16. distributed under the License is distributed on an "AS IS" BASIS,
  17. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. See the License for the specific language governing permissions and
  19. limitations under the License.
  20. */
  21. import util from '../../ons/util';
  22. import BaseElement from './base-element';
  23. import ModifierUtil from '../../ons/internal/modifier-util';
  24. import AnimatorFactory from '../../ons/internal/animator-factory';
  25. import DoorLock from '../../ons/doorlock';
  26. import deviceBackButtonDispatcher from '../../ons/internal/device-back-button-dispatcher';
  27. import contentReady from '../../ons/content-ready';
  28. var BaseDialogElement = function (_BaseElement) {
  29. _inherits(BaseDialogElement, _BaseElement);
  30. _createClass(BaseDialogElement, [{
  31. key: '_updateAnimatorFactory',
  32. value: function _updateAnimatorFactory() {
  33. util.throwMember();
  34. }
  35. }, {
  36. key: '_toggleStyle',
  37. value: function _toggleStyle(shouldShow) {
  38. this.style.display = shouldShow ? 'block' : 'none';
  39. }
  40. }, {
  41. key: '_scheme',
  42. get: function get() {
  43. util.throwMember();
  44. }
  45. }]);
  46. function BaseDialogElement() {
  47. _classCallCheck(this, BaseDialogElement);
  48. var _this = _possibleConstructorReturn(this, (BaseDialogElement.__proto__ || _Object$getPrototypeOf(BaseDialogElement)).call(this));
  49. if (_this.constructor === BaseDialogElement) {
  50. util.throwAbstract();
  51. }
  52. _this._visible = false;
  53. _this._doorLock = new DoorLock();
  54. _this._cancel = _this._cancel.bind(_this);
  55. _this._selfCamelName = util.camelize(_this.tagName.slice(4));
  56. _this._defaultDBB = function (e) {
  57. return _this.cancelable ? _this._cancel() : e.callParentHandler();
  58. };
  59. _this._animatorFactory = _this._updateAnimatorFactory();
  60. return _this;
  61. }
  62. _createClass(BaseDialogElement, [{
  63. key: '_cancel',
  64. value: function _cancel() {
  65. var _this2 = this;
  66. if (this.cancelable && !this._running) {
  67. this._running = true;
  68. this.hide().then(function () {
  69. _this2._running = false;
  70. util.triggerElementEvent(_this2, 'dialog-cancel');
  71. }, function () {
  72. return _this2._running = false;
  73. });
  74. }
  75. }
  76. }, {
  77. key: 'show',
  78. value: function show() {
  79. for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
  80. args[_key] = arguments[_key];
  81. }
  82. return this._setVisible.apply(this, [true].concat(args));
  83. }
  84. }, {
  85. key: 'hide',
  86. value: function hide() {
  87. for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
  88. args[_key2] = arguments[_key2];
  89. }
  90. return this._setVisible.apply(this, [false].concat(args));
  91. }
  92. }, {
  93. key: 'toggle',
  94. value: function toggle() {
  95. for (var _len3 = arguments.length, args = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
  96. args[_key3] = arguments[_key3];
  97. }
  98. return this._setVisible.apply(this, [!this.visible].concat(args));
  99. }
  100. }, {
  101. key: '_setVisible',
  102. value: function _setVisible(shouldShow) {
  103. var _util$triggerElementE,
  104. _this3 = this;
  105. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  106. var action = shouldShow ? 'show' : 'hide';
  107. options = _extends({}, options);
  108. options.animationOptions = util.extend(options.animationOptions || {}, AnimatorFactory.parseAnimationOptionsString(this.getAttribute('animation-options')));
  109. var canceled = false;
  110. util.triggerElementEvent(this, 'pre' + action, (_util$triggerElementE = {}, _defineProperty(_util$triggerElementE, this._selfCamelName, this), _defineProperty(_util$triggerElementE, 'cancel', function cancel() {
  111. return canceled = true;
  112. }), _util$triggerElementE));
  113. if (canceled) {
  114. return _Promise.reject('Canceled in pre' + action + ' event.');
  115. }
  116. return new _Promise(function (resolve) {
  117. _this3._doorLock.waitUnlock(function () {
  118. var unlock = _this3._doorLock.lock();
  119. var animator = _this3._animatorFactory.newAnimator(options);
  120. shouldShow && _this3._toggleStyle(true, options);
  121. _this3._visible = shouldShow;
  122. util.iosPageScrollFix(shouldShow);
  123. contentReady(_this3, function () {
  124. animator[action](_this3, function () {
  125. !shouldShow && _this3._toggleStyle(false, options);
  126. unlock();
  127. util.propagateAction(_this3, '_' + action);
  128. util.triggerElementEvent(_this3, 'post' + action, _defineProperty({}, _this3._selfCamelName, _this3)); // postshow posthide
  129. if (options.callback instanceof Function) {
  130. options.callback(_this3);
  131. }
  132. resolve(_this3);
  133. });
  134. });
  135. });
  136. });
  137. }
  138. }, {
  139. key: '_updateMask',
  140. value: function _updateMask() {
  141. var _this4 = this;
  142. contentReady(this, function () {
  143. if (_this4._mask && _this4.getAttribute('mask-color')) {
  144. _this4._mask.style.backgroundColor = _this4.getAttribute('mask-color');
  145. }
  146. });
  147. }
  148. }, {
  149. key: 'connectedCallback',
  150. value: function connectedCallback() {
  151. var _this5 = this;
  152. if (typeof this._defaultDBB === 'function') {
  153. this.onDeviceBackButton = this._defaultDBB.bind(this);
  154. }
  155. contentReady(this, function () {
  156. if (_this5._mask) {
  157. _this5._mask.addEventListener('click', _this5._cancel, false);
  158. util.iosMaskScrollFix(_this5._mask, true);
  159. }
  160. });
  161. }
  162. }, {
  163. key: 'disconnectedCallback',
  164. value: function disconnectedCallback() {
  165. if (this._backButtonHandler) {
  166. this._backButtonHandler.destroy();
  167. this._backButtonHandler = null;
  168. }
  169. if (this._mask) {
  170. this._mask.removeEventListener('click', this._cancel, false);
  171. util.iosMaskScrollFix(this._mask, false);
  172. }
  173. }
  174. }, {
  175. key: 'attributeChangedCallback',
  176. value: function attributeChangedCallback(name, last, current) {
  177. switch (name) {
  178. case 'modifier':
  179. ModifierUtil.onModifierChanged(last, current, this, this._scheme);
  180. break;
  181. case 'animation':
  182. this._animatorFactory = this._updateAnimatorFactory();
  183. break;
  184. case 'mask-color':
  185. this._updateMask();
  186. break;
  187. }
  188. }
  189. }, {
  190. key: 'onDeviceBackButton',
  191. get: function get() {
  192. return this._backButtonHandler;
  193. },
  194. set: function set(callback) {
  195. if (this._backButtonHandler) {
  196. this._backButtonHandler.destroy();
  197. }
  198. this._backButtonHandler = deviceBackButtonDispatcher.createHandler(this, callback);
  199. }
  200. }, {
  201. key: 'visible',
  202. get: function get() {
  203. return this._visible;
  204. }
  205. }, {
  206. key: 'disabled',
  207. set: function set(value) {
  208. return util.toggleAttribute(this, 'disabled', value);
  209. },
  210. get: function get() {
  211. return this.hasAttribute('disabled');
  212. }
  213. }, {
  214. key: 'cancelable',
  215. set: function set(value) {
  216. return util.toggleAttribute(this, 'cancelable', value);
  217. },
  218. get: function get() {
  219. return this.hasAttribute('cancelable');
  220. }
  221. }], [{
  222. key: 'observedAttributes',
  223. get: function get() {
  224. return ['modifier', 'animation', 'mask-color'];
  225. }
  226. }, {
  227. key: 'events',
  228. get: function get() {
  229. return ['preshow', 'postshow', 'prehide', 'posthide', 'dialog-cancel'];
  230. }
  231. }]);
  232. return BaseDialogElement;
  233. }(BaseElement);
  234. export default BaseDialogElement;