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

ios-slide-animator.js 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. import _extends from 'babel-runtime/helpers/extends';
  2. import _Object$getPrototypeOf from 'babel-runtime/core-js/object/get-prototype-of';
  3. import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
  4. import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
  5. import _createClass from 'babel-runtime/helpers/createClass';
  6. import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
  7. import _get from 'babel-runtime/helpers/get';
  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 IOSSwipeNavigatorAnimator from './ios-swipe-animator';
  22. import util from '../../ons/util';
  23. import animit from '../../ons/animit';
  24. import contentReady from '../../ons/content-ready';
  25. var translate3d = function translate3d() {
  26. var x = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
  27. var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  28. var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
  29. return 'translate3d(' + x + ', ' + y + ', ' + z + ')';
  30. };
  31. /**
  32. * Slide animator for navigator transition like iOS's screen slide transition.
  33. */
  34. var IOSSlideNavigatorAnimator = function (_IOSSwipeNavigatorAni) {
  35. _inherits(IOSSlideNavigatorAnimator, _IOSSwipeNavigatorAni);
  36. function IOSSlideNavigatorAnimator() {
  37. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  38. var _ref$timing = _ref.timing,
  39. timing = _ref$timing === undefined ? 'cubic-bezier(0.3, .4, 0, .9)' : _ref$timing,
  40. _ref$delay = _ref.delay,
  41. delay = _ref$delay === undefined ? 0 : _ref$delay,
  42. _ref$duration = _ref.duration,
  43. duration = _ref$duration === undefined ? 0.4 : _ref$duration,
  44. rest = _objectWithoutProperties(_ref, ['timing', 'delay', 'duration']);
  45. _classCallCheck(this, IOSSlideNavigatorAnimator);
  46. var _this = _possibleConstructorReturn(this, (IOSSlideNavigatorAnimator.__proto__ || _Object$getPrototypeOf(IOSSlideNavigatorAnimator)).call(this, _extends({ timing: timing, delay: delay, duration: duration }, rest)));
  47. _this.backgroundMask = util.createElement('<div style="position: absolute; width: 100%; height: 100%;' + 'background-color: black; z-index: 2"></div>');
  48. return _this;
  49. }
  50. _createClass(IOSSlideNavigatorAnimator, [{
  51. key: '_decompose',
  52. value: function _decompose(page) {
  53. var toolbar = page._getToolbarElement();
  54. var left = toolbar._getToolbarLeftItemsElement();
  55. var right = toolbar._getToolbarRightItemsElement();
  56. var excludeBackButton = function excludeBackButton(elements) {
  57. var result = [];
  58. for (var i = 0; i < elements.length; i++) {
  59. if (elements[i].nodeName.toLowerCase() !== 'ons-back-button') {
  60. result.push(elements[i]);
  61. }
  62. }
  63. return result;
  64. };
  65. var other = [].concat(left.children.length === 0 ? left : excludeBackButton(left.children)).concat(right.children.length === 0 ? right : excludeBackButton(right.children));
  66. return {
  67. toolbarCenter: toolbar._getToolbarCenterItemsElement(),
  68. backButtonIcon: toolbar._getToolbarBackButtonIconElement(),
  69. backButtonLabel: toolbar._getToolbarBackButtonLabelElement(),
  70. other: other,
  71. content: page._getContentElement(),
  72. background: page._getBackgroundElement(),
  73. toolbar: toolbar,
  74. bottomToolbar: page._getBottomToolbarElement()
  75. };
  76. }
  77. }, {
  78. key: '_shouldAnimateToolbar',
  79. value: function _shouldAnimateToolbar(enterPage, leavePage) {
  80. var toolbars = enterPage._canAnimateToolbar() && leavePage._canAnimateToolbar();
  81. var enterToolbar = enterPage._getToolbarElement();
  82. var leaveToolbar = leavePage._getToolbarElement();
  83. var isStatic = enterToolbar.hasAttribute('static') || leaveToolbar.hasAttribute('static');
  84. var isMaterial = util.hasModifier(enterToolbar, 'material') || util.hasModifier(leaveToolbar, 'material');
  85. var isTransparent = util.hasModifier(enterToolbar, 'transparent') || util.hasModifier(leaveToolbar, 'transparent');
  86. return toolbars && !isStatic && !isMaterial && !isTransparent;
  87. }
  88. }, {
  89. key: '_calculateDelta',
  90. value: function _calculateDelta(element, decomposition) {
  91. var title = void 0,
  92. label = void 0;
  93. var pageRect = element.getBoundingClientRect();
  94. if (decomposition.backButtonLabel.classList.contains('back-button__label')) {
  95. var labelRect = decomposition.backButtonLabel.getBoundingClientRect();
  96. title = Math.round(pageRect.width / 2 - labelRect.width / 2 - labelRect.left);
  97. } else {
  98. title = Math.round(pageRect.width / 2 * 0.6);
  99. }
  100. if (decomposition.backButtonIcon.classList.contains('back-button__icon')) {
  101. label = decomposition.backButtonIcon.getBoundingClientRect().right - 2;
  102. }
  103. return { title: title, label: label };
  104. }
  105. /**
  106. * @param {Object} enterPage
  107. * @param {Object} leavePage
  108. * @param {Function} callback
  109. */
  110. }, {
  111. key: 'push',
  112. value: function push(enterPage, leavePage, callback) {
  113. var _this2 = this;
  114. this.backgroundMask.remove();
  115. leavePage.parentNode.insertBefore(this.backgroundMask, leavePage);
  116. var unblock = _get(IOSSlideNavigatorAnimator.prototype.__proto__ || _Object$getPrototypeOf(IOSSlideNavigatorAnimator.prototype), 'block', this).call(this, enterPage);
  117. contentReady(enterPage, function () {
  118. var enterPageTarget = util.findToolbarPage(enterPage) || enterPage;
  119. var leavePageTarget = util.findToolbarPage(leavePage) || leavePage;
  120. var enterPageDecomposition = _this2._decompose(enterPageTarget);
  121. var leavePageDecomposition = _this2._decompose(leavePageTarget);
  122. var delta = _this2._calculateDelta(leavePage, enterPageDecomposition);
  123. var shouldAnimateToolbar = _this2._shouldAnimateToolbar(enterPageTarget, leavePageTarget);
  124. if (shouldAnimateToolbar) {
  125. animit.runAll(animit([enterPageDecomposition.content, enterPageDecomposition.bottomToolbar, enterPageDecomposition.background], _this2.def).default({ transform: translate3d('100%') }, { transform: translate3d() }), animit(enterPageDecomposition.toolbar, _this2.def).default({ opacity: 0 }, { opacity: 1 }), animit(enterPageDecomposition.toolbarCenter, _this2.def).default({ transform: translate3d('125%'), opacity: 1 }, { transform: translate3d(), opacity: 1 }), animit(enterPageDecomposition.backButtonLabel, _this2.def).default({ transform: translate3d(delta.title + 'px'), opacity: 0 }, {
  126. transform: translate3d(),
  127. opacity: 1,
  128. transition: 'opacity ' + _this2.duration + 's linear, transform ' + _this2.duration + 's ' + _this2.timing
  129. }), animit(enterPageDecomposition.other, _this2.def).default({ opacity: 0 }, { css: { opacity: 1 }, timing: 'linear' }), animit([leavePageDecomposition.content, leavePageDecomposition.bottomToolbar, leavePageDecomposition.background], _this2.def).default({ transform: translate3d(), opacity: 1 }, { transform: translate3d('-25%'), opacity: 0.9 }).queue(function (done) {
  130. _this2.backgroundMask.remove();
  131. unblock();
  132. callback();
  133. done();
  134. }), animit(leavePageDecomposition.toolbarCenter, _this2.def).default({ transform: translate3d(), opacity: 1 }, {
  135. transform: translate3d('-' + delta.title + 'px'),
  136. opacity: 0,
  137. transition: 'opacity ' + _this2.duration + 's linear, transform ' + _this2.duration + 's ' + _this2.timing
  138. }), animit(leavePageDecomposition.backButtonLabel, _this2.def).default({ transform: translate3d(), opacity: 1 }, { transform: translate3d('-' + delta.label + 'px'), opacity: 0 }), animit(leavePageDecomposition.other, _this2.def).default({ opacity: 1 }, { css: { opacity: 0 }, timing: 'linear' }));
  139. } else {
  140. animit.runAll(animit(enterPage, _this2.def).default({ transform: translate3d('100%') }, { transform: translate3d() }), animit(leavePage, _this2.def).default({ transform: translate3d(), opacity: 1 }, { transform: translate3d('-25%'), opacity: .9 }).queue(function (done) {
  141. _this2.backgroundMask.remove();
  142. unblock();
  143. callback();
  144. done();
  145. }));
  146. }
  147. });
  148. }
  149. /**
  150. * @param {Object} enterPage
  151. * @param {Object} leavePage
  152. * @param {Function} callback
  153. */
  154. }, {
  155. key: 'pop',
  156. value: function pop(enterPage, leavePage, callback) {
  157. var _this3 = this;
  158. if (this.isSwiping) {
  159. return this.popSwipe(enterPage, leavePage, callback);
  160. }
  161. this.backgroundMask.remove();
  162. enterPage.parentNode.insertBefore(this.backgroundMask, enterPage);
  163. var unblock = _get(IOSSlideNavigatorAnimator.prototype.__proto__ || _Object$getPrototypeOf(IOSSlideNavigatorAnimator.prototype), 'block', this).call(this, enterPage);
  164. var enterPageTarget = util.findToolbarPage(enterPage) || enterPage;
  165. var leavePageTarget = util.findToolbarPage(leavePage) || leavePage;
  166. var enterPageDecomposition = this._decompose(enterPageTarget);
  167. var leavePageDecomposition = this._decompose(leavePageTarget);
  168. var delta = this._calculateDelta(leavePage, leavePageDecomposition);
  169. var shouldAnimateToolbar = this._shouldAnimateToolbar(enterPageTarget, leavePageTarget);
  170. if (shouldAnimateToolbar) {
  171. animit.runAll(animit([enterPageDecomposition.content, enterPageDecomposition.bottomToolbar, enterPageDecomposition.background], this.def).default({ transform: translate3d('-25%'), opacity: .9 }, { transform: translate3d(), opacity: 1 }), animit(enterPageDecomposition.toolbarCenter, this.def).default({ transform: translate3d('-' + delta.title + 'px'), opacity: 0 }, {
  172. transform: translate3d(),
  173. opacity: 1,
  174. transition: 'opacity ' + this.duration + 's linear, transform ' + this.duration + 's ' + this.timing
  175. }), animit(enterPageDecomposition.backButtonLabel, this.def).default({ transform: translate3d('-' + delta.label + 'px') }, { transform: translate3d() }), animit(enterPageDecomposition.other, this.def).default({ opacity: 0 }, { css: { opacity: 1 }, timing: 'linear' }), animit([leavePageDecomposition.content, leavePageDecomposition.bottomToolbar, leavePageDecomposition.background], this.def).default({ transform: translate3d() }, { transform: translate3d('100%') }).wait(0).queue(function (done) {
  176. _this3.backgroundMask.remove();
  177. unblock();
  178. callback();
  179. done();
  180. }), animit(leavePageDecomposition.toolbar, this.def).default({ opacity: 1 }, { opacity: 0 }), animit(leavePageDecomposition.toolbarCenter, this.def).default({ transform: translate3d() }, { transform: translate3d('125%') }), animit(leavePageDecomposition.backButtonLabel, this.def).default({ transform: translate3d(), opacity: 1 }, {
  181. transform: translate3d(delta.title + 'px'),
  182. opacity: 0,
  183. transition: 'opacity ' + this.duration + 's linear, transform ' + this.duration + 's ' + this.timing
  184. }));
  185. } else {
  186. animit.runAll(animit(enterPage, this.def).default({ transform: translate3d('-25%'), opacity: .9 }, { transform: translate3d(), opacity: 1 }), animit(leavePage, this.def).default({ transform: translate3d() }, { transform: translate3d('100%') }).queue(function (done) {
  187. _this3.backgroundMask.remove();
  188. unblock();
  189. callback();
  190. done();
  191. }));
  192. }
  193. }
  194. }]);
  195. return IOSSlideNavigatorAnimator;
  196. }(IOSSwipeNavigatorAnimator);
  197. export default IOSSlideNavigatorAnimator;