ajax_transferStats.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* $Id: ajax_transferStats.js 3239 2007-10-29 22:16:10Z danez $ */
  2. // fields
  3. var ajax_fieldIds = new Array(
  4. "running",
  5. "speedDown",
  6. "speedUp",
  7. "downCurrent",
  8. "upCurrent",
  9. "downTotal",
  10. "upTotal",
  11. "percentDone",
  12. "sharing",
  13. "eta",
  14. "seeds",
  15. "peers",
  16. "cons"
  17. );
  18. var ajax_idCount = ajax_fieldIds.length;
  19. var ajax_transferName = "";
  20. /**
  21. * ajax_initialize
  22. *
  23. * @param timer
  24. * @param delim
  25. * @param name
  26. */
  27. function ajax_initialize(timer, delim, name) {
  28. ajax_updateTimer = timer;
  29. ajax_txtDelim = delim;
  30. ajax_transferName = name;
  31. if (ajax_useXML)
  32. ajax_updateParams = '?t=transfer&f=xml&i=' + name;
  33. else
  34. ajax_updateParams = '?t=transfer&f=txt&h=0&i=' + name;
  35. // state
  36. ajax_updateState = 1;
  37. // http-request
  38. ajax_httpRequest = ajax_getHttpRequest();
  39. // start update-thread
  40. setTimeout("ajax_update();", ajax_updateTimer);
  41. }
  42. /**
  43. * process XML-response
  44. *
  45. * @param content
  46. */
  47. function ajax_processXML(content) {
  48. alert(content);
  49. }
  50. /**
  51. * process text-response
  52. *
  53. * @param content
  54. */
  55. function ajax_processText(content) {
  56. ajax_updateContent(content.split(ajax_txtDelim));
  57. // set timeout
  58. setTimeout("ajax_update();", ajax_updateTimer);
  59. }
  60. /**
  61. * update page contents from response
  62. *
  63. * @param content
  64. */
  65. function ajax_updateContent(content)
  66. {
  67. // progress-bar
  68. currentPercentage = content[7];
  69. document.getElementById('barImage1').style.width = currentPercentage + '%';
  70. document.getElementById('barImage2').style.width = (100 - currentPercentage) + '%';
  71. // fields
  72. for (i = 1; i < ajax_idCount; i++) {
  73. if ((ajax_fieldIds[i] == 'eta') && (content[i] == '-'))
  74. document.getElementById(ajax_fieldIds[i]).innerHTML = '&#8734';
  75. else
  76. document.getElementById(ajax_fieldIds[i]).innerHTML = content[i];
  77. }
  78. }