source: trunk/www.guidonia.net/wp/wp-includes/js/swfupload/plugins/swfupload.queue.js@ 44

Last change on this file since 44 was 44, checked in by luciano, 15 years ago
File size: 3.3 KB
Line 
1/*
2 Queue Plug-in
3
4 Features:
5 *Adds a cancelQueue() method for cancelling the entire queue.
6 *All queued files are uploaded when startUpload() is called.
7 *If false is returned from uploadComplete then the queue upload is stopped.
8 If false is not returned (strict comparison) then the queue upload is continued.
9 *Adds a QueueComplete event that is fired when all the queued files have finished uploading.
10 Set the event handler with the queue_complete_handler setting.
11
12 */
13
14var SWFUpload;
15if (typeof(SWFUpload) === "function") {
16 SWFUpload.queue = {};
17
18 SWFUpload.prototype.initSettings = (function (oldInitSettings) {
19 return function () {
20 if (typeof(oldInitSettings) === "function") {
21 oldInitSettings.call(this);
22 }
23
24 this.queueSettings = {};
25
26 this.queueSettings.queue_cancelled_flag = false;
27 this.queueSettings.queue_upload_count = 0;
28
29 this.queueSettings.user_upload_complete_handler = this.settings.upload_complete_handler;
30 this.queueSettings.user_upload_start_handler = this.settings.upload_start_handler;
31 this.settings.upload_complete_handler = SWFUpload.queue.uploadCompleteHandler;
32 this.settings.upload_start_handler = SWFUpload.queue.uploadStartHandler;
33
34 this.settings.queue_complete_handler = this.settings.queue_complete_handler || null;
35 };
36 })(SWFUpload.prototype.initSettings);
37
38 SWFUpload.prototype.startUpload = function (fileID) {
39 this.queueSettings.queue_cancelled_flag = false;
40 this.callFlash("StartUpload", [fileID]);
41 };
42
43 SWFUpload.prototype.cancelQueue = function () {
44 this.queueSettings.queue_cancelled_flag = true;
45 this.stopUpload();
46
47 var stats = this.getStats();
48 while (stats.files_queued > 0) {
49 this.cancelUpload();
50 stats = this.getStats();
51 }
52 };
53
54 SWFUpload.queue.uploadStartHandler = function (file) {
55 var returnValue;
56 if (typeof(this.queueSettings.user_upload_start_handler) === "function") {
57 returnValue = this.queueSettings.user_upload_start_handler.call(this, file);
58 }
59
60 // To prevent upload a real "FALSE" value must be returned, otherwise default to a real "TRUE" value.
61 returnValue = (returnValue === false) ? false : true;
62
63 this.queueSettings.queue_cancelled_flag = !returnValue;
64
65 return returnValue;
66 };
67
68 SWFUpload.queue.uploadCompleteHandler = function (file) {
69 var user_upload_complete_handler = this.queueSettings.user_upload_complete_handler;
70 var continueUpload;
71
72 if (file.filestatus === SWFUpload.FILE_STATUS.COMPLETE) {
73 this.queueSettings.queue_upload_count++;
74 }
75
76 if (typeof(user_upload_complete_handler) === "function") {
77 continueUpload = (user_upload_complete_handler.call(this, file) === false) ? false : true;
78 } else if (file.filestatus === SWFUpload.FILE_STATUS.QUEUED) {
79 // If the file was stopped and re-queued don't restart the upload
80 continueUpload = false;
81 } else {
82 continueUpload = true;
83 }
84
85 if (continueUpload) {
86 var stats = this.getStats();
87 if (stats.files_queued > 0 && this.queueSettings.queue_cancelled_flag === false) {
88 this.startUpload();
89 } else if (this.queueSettings.queue_cancelled_flag === false) {
90 this.queueEvent("queue_complete_handler", [this.queueSettings.queue_upload_count]);
91 this.queueSettings.queue_upload_count = 0;
92 } else {
93 this.queueSettings.queue_cancelled_flag = false;
94 this.queueSettings.queue_upload_count = 0;
95 }
96 }
97 };
98}
Note: See TracBrowser for help on using the repository browser.