swfupload.queue.js 2.5 KB

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