SlideShowTransitionController.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2014, 2019
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['./SlideTransitionController', 'jquery', 'underscore', '../../util/AnimationHelper'], function (BaseClass, $, _, AnimationHelper) {
  8. var SlideShowTransitionController = BaseClass.extend({
  9. $fromShim: null,
  10. $toShim: null,
  11. $backdrop: null,
  12. _minScale: null,
  13. init: function init(options) {
  14. SlideShowTransitionController.inherited('init', this, arguments);
  15. this._minScale = options.minScale ? options.minScale : 0.7;
  16. },
  17. _beforeNext: function _beforeNext(from, to) {
  18. // z-index manipulations are necessary for navigation across the end-of-story boundary
  19. this.$fromShim = this._makeShim(from.$el).css(this._cssOnScreen).css({ 'z-index': 1 });
  20. from.$el.css(this._cssOnScreen).css({ 'z-index': 1 });
  21. this.$toShim = this._makeShim(to.$el).css(this._cssOnScreen).css({
  22. left: from.$el.width(),
  23. 'z-index': 2,
  24. opacity: 1
  25. });
  26. to.$el.css(this._cssOnScreen).css({
  27. left: from.$el.width(),
  28. 'z-index': 2,
  29. opacity: 1
  30. });
  31. this._showWidgets(to);
  32. this.$backdrop = $('<div class="animationBackdrop"/>').insertBefore(this.$fromShim);
  33. return SlideShowTransitionController.inherited('_beforeNext', this, arguments);
  34. },
  35. _next: function _next(from, to) {
  36. return Promise.all([this._scaleOut(from), this._slideIn(to)]);
  37. },
  38. _afterNext: function _afterNext(from, to) {
  39. this._hideWidgets(from);
  40. from.$el.css({ transform: AnimationHelper.SCALE_ZERO });
  41. this._cleanAnimationArtifacts(from, to);
  42. return SlideShowTransitionController.inherited('_afterNext', this, arguments);
  43. },
  44. _beforePrevious: function _beforePrevious(from, to) {
  45. // z-index manipulations are necessary for navigation across the end-of-story boundary
  46. this.$fromShim = this._makeShim(from.$el).css(this._cssOnScreen).css({ 'z-index': 1 });
  47. from.$el.css(this._cssOnScreen).css({ 'z-index': 1 });
  48. this.$toShim = this._makeShim(to.$el).css(this._cssOnScreen).css({
  49. 'z-index': 2,
  50. opacity: 0
  51. });
  52. to.$el.css(this._cssOnScreen).css({
  53. 'z-index': 2,
  54. opacity: 0
  55. });
  56. this._showWidgets(to);
  57. this.$backdrop = $('<div class="animationBackdrop"/>').insertBefore(this.$toShim);
  58. return SlideShowTransitionController.inherited('_beforePrevious', this, arguments);
  59. },
  60. _previous: function _previous(from, to) {
  61. return Promise.all([this._slideOut(from), this._scaleIn(to)]);
  62. },
  63. _afterPrevious: function _afterPrevious(from) {
  64. this._hideWidgets(from);
  65. from.$el.css({
  66. transform: AnimationHelper.SCALE_ZERO
  67. });
  68. this._cleanAnimationArtifacts();
  69. return SlideShowTransitionController.inherited('_afterPrevious', this, arguments);
  70. },
  71. // Animations
  72. _slideIn: function _slideIn(scene) {
  73. var _this = this;
  74. return new Promise(function (resolve) {
  75. scene.$el.addClass('slideShowSlide');
  76. _this._slideTo(_this.$toShim, '0px', function () {});
  77. _this._slideTo(scene.$el, '0px', function () {
  78. scene.$el.removeClass('slideShowSlide');
  79. resolve();
  80. });
  81. });
  82. },
  83. _slideOut: function _slideOut(scene) {
  84. var _this2 = this;
  85. return new Promise(function (resolve) {
  86. scene.$el.addClass('slideShowSlide');
  87. _this2._slideTo(_this2.$fromShim, scene.$el.width(), function () {});
  88. _this2._slideTo(scene.$el, scene.$el.width(), function () {
  89. scene.$el.removeClass('slideShowSlide');
  90. resolve();
  91. });
  92. });
  93. },
  94. _slideTo: function _slideTo($el, left, complete) {
  95. $el.animate({
  96. left: left
  97. }, {
  98. duration: this._duration,
  99. complete: complete,
  100. queue: false,
  101. easing: 'swing'
  102. });
  103. },
  104. _scaleIn: function _scaleIn(scene) {
  105. var _this3 = this;
  106. return new Promise(function (resolve) {
  107. scene.$el.addClass('slideShowScale');
  108. _this3._scaleInAnimation(_this3.$toShim, function () {});
  109. _this3._scaleInAnimation(scene.$el, function () {
  110. scene.$el.removeClass('slideShowScale');
  111. resolve();
  112. });
  113. });
  114. },
  115. _scaleInAnimation: function _scaleInAnimation($el, complete) {
  116. var minScale = this._minScale;
  117. $el.animate({
  118. transform: 1,
  119. opacity: 1
  120. }, {
  121. step: function step(now, fx) {
  122. if (fx.prop === 'transform') {
  123. $el.css({
  124. transform: 'scale(' + (now * (1 - minScale) + minScale) + ')'
  125. });
  126. }
  127. },
  128. duration: this._duration,
  129. complete: complete
  130. }, 'swing');
  131. },
  132. _scaleOut: function _scaleOut(scene) {
  133. var _this4 = this;
  134. return new Promise(function (resolve) {
  135. scene.$el.addClass('slideShowScale');
  136. _this4._scaleOutAnimation(_this4.$fromShim, function () {});
  137. _this4._scaleOutAnimation(scene.$el, function () {
  138. scene.$el.removeClass('slideShowScale');
  139. scene.$el.css({ opacity: 1 });
  140. resolve();
  141. });
  142. });
  143. },
  144. _scaleOutAnimation: function _scaleOutAnimation($el, complete) {
  145. var minScale = this._minScale;
  146. var duration = this._duration * 0.8;
  147. $el.delay(this._duration - duration).animate({
  148. transform: 1,
  149. opacity: 0
  150. }, {
  151. step: function step(now) {
  152. $el.css({
  153. transform: 'scale(' + (now * (1 - minScale) + minScale) + ')'
  154. });
  155. },
  156. duration: duration,
  157. complete: complete
  158. }, 'swing');
  159. },
  160. _makeShim: function _makeShim($el) {
  161. var $shimRoot = $('<div class="animationShim"/>');
  162. var parents = $el.parents('.contentViewPane *').get();
  163. var $shimTree = $shimRoot;
  164. _.each(parents.reverse(), function (parent) {
  165. var $clone = $(parent.cloneNode(false));
  166. $shimTree.append($clone);
  167. $shimTree = $clone;
  168. });
  169. $shimRoot.insertBefore($el);
  170. return $shimRoot;
  171. },
  172. _cleanAnimationArtifacts: function _cleanAnimationArtifacts(from, to) {
  173. if (from && from.$el) {
  174. from.$el.css({ 'z-index': '' });
  175. }
  176. if (to && to.$el) {
  177. to.$el.css({ 'z-index': '' });
  178. }
  179. if (this.$toShim) {
  180. this.$toShim.remove();
  181. this.$toShim = null;
  182. }
  183. if (this.$fromShim) {
  184. this.$fromShim.remove();
  185. this.$fromShim = null;
  186. }
  187. if (this.$backdrop) {
  188. this.$backdrop.remove();
  189. this.$backdrop = null;
  190. }
  191. }
  192. });
  193. return SlideShowTransitionController;
  194. });
  195. //# sourceMappingURL=SlideShowTransitionController.js.map