Source: env/media/waitReadyIndicator.js

  1. /**
  2. * Default / standard implementation for wait-/ready-indication:
  3. *
  4. * media-modules may signal that they are <code>preparing</code> a resource, and then that
  5. * they are <code>ready</code> via the {@link mmir.MediaManager#_preparing} and
  6. * {@link mmir.MediaManager#_ready}.
  7. *
  8. * This implementation provides a simple mechanism for showing these states to the user:
  9. * upon <em>preparing</em> an overlay with a "please wait" message is shown, and upon
  10. * <em>ready</em> the overlay is hidden again.
  11. *
  12. * See {@link #setWaitCaption} for details on setting a custom text message.
  13. *
  14. * In order to load this implementation, add the entry <code>"waitReadyIndicator"</code>
  15. * to the <code>mediaManager.plugins</code> list in the MMIR configuration file
  16. * at <code>config/configuration.json</code>:
  17. * <pre>
  18. * ...
  19. * "mediaManager": {
  20. * "plugins": {
  21. * "browser": ["waitReadyIndicator",
  22. * // OR: {"mod": "waitReadyIndicator", "config": "url to css styles"},
  23. * "webAudio",
  24. * ...
  25. * ],
  26. * "cordova": ["waitReadyIndicator",
  27. * // OR: {"mod": "waitReadyIndicator", "config": "url to css styles"},
  28. * "androidAudioInput",
  29. * ...
  30. * ]
  31. * ...
  32. * }
  33. * },
  34. * ...
  35. * </pre>
  36. * NOTE: the optional configuration value specifies an URL to a CSS file for styling the
  37. * wait-/ready-indication dialog.
  38. * If not specified, the default styling of stlne-wait-dlg is used.
  39. *
  40. * @example
  41. *
  42. * //starting to prepare a resource:
  43. * mmir.MediaManager._preparing();
  44. *
  45. * // do something ...
  46. *
  47. * //... when the resouce has been prepared
  48. * // and is ready to be used:
  49. * mmir.MediaManager._ready();
  50. *
  51. * @class
  52. * @public
  53. * @name WaitReadyIndicatorImpl
  54. * @memberOf mmir.env.media
  55. * @hideconstructor
  56. * @implements mmir.env.media.IWaitReadyIndicator
  57. *
  58. * @requires mmirf/waitDialog the stlne-wait-dlg implementation (waitDialog module and CSS)
  59. */
  60. define(['mmirf/languageManager', 'mmirf/waitDialog'], function(lang, dlg){
  61. /** @class mmir.env.media.WaitReadyIndicatorImpl
  62. * @ignore
  63. */
  64. return {
  65. /** @memberOf mmir.env.media.WaitReadyIndicatorImpl */
  66. initialize: function(callBack, __mediaManager, ctxId, moduleConfig){
  67. /**
  68. * @readonly
  69. * @inner
  70. * @default "waitReadyIndicator"
  71. * @memberOf mmir.env.media.WaitReadyIndicatorImpl#
  72. */
  73. var _pluginName = 'waitReadyIndicator';
  74. /** @memberOf mmir.env.media.WaitReadyIndicatorImpl# */
  75. var _id = 'media-plugin-wait';
  76. /**
  77. * @private
  78. * @memberOf mmir.env.media.WaitReadyIndicatorImpl#
  79. */
  80. var caption;
  81. /**
  82. * @private
  83. * @memberOf mmir.env.media.WaitReadyIndicatorImpl#
  84. */
  85. var cssUrl = moduleConfig? moduleConfig : dlg.styleUrl;
  86. //load the stylesheet file for the wait-dialog
  87. // (does nothing, if this load-function was already called before)
  88. dlg._loadStyle(cssUrl);
  89. //create the DOM elements for the wait dialog (hidden)
  90. dlg.create(_id);//, {type: 'verbose', theme: 'a'});//DISABLED: these are the default options
  91. //invoke the passed-in initializer-callback and export the public functions:
  92. callBack({waitReadyImpl: {
  93. /**
  94. * Shows wait dialog.
  95. *
  96. * @public
  97. * @memberOf mmir.env.media.WaitReadyIndicatorImpl.prototype
  98. * @see mmir.MediaManager#_preparing
  99. */
  100. preparing: function (){
  101. var text = typeof caption !== 'undefined'? caption : lang.getText('loadingText');
  102. dlg.show(text, _id);
  103. },
  104. /**
  105. * Hides wait dialog.
  106. *
  107. * @public
  108. * @memberOf mmir.env.media.WaitReadyIndicatorImpl.prototype
  109. * @see mmir.MediaManager#_ready
  110. */
  111. ready: function(){
  112. dlg.hide(_id);
  113. },
  114. /**
  115. * Set caption for wait dialog.
  116. *
  117. * <p>
  118. * By default (i.e. not set), the dictionary entry for
  119. * "loadingText" is used as caption / label.
  120. *
  121. * @param {String} text
  122. * set the caption / label for the wait-dialog.<br>
  123. * If <code>undefined</code>, the default caption will be used.
  124. *
  125. * @public
  126. * @memberOf mmir.env.media.WaitReadyIndicatorImpl.prototype
  127. * @see mmir.MediaManager#ready
  128. * @see mmir.LanguageManager#getText
  129. */
  130. setWaitCaption: function(text){
  131. caption = text;
  132. },
  133. /**
  134. * Get current caption for wait dialog.
  135. *
  136. * NOTE if none is set, then internally the value of "loadingText"
  137. * property of the current language dictionary will be used.
  138. *
  139. * @public
  140. * @memberOf mmir.env.media.WaitReadyIndicatorImpl.prototype
  141. * @see mmir.MediaManager#_ready
  142. * @see #setWaitCaption
  143. */
  144. getWaitCaption: function(){
  145. return caption;
  146. }
  147. }});
  148. }
  149. };
  150. });//END define