您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

progressstatus.js 3.6 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. g_var_progress_bar = -1;
  2. g_status_text = [null];
  3. g_status_timer = [-1.0];
  4. //-------------------------------------------------------------------------
  5. // PROGRESS BAR STATUS FUNCTIONS
  6. //-------------------------------------------------------------------------
  7. //Update the actual progress bar
  8. function UpdateProgressBarValue(new_status, new_value, new_max)
  9. {
  10. var progress_bar = GetProgressBar();
  11. if (progress_bar)
  12. {
  13. if (new_value != undefined && new_max != undefined)
  14. {
  15. if (progress_bar.value < 0)
  16. g_var_progress_bar = -1;
  17. var loading_text = new_status + '[' + (Math.min(1.0, new_value / new_max) * 100.0).toFixed(0) + '%]';
  18. //update the progress status
  19. progress_bar.max = new_max;
  20. progress_bar.value = new_value;
  21. g_var_progress_bar = AddTextStatus(loading_text, g_var_progress_bar);
  22. }
  23. //Load length is not usable
  24. else
  25. {
  26. if (progress_bar.value > 0)
  27. g_var_progress_bar = -1;
  28. progress_bar.value = -1;
  29. g_var_progress_bar = AddTextStatus(new_status, g_var_progress_bar);
  30. }
  31. //Force Status text update for coherency
  32. UpdateTextStatus(0.0);
  33. }
  34. }
  35. //Add text status to the stack
  36. function GetMaxStatusTime(min_value)
  37. {
  38. var higher_time = (min_value) ? (min_value) : (0.0);
  39. for (var i = 0; i < g_status_timer.length; i++)
  40. if (g_status_timer[i])
  41. higher_time = Math.max(higher_time, g_status_timer[i]);
  42. }
  43. //Update progress bar status
  44. function UpdateTextStatus(seconds)
  45. {
  46. var div_progress_status = GetDivProgressStatus();
  47. if (div_progress_status)
  48. {
  49. div_progress_status.innerHTML = '';
  50. for (var i = 0; i < g_status_text.length; i++)
  51. {
  52. if (g_status_timer[i] == undefined || g_status_timer[i] < 0.0)
  53. {
  54. g_status_timer[i] = -1.0;
  55. g_status_text[i] = undefined;
  56. }
  57. else
  58. {
  59. g_status_timer[i] -= seconds;
  60. div_progress_status.innerHTML += g_status_text[i];
  61. //div_progress_status.innerHTML += '[' + g_status_timer[i].toFixed(2) + ']';
  62. if (i < g_status_text.length - 1)
  63. div_progress_status.innerHTML += '<br>';
  64. }
  65. }
  66. window.setTimeout("UpdateTextStatus(0.1)", 100);
  67. }
  68. }
  69. //Add text status to the stack
  70. function AddTextStatus(message, message_id)
  71. {
  72. var msg_timer = 2.0;
  73. if (message_id == undefined || message_id < 0)
  74. {
  75. g_status_text[g_status_text.length] = message;
  76. g_status_timer[g_status_timer.length] = GetMaxStatusTime(msg_timer) + 0.5;
  77. return g_status_timer.length - 1;
  78. }
  79. else
  80. {
  81. g_status_text[message_id] = message;
  82. g_status_timer[message_id] = msg_timer;
  83. return message_id;
  84. }
  85. }
  86. //Hide Progress Status and empty status texts
  87. function HideProgressStatus(should_hide)
  88. {
  89. var progress_bar = GetProgressBar();
  90. var div_progress = GetDivProgress();
  91. if (div_progress && progress_bar)
  92. {
  93. if (should_hide == true)
  94. {
  95. div_progress.style.visibility = "hidden";
  96. g_status_text.splice(0, g_status_text.length);
  97. g_status_timer.splice(0, g_status_timer.length);
  98. progress_bar.value = -1;
  99. UpdateTextStatus(1.0);
  100. }
  101. else
  102. {
  103. div_progress.style.visibility = "visible";
  104. progress_bar.value = -1;
  105. AddTextStatus('Please wait for module loading');
  106. UpdateTextStatus(1.0);
  107. }
  108. }
  109. }