meter.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. var Meter = function() {
  2. var meterLabel, meterCurrent, meterStep, meterDuration, meterCallback, meterActive;
  3. this.isRunning = function() {
  4. return meterActive;
  5. };
  6. this.set = function(display, duration, callback) {
  7. var bar = document.getElementById("progressBar");
  8. bar.style.visibility = "visible";
  9. var label = document.getElementById("progressLabel");
  10. label.style.visibility = "visible";
  11. label.innerHTML = display;
  12. if (duration == 0) {
  13. meterStep = 0;
  14. meterCurrent = 0;
  15. } else {
  16. meterDuration = duration;
  17. meterCallback = callback;
  18. meterCurrent = 0;
  19. meterStep = 100 / meterDuration;
  20. }
  21. bar.value = meterCurrent;
  22. meterActive = true;
  23. };
  24. this.hide = function() {
  25. document.getElementById("progressBar").style.visibility = "hidden";
  26. document.getElementById("progressLabel").style.visibility = "hidden";
  27. meterActive = false;
  28. };
  29. this.update = function() {
  30. if (meterActive) {
  31. meterCurrent += meterStep;
  32. document.getElementById("progressBar").value = meterCurrent;
  33. if (meterCurrent >= 100) {
  34. meterCallback();
  35. this.hide();
  36. meterCallback = null;
  37. }
  38. }
  39. };
  40. this.save = function() {
  41. //localStorage.
  42. };
  43. this.load = function() {
  44. };
  45. };
  46. var meter = new Meter();