AnimatedPathSlideShowTransitionController.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: BI Cloud (C) Copyright IBM Corp. 2017
  5. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  6. */
  7. define(['../TransitionController', './TransitionDirector', '../../util/AnimationHelper'], function (BaseClass, TransitionDirector, AnimationHelper) {
  8. var AnimatedPathSlideShowTransitionController = BaseClass.extend({
  9. _duration: null,
  10. _cssOnScreen: {
  11. display: 'block',
  12. transform: 'scale(1)',
  13. position: 'absolute',
  14. top: '0px',
  15. bottom: '0px',
  16. left: '0px',
  17. right: '0px'
  18. },
  19. init: function init(options) {
  20. AnimatedPathSlideShowTransitionController.inherited('init', this, arguments);
  21. this._duration = options.duration ? options.duration : 100;
  22. this._timeline = options.timeline;
  23. },
  24. _beforeJump: function _beforeJump(from) {
  25. this._hideWidgets(from);
  26. return AnimatedPathSlideShowTransitionController.inherited('_beforeJump', this, arguments);
  27. },
  28. _jump: function _jump(from, to) {
  29. if (from && from.$el) {
  30. from.$el.css({
  31. transform: AnimationHelper.SCALE_ZERO
  32. }).attr('aria-hidden', 'true');
  33. }
  34. to.$el.css(this._cssOnScreen).css({ opacity: 1 }).addClass('selected').attr('aria-hidden', 'false');
  35. return AnimatedPathSlideShowTransitionController.inherited('_jump', this, arguments);
  36. },
  37. _afterJump: function _afterJump(from, to) {
  38. this._showWidgets(to);
  39. return AnimatedPathSlideShowTransitionController.inherited('_afterJump', this, arguments);
  40. },
  41. _beforeNext: function _beforeNext(from, to) {
  42. return Promise.try(function () {
  43. this._beforeJump(from, to);
  44. }.bind(this)).then(function () {
  45. to.$el.css(this._cssOnScreen).addClass('selected').attr('aria-hidden', 'false');
  46. return this._transitionWidgets(from, to);
  47. }.bind(this));
  48. },
  49. _next: function _next() {
  50. return AnimatedPathSlideShowTransitionController.inherited('_next', this, arguments);
  51. },
  52. _afterNext: function _afterNext(from, to) {
  53. from.$el.css({
  54. transform: AnimationHelper.SCALE_ZERO
  55. }).attr('aria-hidden', 'true');
  56. return this._restoreWidgets(from, to).then(this._afterJump.bind(this, from, to));
  57. },
  58. _beforePrevious: function _beforePrevious(from, to) {
  59. return this._beforeJump(from, to);
  60. },
  61. _previous: function _previous(from, to) {
  62. return this._jump(from, to);
  63. },
  64. _afterPrevious: function _afterPrevious(from, to) {
  65. return this._afterJump(from, to);
  66. },
  67. _transitionWidgets: function _transitionWidgets(view, target) {
  68. if (view && view.getLayoutView && target && target.getLayoutView) {
  69. this._transitionMap = this._timeline.getWidgetTransitionMap(view.getLayoutView(), target.getLayoutView());
  70. if (this._transitionMap) {
  71. var fromEvent = {
  72. current: view,
  73. to: target,
  74. linkIdMap: this._transitionMap
  75. };
  76. var toEvent = {
  77. current: target,
  78. from: view,
  79. linkIdMap: this._transitionMap
  80. };
  81. var layoutView = view.getLayoutView();
  82. if (layoutView && layoutView.model) {
  83. var rootLayout = view.getLayoutView().model.getTopLayoutModel();
  84. var director = new TransitionDirector({ rootLayout: rootLayout });
  85. var promises = [];
  86. promises = promises.concat(view.getLayoutView().reduce(director.getOnTransitionCallback(fromEvent)));
  87. promises = promises.concat(target.getLayoutView().reduce(director.getOnTransitionCallback(toEvent)));
  88. return Promise.all(promises);
  89. }
  90. }
  91. }
  92. return Promise.resolve();
  93. },
  94. _restoreWidgets: function _restoreWidgets(view, target) {
  95. if (view && view.getLayoutView && target && target.getLayoutView && this._transitionMap) {
  96. var fromEvent = {
  97. current: view,
  98. to: target,
  99. linkIdMap: this._transitionMap
  100. };
  101. var toEvent = {
  102. current: target,
  103. from: view,
  104. linkIdMap: this._transitionMap
  105. };
  106. this._transitionMap = null;
  107. var layoutView = view.getLayoutView();
  108. if (layoutView && layoutView.model) {
  109. var rootLayout = view.getLayoutView().model.getTopLayoutModel();
  110. var director = new TransitionDirector({ rootLayout: rootLayout });
  111. var promises = [];
  112. promises = promises.concat(view.getLayoutView().reduce(director.getAfterTransitionCallback(fromEvent)));
  113. promises = promises.concat(target.getLayoutView().reduce(director.getAfterTransitionCallback(toEvent)));
  114. return Promise.all(promises);
  115. }
  116. }
  117. return Promise.resolve();
  118. }
  119. });
  120. return AnimatedPathSlideShowTransitionController;
  121. });
  122. //# sourceMappingURL=AnimatedPathSlideShowTransitionController.js.map