colonymech / docs / www / colonyscout / internal / includes / uploadify / jquery.uploadify.v2.1.1.js @ f59acf11
History | View | Annotate | Download (13.7 KB)
1 |
/*
|
---|---|
2 |
Uploadify v2.1.1
|
3 |
Release Date: November 1, 2010
|
4 |
|
5 |
Copyright (c) 2010 Ronnie Garcia, Travis Nickels
|
6 |
|
7 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
8 |
of this software and associated documentation files (the "Software"), to deal
|
9 |
in the Software without restriction, including without limitation the rights
|
10 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11 |
copies of the Software, and to permit persons to whom the Software is
|
12 |
furnished to do so, subject to the following conditions:
|
13 |
|
14 |
The above copyright notice and this permission notice shall be included in
|
15 |
all copies or substantial portions of the Software.
|
16 |
|
17 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23 |
THE SOFTWARE.
|
24 |
*/
|
25 |
|
26 |
if(jQuery)(
|
27 |
function(jQuery){
|
28 |
jQuery.extend(jQuery.fn,{ |
29 |
uploadify:function(options) { |
30 |
jQuery(this).each(function(){ |
31 |
settings = jQuery.extend({ |
32 |
id : jQuery(this).attr('id'), // The ID of the object being Uploadified |
33 |
uploader : 'uploadify.swf', // The path to the uploadify swf file |
34 |
script : 'uploadify.php', // The path to the uploadify backend upload script |
35 |
expressInstall : null, // The path to the express install swf file |
36 |
folder : '', // The path to the upload folder |
37 |
height : 30, // The height of the flash button |
38 |
width : 120, // The width of the flash button |
39 |
cancelImg : 'cancel.png', // The path to the cancel image for the default file queue item container |
40 |
wmode : 'opaque', // The wmode of the flash file |
41 |
scriptAccess : 'sameDomain', // Set to "always" to allow script access across domains |
42 |
fileDataName : 'Filedata', // The name of the file collection object in the backend upload script |
43 |
method : 'POST', // The method for sending variables to the backend upload script |
44 |
queueSizeLimit : 999, // The maximum size of the file queue |
45 |
simUploadLimit : 1, // The number of simultaneous uploads allowed |
46 |
queueID : false, // The optional ID of the queue container |
47 |
displayData : 'percentage', // Set to "speed" to show the upload speed in the default queue item |
48 |
removeCompleted : true, // Set to true if you want the queue items to be removed when a file is done uploading |
49 |
onInit : function() {}, // Function to run when uploadify is initialized |
50 |
onSelect : function() {}, // Function to run when a file is selected |
51 |
onQueueFull : function() {}, // Function to run when the queue reaches capacity |
52 |
onCheck : function() {}, // Function to run when script checks for duplicate files on the server |
53 |
onCancel : function() {}, // Function to run when an item is cleared from the queue |
54 |
onClearQueue : function() {}, // Function to run when the queue is manually cleared |
55 |
onError : function() {}, // Function to run when an upload item returns an error |
56 |
onProgress : function() {}, // Function to run each time the upload progress is updated |
57 |
onComplete : function() {}, // Function to run when an upload is completed |
58 |
onAllComplete : function() {} // Function to run when all uploads are completed |
59 |
}, options); |
60 |
var pagePath = location.pathname;
|
61 |
pagePath = pagePath.split('/');
|
62 |
pagePath.pop(); |
63 |
pagePath = pagePath.join('/') + '/'; |
64 |
var data = {};
|
65 |
data.uploadifyID = settings.id; |
66 |
data.pagepath = pagePath; |
67 |
if (settings.buttonImg) data.buttonImg = escape(settings.buttonImg);
|
68 |
if (settings.buttonText) data.buttonText = escape(settings.buttonText);
|
69 |
if (settings.rollover) data.rollover = true; |
70 |
data.script = settings.script; |
71 |
data.folder = escape(settings.folder); |
72 |
if (settings.scriptData) {
|
73 |
var scriptDataString = ''; |
74 |
for (var name in settings.scriptData) { |
75 |
scriptDataString += '&' + name + '=' + settings.scriptData[name]; |
76 |
} |
77 |
data.scriptData = escape(scriptDataString.substr(1));
|
78 |
} |
79 |
data.width = settings.width; |
80 |
data.height = settings.height; |
81 |
data.wmode = settings.wmode; |
82 |
data.method = settings.method; |
83 |
data.queueSizeLimit = settings.queueSizeLimit; |
84 |
data.simUploadLimit = settings.simUploadLimit; |
85 |
if (settings.hideButton) data.hideButton = true; |
86 |
if (settings.fileDesc) data.fileDesc = settings.fileDesc;
|
87 |
if (settings.fileExt) data.fileExt = settings.fileExt;
|
88 |
if (settings.multi) data.multi = true; |
89 |
if (settings.auto) data.auto = true; |
90 |
if (settings.sizeLimit) data.sizeLimit = settings.sizeLimit;
|
91 |
if (settings.checkScript) data.checkScript = settings.checkScript;
|
92 |
if (settings.fileDataName) data.fileDataName = settings.fileDataName;
|
93 |
if (settings.queueID) data.queueID = settings.queueID;
|
94 |
if (settings.onInit() !== false) { |
95 |
jQuery(this).css('display','none'); |
96 |
jQuery(this).after('<div id="' + jQuery(this).attr('id') + 'Uploader"></div>'); |
97 |
swfobject.embedSWF(settings.uploader, settings.id + 'Uploader', settings.width, settings.height, '9.0.24', settings.expressInstall, data, {'quality':'high','wmode':settings.wmode,'allowScriptAccess':settings.scriptAccess},{},function(event) { |
98 |
if (typeof(settings.onSWFReady) == 'function' && event.success) settings.onSWFReady(); |
99 |
}); |
100 |
if (settings.queueID == false) { |
101 |
jQuery("#" + jQuery(this).attr('id') + "Uploader").after('<div id="' + jQuery(this).attr('id') + 'Queue" class="uploadifyQueue"></div>'); |
102 |
} else {
|
103 |
jQuery("#" + settings.queueID).addClass('uploadifyQueue'); |
104 |
} |
105 |
} |
106 |
if (typeof(settings.onOpen) == 'function') { |
107 |
jQuery(this).bind("uploadifyOpen", settings.onOpen); |
108 |
} |
109 |
jQuery(this).bind("uploadifySelect", {'action': settings.onSelect, 'queueID': settings.queueID}, function(event, ID, fileObj) { |
110 |
if (event.data.action(event, ID, fileObj) !== false) { |
111 |
var byteSize = Math.round(fileObj.size / 1024 * 100) * .01; |
112 |
var suffix = 'KB'; |
113 |
if (byteSize > 1000) { |
114 |
byteSize = Math.round(byteSize *.001 * 100) * .01; |
115 |
suffix = 'MB';
|
116 |
} |
117 |
var sizeParts = byteSize.toString().split('.'); |
118 |
if (sizeParts.length > 1) { |
119 |
byteSize = sizeParts[0] + '.' + sizeParts[1].substr(0,2); |
120 |
} else {
|
121 |
byteSize = sizeParts[0];
|
122 |
} |
123 |
if (fileObj.name.length > 20) { |
124 |
fileName = fileObj.name.substr(0,20) + '...'; |
125 |
} else {
|
126 |
fileName = fileObj.name; |
127 |
} |
128 |
queue = '#' + jQuery(this).attr('id') + 'Queue'; |
129 |
if (event.data.queueID) {
|
130 |
queue = '#' + event.data.queueID;
|
131 |
} |
132 |
jQuery(queue).append('<div id="' + jQuery(this).attr('id') + ID + '" class="uploadifyQueueItem">\ |
133 |
<div class="cancel">\
|
134 |
<a href="javascript:jQuery(\'#' + jQuery(this).attr('id') + '\').uploadifyCancel(\'' + ID + '\')"><img src="' + settings.cancelImg + '" border="0" /></a>\ |
135 |
</div>\
|
136 |
<span class="fileName">' + fileName + ' (' + byteSize + suffix + ')</span><span class="percentage"></span>\ |
137 |
<div class="uploadifyProgress">\
|
138 |
<div id="' + jQuery(this).attr('id') + ID + 'ProgressBar" class="uploadifyProgressBar"><!--Progress Bar--></div>\ |
139 |
</div>\
|
140 |
</div>');
|
141 |
} |
142 |
}); |
143 |
if (typeof(settings.onSelectOnce) == 'function') { |
144 |
jQuery(this).bind("uploadifySelectOnce", settings.onSelectOnce); |
145 |
} |
146 |
jQuery(this).bind("uploadifyQueueFull", {'action': settings.onQueueFull}, function(event, queueSizeLimit) { |
147 |
if (event.data.action(event, queueSizeLimit) !== false) { |
148 |
alert('The queue is full. The max size is ' + queueSizeLimit + '.'); |
149 |
} |
150 |
}); |
151 |
jQuery(this).bind("uploadifyCheckExist", {'action': settings.onCheck}, function(event, checkScript, fileQueueObj, folder, single) { |
152 |
var postData = new Object(); |
153 |
postData = fileQueueObj; |
154 |
postData.folder = (folder.substr(0,1) == '/') ? folder : pagePath + folder; |
155 |
if (single) {
|
156 |
for (var ID in fileQueueObj) { |
157 |
var singleFileID = ID;
|
158 |
} |
159 |
} |
160 |
jQuery.post(checkScript, postData, function(data) {
|
161 |
for(var key in data) { |
162 |
if (event.data.action(event,data,key) !== false) { |
163 |
var replaceFile = confirm("Do you want to replace the file " + data[key] + "?"); |
164 |
if (!replaceFile) {
|
165 |
document.getElementById(jQuery(event.target).attr('id') + 'Uploader').cancelFileUpload(key,true,true); |
166 |
} |
167 |
} |
168 |
} |
169 |
if (single) {
|
170 |
document.getElementById(jQuery(event.target).attr('id') + 'Uploader').startFileUpload(singleFileID, true); |
171 |
} else {
|
172 |
document.getElementById(jQuery(event.target).attr('id') + 'Uploader').startFileUpload(null, true); |
173 |
} |
174 |
}, "json");
|
175 |
}); |
176 |
jQuery(this).bind("uploadifyCancel", {'action': settings.onCancel}, function(event, ID, fileObj, data, remove, clearFast) { |
177 |
if (event.data.action(event, ID, fileObj, data, clearFast) !== false) { |
178 |
if (remove) {
|
179 |
var fadeSpeed = (clearFast == true) ? 0 : 250; |
180 |
jQuery("#" + jQuery(this).attr('id') + ID).fadeOut(fadeSpeed, function() { jQuery(this).remove() }); |
181 |
} |
182 |
} |
183 |
}); |
184 |
jQuery(this).bind("uploadifyClearQueue", {'action': settings.onClearQueue}, function(event, clearFast) { |
185 |
if (clearFast) {
|
186 |
jQuery("#" + jQuery(this).attr('id') + 'Queue').find('.uploadifyQueueItem').remove(); |
187 |
} |
188 |
if (event.data.action(event, clearFast) !== false) { |
189 |
jQuery("#" + jQuery(this).attr('id') + 'Queue').find('.uploadifyQueueItem').each(function() { |
190 |
var index = jQuery('.uploadifyQueueItem').index(this); |
191 |
jQuery(this).delay(index * 100).fadeOut(250, function() { jQuery(this).remove() }); |
192 |
}); |
193 |
} |
194 |
}); |
195 |
var errorArray = [];
|
196 |
jQuery(this).bind("uploadifyError", {'action': settings.onError}, function(event, ID, fileObj, errorObj) { |
197 |
if (event.data.action(event, ID, fileObj, errorObj) !== false) { |
198 |
var fileArray = new Array(ID, fileObj, errorObj); |
199 |
errorArray.push(fileArray); |
200 |
jQuery("#" + jQuery(this).attr('id') + ID).find('.percentage').text(" - " + errorObj.type + " Error"); |
201 |
jQuery("#" + jQuery(this).attr('id') + ID).addClass('uploadifyError'); |
202 |
} |
203 |
}); |
204 |
if (typeof(settings.onUpload) == 'function') { |
205 |
jQuery(this).bind("uploadifyUpload", settings.onUpload); |
206 |
} |
207 |
jQuery(this).bind("uploadifyProgress", {'action': settings.onProgress, 'toDisplay': settings.displayData}, function(event, ID, fileObj, data) { |
208 |
if (event.data.action(event, ID, fileObj, data) !== false) { |
209 |
jQuery("#" + jQuery(this).attr('id') + ID + "ProgressBar").animate({'width': data.percentage + '%'},250,function() { |
210 |
if (data.percentage == 100) { |
211 |
jQuery(this).closest('.uploadifyProgress').fadeOut(250,function() { jQuery(this).remove(); }); |
212 |
} |
213 |
}); |
214 |
if (event.data.toDisplay == 'percentage') displayData = ' - ' + data.percentage + '%'; |
215 |
if (event.data.toDisplay == 'speed') displayData = ' - ' + data.speed + 'KB/s'; |
216 |
if (event.data.toDisplay == null) displayData = ' '; |
217 |
jQuery("#" + jQuery(this).attr('id') + ID).find('.percentage').text(displayData); |
218 |
} |
219 |
}); |
220 |
jQuery(this).bind("uploadifyComplete", {'action': settings.onComplete}, function(event, ID, fileObj, response, data) { |
221 |
if (event.data.action(event, ID, fileObj, unescape(response), data) !== false) { |
222 |
jQuery("#" + jQuery(this).attr('id') + ID).find('.percentage').text(' - Completed'); |
223 |
if (settings.removeCompleted) {
|
224 |
jQuery("#" + jQuery(event.target).attr('id') + ID).fadeOut(250,function() { jQuery(this).remove() }); |
225 |
} else {
|
226 |
jQuery("#" + jQuery(event.target).attr('id') + ID).addClass('completed'); |
227 |
} |
228 |
} |
229 |
}); |
230 |
if (typeof(settings.onAllComplete) == 'function') { |
231 |
jQuery(this).bind("uploadifyAllComplete", {'action': settings.onAllComplete}, function(event, data) { |
232 |
if (event.data.action(event, data) !== false) { |
233 |
errorArray = []; |
234 |
} |
235 |
}); |
236 |
} |
237 |
}); |
238 |
}, |
239 |
uploadifySettings:function(settingName, settingValue, resetObject) { |
240 |
var returnValue = false; |
241 |
jQuery(this).each(function() { |
242 |
if (settingName == 'scriptData' && settingValue != null) { |
243 |
if (resetObject) {
|
244 |
var scriptData = settingValue;
|
245 |
} else {
|
246 |
var scriptData = jQuery.extend(settings.scriptData, settingValue);
|
247 |
} |
248 |
var scriptDataString = ''; |
249 |
for (var name in scriptData) { |
250 |
scriptDataString += '&' + name + '=' + escape(scriptData[name]); |
251 |
} |
252 |
settingValue = scriptDataString.substr(1);
|
253 |
} |
254 |
returnValue = document.getElementById(jQuery(this).attr('id') + 'Uploader').updateSettings(settingName, settingValue); |
255 |
}); |
256 |
if (settingValue == null) { |
257 |
if (settingName == 'scriptData') { |
258 |
var returnSplit = unescape(returnValue).split('&'); |
259 |
var returnObj = new Object(); |
260 |
for (var i = 0; i < returnSplit.length; i++) { |
261 |
var iSplit = returnSplit[i].split('='); |
262 |
returnObj[iSplit[0]] = iSplit[1]; |
263 |
} |
264 |
returnValue = returnObj; |
265 |
} |
266 |
return returnValue;
|
267 |
} |
268 |
}, |
269 |
uploadifyUpload:function(ID) { |
270 |
jQuery(this).each(function() { |
271 |
document.getElementById(jQuery(this).attr('id') + 'Uploader').startFileUpload(ID, false); |
272 |
}); |
273 |
}, |
274 |
uploadifyCancel:function(ID) { |
275 |
jQuery(this).each(function() { |
276 |
document.getElementById(jQuery(this).attr('id') + 'Uploader').cancelFileUpload(ID, true, true, false); |
277 |
}); |
278 |
}, |
279 |
uploadifyClearQueue:function() { |
280 |
jQuery(this).each(function() { |
281 |
document.getElementById(jQuery(this).attr('id') + 'Uploader').clearFileUploadQueue(false); |
282 |
}); |
283 |
} |
284 |
}) |
285 |
})(jQuery); |