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

animator.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 _inherits from 'babel-runtime/helpers/inherits';
  7. /*
  8. Copyright 2013-2018 ASIAL CORPORATION
  9. Licensed under the Apache License, Version 2.0 (the "License");
  10. you may not use this file except in compliance with the License.
  11. You may obtain a copy of the License at
  12. http://www.apache.org/licenses/LICENSE-2.0
  13. Unless required by applicable law or agreed to in writing, software
  14. distributed under the License is distributed on an "AS IS" BASIS,
  15. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. See the License for the specific language governing permissions and
  17. limitations under the License.
  18. */
  19. import animit from '../../ons/animit';
  20. import BaseAnimator from '../../ons/base-animator';
  21. export var ListItemAnimator = function (_BaseAnimator) {
  22. _inherits(ListItemAnimator, _BaseAnimator);
  23. function ListItemAnimator() {
  24. var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
  25. _ref$timing = _ref.timing,
  26. timing = _ref$timing === undefined ? 'linear' : _ref$timing,
  27. _ref$delay = _ref.delay,
  28. delay = _ref$delay === undefined ? 0 : _ref$delay,
  29. _ref$duration = _ref.duration,
  30. duration = _ref$duration === undefined ? 0.2 : _ref$duration;
  31. _classCallCheck(this, ListItemAnimator);
  32. return _possibleConstructorReturn(this, (ListItemAnimator.__proto__ || _Object$getPrototypeOf(ListItemAnimator)).call(this, { timing: timing, delay: delay, duration: duration }));
  33. }
  34. _createClass(ListItemAnimator, [{
  35. key: 'showExpansion',
  36. value: function showExpansion(listItem, callback) {
  37. callback();
  38. }
  39. }, {
  40. key: 'hideExpansion',
  41. value: function hideExpansion(listItem, callback) {
  42. callback();
  43. }
  44. }]);
  45. return ListItemAnimator;
  46. }(BaseAnimator);
  47. export var SlideListItemAnimator = function (_ListItemAnimator) {
  48. _inherits(SlideListItemAnimator, _ListItemAnimator);
  49. function SlideListItemAnimator() {
  50. _classCallCheck(this, SlideListItemAnimator);
  51. return _possibleConstructorReturn(this, (SlideListItemAnimator.__proto__ || _Object$getPrototypeOf(SlideListItemAnimator)).apply(this, arguments));
  52. }
  53. _createClass(SlideListItemAnimator, [{
  54. key: 'showExpansion',
  55. value: function showExpansion(listItem, callback) {
  56. this._animateExpansion(listItem, true, callback);
  57. }
  58. }, {
  59. key: 'hideExpansion',
  60. value: function hideExpansion(listItem, callback) {
  61. this._animateExpansion(listItem, false, callback);
  62. }
  63. }, {
  64. key: '_animateExpansion',
  65. value: function _animateExpansion(listItem, shouldOpen, callback) {
  66. var _animit;
  67. // To animate the opening of the expansion panel correctly, we need to know its
  68. // height. To calculate this, we set its height to auto, and then get the computed
  69. // height and padding. Once this is done, we set the height back to its original value.
  70. var oldHeight = listItem.expandableContent.style.height;
  71. var oldDisplay = listItem.expandableContent.style.display;
  72. listItem.expandableContent.style.height = 'auto';
  73. listItem.expandableContent.style.display = 'block';
  74. var computedStyle = window.getComputedStyle(listItem.expandableContent);
  75. var expansionOpenTransition = [{ height: 0, paddingTop: 0, paddingBottom: 0 }, {
  76. height: computedStyle.height,
  77. paddingTop: computedStyle.paddingTop,
  78. paddingBottom: computedStyle.paddingBottom
  79. }];
  80. var iconOpenTransition = [{ transform: 'rotate(45deg)' }, { transform: 'rotate(225deg)' }];
  81. // Now that we have the values we need, reset the height back to its original state
  82. listItem.expandableContent.style.height = oldHeight;
  83. (_animit = animit(listItem.expandableContent, { duration: this.duration, property: 'height padding-top padding-bottom' })).default.apply(_animit, _toConsumableArray(shouldOpen ? expansionOpenTransition : expansionOpenTransition.reverse())).play(function () {
  84. listItem.expandableContent.style.display = oldDisplay;
  85. callback && callback();
  86. });
  87. if (listItem.expandChevron) {
  88. var _animit2;
  89. (_animit2 = animit(listItem.expandChevron, { duration: this.duration, property: 'transform' })).default.apply(_animit2, _toConsumableArray(shouldOpen ? iconOpenTransition : iconOpenTransition.reverse())).play();
  90. }
  91. }
  92. }]);
  93. return SlideListItemAnimator;
  94. }(ListItemAnimator);