Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

108 Zeilen
3.0 KiB

  1. g_embed_nacl_module = null;
  2. if (IsUsingNaCl()) NaClLoadingInit();
  3. function InitNaClModuleVar() { g_embed_nacl_module = GetiFrameModuleVar(); }
  4. function RegisterListener()
  5. {
  6. //Register all the correct functions to the listener
  7. var div_listener = GetiFrameDivEmbed();
  8. if (div_listener)
  9. {
  10. div_listener.addEventListener('loadstart', ModuleStartedLoad, true);
  11. div_listener.addEventListener('load', ModuleDidLoad, true);
  12. div_listener.addEventListener('error', ModuleError, true);
  13. div_listener.addEventListener('progress', ModuleLoadUpdate, true);
  14. div_listener.addEventListener('message', ModuleSentMessage, true);
  15. div_listener.addEventListener('crash', ModuleCrash, true);
  16. window.setTimeout("UpdateTextStatus(0.1)", 100);
  17. }
  18. else if (IsUsingNaCl())
  19. window.setTimeout("RegisterListener()", 200);
  20. }
  21. //-------------------------------------------------------------------------
  22. // MODULE LOADING FUNCTIONS
  23. //-------------------------------------------------------------------------
  24. //Indicate page has been loaded.
  25. function NaClLoadingInit()
  26. {
  27. HideProgressStatus(false);
  28. //Page did load before NaCl module
  29. if (!g_embed_nacl_module)
  30. AddTextStatus('Please wait for module loading');
  31. RegisterListener();
  32. }
  33. //Module starts load
  34. function ModuleStartedLoad()
  35. {
  36. AddTextStatus('Module Started Loading');
  37. InitNaClModuleVar();
  38. }
  39. //Module progress event
  40. function ModuleLoadUpdate(event)
  41. {
  42. if (event.lengthComputable)
  43. UpdateProgressBarValue('Please wait, loading', event.loaded, event.total);
  44. else
  45. UpdateProgressBarValue('Please wait, calculating load balance ...');
  46. }
  47. //Indicate module load success.
  48. function ModuleDidLoad()
  49. {
  50. if (!g_embed_nacl_module)
  51. InitNaClModuleVar();
  52. //Hide the progress div
  53. AddTextStatus('Module is live, thank you for your patience.');
  54. window.setTimeout('HideProgressStatus(true)', GetMaxStatusTime(0.5) * 1000);
  55. }
  56. //Module did crash
  57. function ModuleCrash(event)
  58. {
  59. RestartModule();
  60. AddTextStatus("Module has crashed ! Restarting ...");
  61. }
  62. //Module had an error
  63. function ModuleError(event)
  64. {
  65. RestartModule();
  66. AddTextStatus("Module Load/start Error ! Restarting ...");
  67. }
  68. //Used to restart module on crash/error/load fail ....
  69. function RestartModule()
  70. {
  71. var id_frame_embed = GetFrameData();
  72. if (id_frame_embed)
  73. {
  74. HideProgressStatus(false);
  75. window.setTimeout('GetFrameData().contentDocument.location.reload(true)', 1000);
  76. }
  77. }
  78. //-------------------------------------------------------------------------
  79. // MODULE COMMUNICATION FUNCTIONS
  80. //-------------------------------------------------------------------------
  81. //Handle message from the NaCl module
  82. function ModuleSentMessage(message)
  83. {
  84. alert('Module sent message: ' + message.data);
  85. }
  86. //Called by the "Send Mesh Command !" button
  87. function SendMessageToModule()
  88. {
  89. if (g_embed_nacl_module)
  90. g_embed_nacl_module.postMessage(GetTextAreaCodeSrc().value);
  91. else
  92. alert("Module not loaded !");
  93. }