swfupload.queue.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. [Leo.C, Studio] (C)2004 - 2008
  3. $Hanization: LeoChung $
  4. $E-Mail: who@imll.net $
  5. $HomePage: http://imll.net $
  6. $Date: 2008/11/8 18:02 $
  7. */
  8. /*
  9. Queue Plug-in
  10. Features:
  11. *Adds a cancelQueue() method for cancelling the entire queue.
  12. *All queued files are uploaded when startUpload() is called.
  13. *If false is returned from uploadComplete then the queue upload is stopped.
  14. If false is not returned (strict comparison) then the queue upload is continued.
  15. *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
  16. Set the event handler with the queue_complete_handler setting.
  17. */
  18. var SWFUpload;
  19. if (typeof(SWFUpload) === "function") {
  20. SWFUpload.queue = {};
  21. SWFUpload.prototype.initSettings = (function (oldInitSettings) {
  22. return function () {
  23. if (typeof(oldInitSettings) === "function") {
  24. oldInitSettings.call(this);
  25. }
  26. this.customSettings.queue_cancelled_flag = false;
  27. this.customSettings.queue_upload_count = 0;
  28. this.settings.user_upload_complete_handler = this.settings.upload_complete_handler;
  29. this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
  30. this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
  31. };
  32. })(SWFUpload.prototype.initSettings);
  33. SWFUpload.prototype.startUpload = function (fileID) {
  34. this.customSettings.queue_cancelled_flag = false;
  35. this.callFlash("StartUpload", false, [fileID]);
  36. };
  37. SWFUpload.prototype.cancelQueue = function () {
  38. this.customSettings.queue_cancelled_flag = true;
  39. this.stopUpload();
  40. var stats = this.getStats();
  41. while (stats.files_queued > 0) {
  42. this.cancelUpload();
  43. stats = this.getStats();
  44. }
  45. };
  46. SWFUpload.queue.uploadCompleteHandler = function (file) {
  47. var user_upload_complete_handler = this.settings.user_upload_complete_handler;
  48. var continueUpload;
  49. if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
  50. this.customSettings.queue_upload_count++;
  51. }
  52. if (typeof(user_upload_complete_handler) === "function") {
  53. continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
  54. } else {
  55. continueUpload = true;
  56. }
  57. if (continueUpload) {
  58. var stats = this.getStats();
  59. if (stats.files_queued > 0 && this.customSettings.queue_cancelled_flag === false) {
  60. this.startUpload();
  61. } else if (this.customSettings.queue_cancelled_flag === false) {
  62. this.queueEvent("queue_complete_handler", [this.customSettings.queue_upload_count]);
  63. this.customSettings.queue_upload_count = 0;
  64. } else {
  65. this.customSettings.queue_cancelled_flag = false;
  66. this.customSettings.queue_upload_count = 0;
  67. }
  68. }
  69. };
  70. }