TransitionController.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. 'use strict';
  2. /**
  3. * Licensed Materials - Property of IBM
  4. * IBM Cognos Products: Storytelling
  5. * (C) Copyright IBM Corp. 2014, 2018
  6. * US Government Users Restricted Rights - Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  7. */
  8. define(['baglass/core-client/js/core-client/ui/core/Class', 'underscore'], function (Class, _) {
  9. /**
  10. * Base controller for scene transitions.
  11. * Rejects calls while transitions are in progress.
  12. * Subclasses override '_next' and '_previous' to perform transitions
  13. */
  14. var TransitionController = Class.extend({
  15. _deck: [],
  16. init: function init() {
  17. TransitionController.inherited('init', this, arguments);
  18. },
  19. jumpTo: function jumpTo(from, to) {
  20. var _this = this;
  21. return this._beforeJump(from, to).then(function () {
  22. return _this._jump(from, to);
  23. }).then(function () {
  24. return _this._afterJump(from, to);
  25. }).then(function () {
  26. return { overview: to.id === 'end' || to.id === 'start' };
  27. }).catch(function (err) {
  28. return _this._afterJump(from, to).then(function () {
  29. return Promise.reject(err);
  30. });
  31. });
  32. },
  33. forward: function forward(from, to) {
  34. var _this2 = this;
  35. return this._beforeNext(from, to).then(function () {
  36. return _this2._next(from, to);
  37. }).then(function () {
  38. return _this2._afterNext(from, to);
  39. }).then(function () {
  40. return { overview: false };
  41. });
  42. },
  43. backward: function backward(from, to) {
  44. var _this3 = this;
  45. return this._beforePrevious(from, to).then(function () {
  46. return _this3._previous(from, to);
  47. }).then(function () {
  48. return _this3._afterPrevious(from, to);
  49. }).then(function () {
  50. return { overview: false };
  51. });
  52. },
  53. _beforeJump: function _beforeJump(from, to) {
  54. this._setNextSceneScrollPosition(from, to);
  55. return Promise.resolve();
  56. },
  57. _jump: function _jump() {
  58. return Promise.resolve();
  59. },
  60. _afterJump: function _afterJump() {
  61. return Promise.resolve();
  62. },
  63. _beforeNext: function _beforeNext(from, to) {
  64. this._setNextSceneScrollPosition(from, to);
  65. return Promise.resolve();
  66. },
  67. _next: function _next() {
  68. return Promise.resolve();
  69. },
  70. _afterNext: function _afterNext() {
  71. return Promise.resolve();
  72. },
  73. _beforePrevious: function _beforePrevious(from, to) {
  74. this._setNextSceneScrollPosition(from, to);
  75. return Promise.resolve();
  76. },
  77. _previous: function _previous() {
  78. return Promise.resolve();
  79. },
  80. _afterPrevious: function _afterPrevious() {
  81. return Promise.resolve();
  82. },
  83. _setNextSceneScrollPosition: function _setNextSceneScrollPosition(from, to) {
  84. if (from && to && from.getLayoutView && to.getLayoutView) {
  85. var fromSceneScrollPosition = from.getLayoutView().$el.scrollTop();
  86. to.getLayoutView().$el.scrollTop(fromSceneScrollPosition);
  87. }
  88. },
  89. deckScenes: function deckScenes(scenes) {
  90. var _this4 = this;
  91. var setOnDeck = function setOnDeck($el) {
  92. if ($el.length) {
  93. $el.addClass('onDeck');
  94. $el.removeClass('hiddenScene');
  95. }
  96. };
  97. _.each(scenes, function (scene) {
  98. setOnDeck(scene.$el);
  99. _this4._showWidgets(scene);
  100. _this4._hideWidgets(scene);
  101. });
  102. this._deck = scenes;
  103. },
  104. undeckScenes: function undeckScenes(scenes) {
  105. var _this5 = this;
  106. var setOffDeck = function setOffDeck($el) {
  107. if ($el.length) {
  108. $el.removeClass('onDeck');
  109. $el.addClass('hiddenScene');
  110. $el.attr('aria-hidden', 'true');
  111. }
  112. };
  113. _.each(scenes, function (scene) {
  114. if (!(_this5._deck.indexOf(scene) !== -1)) {
  115. setOffDeck(scene.$el);
  116. }
  117. });
  118. },
  119. _hideWidgets: function _hideWidgets(view) {
  120. if (view && view.getLayoutView) {
  121. view.getLayoutView().onHide();
  122. }
  123. },
  124. _showWidgets: function _showWidgets(view) {
  125. if (view && view.getLayoutView) {
  126. view.getLayoutView().onShow();
  127. }
  128. }
  129. });
  130. return TransitionController;
  131. });
  132. //# sourceMappingURL=TransitionController.js.map