Show:
  1. /**
  2. * @module Player
  3. */
  4.  
  5.  
  6. /**
  7. * I am the Interface module.
  8. *
  9. * I am the central place which inititalizes and coordinates all other interface-related modules.
  10. *
  11. * When this module is loaded, it loads also:
  12. * * {{#crossLink "Titlebar"}}Titlebar{{/crossLink}}
  13. * * {{#crossLink "Sidebar"}}Sidebar{{/crossLink}}
  14. * * {{#crossLink "ViewOverview"}}ViewOverview{{/crossLink}}
  15. * * {{#crossLink "ViewVideo"}}ViewVideo{{/crossLink}} (when there is a hypervideo present)
  16. * * {{#crossLink "ViewResources"}}ViewResources{{/crossLink}}
  17. *
  18. * @class Interface
  19. * @static
  20. */
  21.  
  22.  
  23. FrameTrail.defineModule('Interface', function(){
  24.  
  25.  
  26. FrameTrail.initModule('Titlebar');
  27. FrameTrail.initModule('Sidebar');
  28.  
  29. FrameTrail.initModule('ViewOverview');
  30.  
  31. if (FrameTrail.module('RouteNavigation').hypervideoID) {
  32. FrameTrail.initModule('ViewVideo');
  33. }
  34.  
  35. FrameTrail.initModule('ViewResources');
  36.  
  37. var mainContainer = $('<div id="MainContainer"></div>');
  38.  
  39.  
  40.  
  41.  
  42.  
  43. /**
  44. * I call the create method of all my sub-modules, and set the window resize event listener.
  45. *
  46. * @method create
  47. * @param {Function} callback
  48. */
  49. function create(callback) {
  50.  
  51. FrameTrail.module('InterfaceModal').showStatusMessage('Loading Interface ...');
  52.  
  53. // Check if window is in iFrame
  54. var iFrame;
  55. try {
  56. iFrame = (window.self !== window.top);
  57. } catch (e) {
  58. iFrame = true;
  59. }
  60. FrameTrail.changeState('embed', iFrame);
  61.  
  62. FrameTrail.module('Titlebar').create();
  63. FrameTrail.module('Sidebar').create();
  64.  
  65.  
  66. $('body').append(mainContainer);
  67.  
  68. FrameTrail.module('ViewOverview').create();
  69.  
  70. if (FrameTrail.module('RouteNavigation').hypervideoID) {
  71. FrameTrail.module('ViewVideo').create();
  72. }
  73.  
  74. FrameTrail.module('ViewResources').create();
  75.  
  76. initWindowResizeHandler();
  77.  
  78. callback.call();
  79. };
  80.  
  81.  
  82. /**
  83. * I set the event listener for the resize event of the window.
  84. *
  85. * This event triggers a change of the global state "viewSize", so all modules can react to this event.
  86. *
  87. * Also, after the .create() method of all interface modules has been called, I trigger once the resize event, to propagate a valid state "viewSize" throughout the app.
  88. *
  89. * @method initWindowResizeHandler
  90. */
  91. function initWindowResizeHandler() {
  92.  
  93. var _window = $(window),
  94. resizeTimeout = false;
  95.  
  96. _window.resize(function(){
  97.  
  98. var width = _window.width(),
  99. height = _window.height();
  100.  
  101. $('#MainContainer').height( height - FrameTrail.module('Titlebar').height );
  102. FrameTrail.changeState('viewSize', [width, height]);
  103.  
  104. if ( resizeTimeout !== false ) {
  105. clearTimeout(resizeTimeout);
  106. }
  107.  
  108. resizeTimeout = setTimeout(function() {
  109. FrameTrail.changeState('viewSizeChanged');
  110. }, 200);
  111. });
  112.  
  113. _window.resize();
  114.  
  115.  
  116. };
  117.  
  118. /**
  119. * When the global state "sidebarOpen" changes, I react to it.
  120. *
  121. * Most importantly, I assure that the &lt;div id="MainContainer"&gt; is resized __before__ the {{#crossLink "ViewVideo/toggleSidebarOpen:method"}}ViewVideo.toggleSidebarOpen{{/crossLink}} is called.
  122. *
  123. * @method toggleSidebarOpen
  124. * @param {Boolean} opened
  125. */
  126. function toggleSidebarOpen(opened) {
  127.  
  128. if (opened) {
  129. mainContainer.addClass('sidebarOpen');
  130. } else {
  131. mainContainer.removeClass('sidebarOpen');
  132. }
  133.  
  134. var ViewVideo = FrameTrail.module('ViewVideo');
  135.  
  136. if (ViewVideo) {
  137. ViewVideo.toggleSidebarOpen(opened);
  138. }
  139.  
  140. };
  141.  
  142.  
  143. /**
  144. * I react to a change in the global state "editMode"
  145. * @method toggleEditMode
  146. * @param {String} editMode
  147. * @param {String} oldEditMode
  148. */
  149. function toggleEditMode(editMode, oldEditMode){
  150.  
  151. if (editMode) {
  152.  
  153. mainContainer.addClass('editActive');
  154.  
  155. } else {
  156.  
  157. mainContainer.removeClass('editActive');
  158.  
  159. }
  160.  
  161. };
  162.  
  163.  
  164.  
  165. return {
  166.  
  167. create: create,
  168.  
  169. onChange: {
  170. sidebarOpen: toggleSidebarOpen,
  171. editMode: toggleEditMode
  172. }
  173.  
  174. };
  175.  
  176. });