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. *
  56. * @requires mmirf/waitDialog the stlne-wait-dlg implementation (waitDialog module and CSS)
  57. */
  58. define(['mmirf/languageManager', 'mmirf/waitDialog'], function(lang, dlg){
  59. /** @class WaitReadyIndicatorImpl */
  60. return {
  61. /** @memberOf WaitReadyIndicatorImpl# */
  62. initialize: function(callBack, __mediaManager, ctxId, moduleConfig){
  63. /** @memberOf WaitReadyIndicatorImpl# */
  64. var _pluginName = 'waitReadyIndicator';
  65. /** @memberOf WaitReadyIndicatorImpl# */
  66. var _id = 'media-plugin-wait';
  67. /** @memberOf WaitReadyIndicatorImpl# */
  68. var caption;
  69. /** @memberOf WaitReadyIndicatorImpl# */
  70. var cssUrl = moduleConfig? moduleConfig : dlg.styleUrl;
  71. //load the stylesheet file for the wait-dialog
  72. // (does nothing, if this load-function was already called before)
  73. dlg._loadStyle(cssUrl);
  74. //create the DOM elements for the wait dialog (hidden)
  75. dlg.create(_id);//, {type: 'verbose', theme: 'a'});//DISABLED: these are the default options
  76. //invoke the passed-in initializer-callback and export the public functions:
  77. callBack({waitReadyImpl: {
  78. /**
  79. * Shows wait dialog.
  80. *
  81. * @public
  82. * @memberOf WaitReadyIndicatorImpl.prototype
  83. * @see mmir.MediaManager#_preparing
  84. */
  85. preparing: function (){
  86. var text = typeof caption !== 'undefined'? caption : lang.getText('loadingText');
  87. dlg.show(text, _id);
  88. },
  89. /**
  90. * Hides wait dialog.
  91. *
  92. * @public
  93. * @memberOf WaitReadyIndicatorImpl.prototype
  94. * @see mmir.MediaManager#_ready
  95. */
  96. ready: function(){
  97. dlg.hide(_id);
  98. },
  99. /**
  100. * Set caption for wait dialog.
  101. *
  102. * <p>
  103. * By default (i.e. not set), the dictionary entry for
  104. * "loadingText" is used as caption / label.
  105. *
  106. * @param {String} text
  107. * set the caption / label for the wait-dialog.<br>
  108. * If <code>undefined</code>, the default caption will be used.
  109. *
  110. * @public
  111. * @memberOf WaitReadyIndicatorImpl.prototype
  112. * @see mmir.MediaManager#ready
  113. * @see mmir.LanguageManager#getText
  114. */
  115. setWaitCaption: function(text){
  116. caption = text;
  117. },
  118. /**
  119. * Get current caption for wait dialog.
  120. *
  121. * NOTE if none is set, then internally the value of "loadingText"
  122. * property of the current language dictionary will be used.
  123. *
  124. * @public
  125. * @memberOf WaitReadyIndicatorImpl.prototype
  126. * @see mmir.MediaManager#_ready
  127. * @see #setWaitCaption
  128. */
  129. getWaitCaption: function(){
  130. return caption;
  131. }
  132. }});
  133. }
  134. };
  135. });//END define