|
|
1
|
+/*
|
|
|
2
|
+UploadiFive 1.2.2
|
|
|
3
|
+Copyright (c) 2012 Reactive Apps, Ronnie Garcia
|
|
|
4
|
+Released under the UploadiFive Standard License <http://www.uploadify.com/uploadifive-standard-license>
|
|
|
5
|
+*/
|
|
|
6
|
+
|
|
|
7
|
+var jQuery = require('yoho-jquery');
|
|
|
8
|
+
|
|
|
9
|
+;(function($) {
|
|
|
10
|
+
|
|
|
11
|
+ var methods = {
|
|
|
12
|
+
|
|
|
13
|
+ init : function(options) {
|
|
|
14
|
+
|
|
|
15
|
+ return this.each(function() {
|
|
|
16
|
+
|
|
|
17
|
+ // Create a reference to the jQuery DOM object
|
|
|
18
|
+ var $this = $(this);
|
|
|
19
|
+ $this.data('uploadifive', {
|
|
|
20
|
+ inputs : {}, // The object that contains all the file inputs
|
|
|
21
|
+ inputCount : 0, // The total number of file inputs created
|
|
|
22
|
+ fileID : 0,
|
|
|
23
|
+ queue : {
|
|
|
24
|
+ count : 0, // Total number of files in the queue
|
|
|
25
|
+ selected : 0, // Number of files selected in the last select operation
|
|
|
26
|
+ replaced : 0, // Number of files replaced in the last select operation
|
|
|
27
|
+ errors : 0, // Number of files that returned an error in the last select operation
|
|
|
28
|
+ queued : 0, // Number of files added to the queue in the last select operation
|
|
|
29
|
+ cancelled : 0 // Total number of files that have been cancelled or removed from the queue
|
|
|
30
|
+ },
|
|
|
31
|
+ uploads : {
|
|
|
32
|
+ current : 0, // Number of files currently being uploaded
|
|
|
33
|
+ attempts : 0, // Number of file uploads attempted in the last upload operation
|
|
|
34
|
+ successful : 0, // Number of files successfully uploaded in the last upload operation
|
|
|
35
|
+ errors : 0, // Number of files returning errors in the last upload operation
|
|
|
36
|
+ count : 0 // Total number of files uploaded successfully
|
|
|
37
|
+ }
|
|
|
38
|
+ });
|
|
|
39
|
+ var $data = $this.data('uploadifive');
|
|
|
40
|
+
|
|
|
41
|
+ // Set the default options
|
|
|
42
|
+ var settings = $data.settings = $.extend({
|
|
|
43
|
+ 'auto' : true, // Automatically upload a file when it's added to the queue
|
|
|
44
|
+ 'buttonClass' : false, // A class to add to the UploadiFive button
|
|
|
45
|
+ 'buttonText' : 'Select Files', // The text that appears on the UploadiFive button
|
|
|
46
|
+ 'checkScript' : false, // Path to the script that checks for existing file names
|
|
|
47
|
+ 'dnd' : true, // Allow drag and drop into the queue
|
|
|
48
|
+ 'dropTarget' : false, // Selector for the drop target
|
|
|
49
|
+ 'fileObjName' : 'Filedata', // The name of the file object to use in your server-side script
|
|
|
50
|
+ 'fileSizeLimit' : 0, // Maximum allowed size of files to upload
|
|
|
51
|
+ 'fileType' : false, // Type of files allowed (image, etc), separate with a pipe character |
|
|
|
52
|
+ 'formData' : {}, // Additional data to send to the upload script
|
|
|
53
|
+ 'height' : 30, // The height of the button
|
|
|
54
|
+ 'itemTemplate' : false, // The HTML markup for the item in the queue
|
|
|
55
|
+ 'method' : 'post', // The method to use when submitting the upload
|
|
|
56
|
+ 'multi' : true, // Set to true to allow multiple file selections
|
|
|
57
|
+ 'overrideEvents' : [], // An array of events to override
|
|
|
58
|
+ 'queueID' : false, // The ID of the file queue
|
|
|
59
|
+ 'queueSizeLimit' : 0, // The maximum number of files that can be in the queue
|
|
|
60
|
+ 'removeCompleted' : false, // Set to true to remove files that have completed uploading
|
|
|
61
|
+ 'simUploadLimit' : 0, // The maximum number of files to upload at once
|
|
|
62
|
+ 'truncateLength' : 0, // The length to truncate the file names to
|
|
|
63
|
+ 'uploadLimit' : 0, // The maximum number of files you can upload
|
|
|
64
|
+ 'uploadScript' : 'uploadifive.php', // The path to the upload script
|
|
|
65
|
+ 'width' : 100 // The width of the button
|
|
|
66
|
+
|
|
|
67
|
+ /*
|
|
|
68
|
+ // Events
|
|
|
69
|
+ 'onAddQueueItem' : function(file) {}, // Triggered for each file that is added to the queue
|
|
|
70
|
+ 'onCancel' : function(file) {}, // Triggered when a file is cancelled or removed from the queue
|
|
|
71
|
+ 'onCheck' : function(file, exists) {}, // Triggered when the server is checked for an existing file
|
|
|
72
|
+ 'onClearQueue' : function(queue) {}, // Triggered during the clearQueue function
|
|
|
73
|
+ 'onDestroy' : function() {} // Triggered during the destroy function
|
|
|
74
|
+ 'onDrop' : function(files, numberOfFilesDropped) {}, // Triggered when files are dropped into the file queue
|
|
|
75
|
+ 'onError' : function(file, fileType, data) {}, // Triggered when an error occurs
|
|
|
76
|
+ 'onFallback' : function() {}, // Triggered if the HTML5 File API is not supported by the browser
|
|
|
77
|
+ 'onInit' : function() {}, // Triggered when UploadiFive if initialized
|
|
|
78
|
+ 'onQueueComplete' : function() {}, // Triggered once when an upload queue is done
|
|
|
79
|
+ 'onProgress' : function(file, event) {}, // Triggered during each progress update of an upload
|
|
|
80
|
+ 'onSelect' : function() {}, // Triggered once when files are selected from a dialog box
|
|
|
81
|
+ 'onUpload' : function(file) {}, // Triggered when an upload queue is started
|
|
|
82
|
+ 'onUploadComplete' : function(file, data) {}, // Triggered when a file is successfully uploaded
|
|
|
83
|
+ 'onUploadFile' : function(file) {}, // Triggered for each file being uploaded
|
|
|
84
|
+ */
|
|
|
85
|
+ }, options);
|
|
|
86
|
+
|
|
|
87
|
+ // Calculate the file size limit
|
|
|
88
|
+ if (isNaN(settings.fileSizeLimit)) {
|
|
|
89
|
+ var fileSizeLimitBytes = parseInt(settings.fileSizeLimit) * 1.024
|
|
|
90
|
+ if (settings.fileSizeLimit.indexOf('KB') > -1) {
|
|
|
91
|
+ settings.fileSizeLimit = fileSizeLimitBytes * 1000;
|
|
|
92
|
+ } else if (settings.fileSizeLimit.indexOf('MB') > -1) {
|
|
|
93
|
+ settings.fileSizeLimit = fileSizeLimitBytes * 1000000;
|
|
|
94
|
+ } else if (settings.fileSizeLimit.indexOf('GB') > -1) {
|
|
|
95
|
+ settings.fileSizeLimit = fileSizeLimitBytes * 1000000000;
|
|
|
96
|
+ }
|
|
|
97
|
+ } else {
|
|
|
98
|
+ settings.fileSizeLimit = settings.fileSizeLimit * 1024;
|
|
|
99
|
+ }
|
|
|
100
|
+
|
|
|
101
|
+ // Create a template for a file input
|
|
|
102
|
+ $data.inputTemplate = $('<input type="file">')
|
|
|
103
|
+ .css({
|
|
|
104
|
+ 'font-size' : settings.height + 'px',
|
|
|
105
|
+ 'opacity' : 0,
|
|
|
106
|
+ 'position' : 'absolute',
|
|
|
107
|
+ 'right' : '-3px',
|
|
|
108
|
+ 'top' : '-3px',
|
|
|
109
|
+ 'z-index' : 999
|
|
|
110
|
+ });
|
|
|
111
|
+
|
|
|
112
|
+ // Create a new input
|
|
|
113
|
+ $data.createInput = function() {
|
|
|
114
|
+
|
|
|
115
|
+ // Create a clone of the file input
|
|
|
116
|
+ var input = $data.inputTemplate.clone();
|
|
|
117
|
+ // Create a unique name for the input item
|
|
|
118
|
+ var inputName = input.name = 'input' + $data.inputCount++;
|
|
|
119
|
+ // Set the multiple attribute
|
|
|
120
|
+ if (settings.multi) {
|
|
|
121
|
+ input.attr('multiple', true);
|
|
|
122
|
+ }
|
|
|
123
|
+ // Set the accept attribute on the input
|
|
|
124
|
+ if (settings.fileType) {
|
|
|
125
|
+ input.attr('accept', settings.fileType);
|
|
|
126
|
+ }
|
|
|
127
|
+ // Set the onchange event for the input
|
|
|
128
|
+ input.bind('change', function() {
|
|
|
129
|
+ $data.queue.selected = 0;
|
|
|
130
|
+ $data.queue.replaced = 0;
|
|
|
131
|
+ $data.queue.errors = 0;
|
|
|
132
|
+ $data.queue.queued = 0;
|
|
|
133
|
+ // Add a queue item to the queue for each file
|
|
|
134
|
+ var limit = this.files.length;
|
|
|
135
|
+ $data.queue.selected = limit;
|
|
|
136
|
+ if (($data.queue.count + limit) > settings.queueSizeLimit && settings.queueSizeLimit !== 0) {
|
|
|
137
|
+ if ($.inArray('onError', settings.overrideEvents) < 0) {
|
|
|
138
|
+ alert('The maximum number of queue items has been reached (' + settings.queueSizeLimit + '). Please select fewer files.');
|
|
|
139
|
+ }
|
|
|
140
|
+ // Trigger the error event
|
|
|
141
|
+ if (typeof settings.onError === 'function') {
|
|
|
142
|
+ settings.onError.call($this, 'QUEUE_LIMIT_EXCEEDED');
|
|
|
143
|
+ }
|
|
|
144
|
+ } else {
|
|
|
145
|
+ for (var n = 0; n < limit; n++) {
|
|
|
146
|
+ file = this.files[n];
|
|
|
147
|
+ $data.addQueueItem(file);
|
|
|
148
|
+ }
|
|
|
149
|
+ $data.inputs[inputName] = this;
|
|
|
150
|
+ $data.createInput();
|
|
|
151
|
+ }
|
|
|
152
|
+ // Upload the file if auto-uploads are enabled
|
|
|
153
|
+ if (settings.auto) {
|
|
|
154
|
+ methods.upload.call($this);
|
|
|
155
|
+ }
|
|
|
156
|
+ // Trigger the select event
|
|
|
157
|
+ if (typeof settings.onSelect === 'function') {
|
|
|
158
|
+ settings.onSelect.call($this, $data.queue);
|
|
|
159
|
+ }
|
|
|
160
|
+ });
|
|
|
161
|
+ // Hide the existing current item and add the new one
|
|
|
162
|
+ if ($data.currentInput) {
|
|
|
163
|
+ $data.currentInput.hide();
|
|
|
164
|
+ }
|
|
|
165
|
+ $data.button.append(input);
|
|
|
166
|
+ $data.currentInput = input;
|
|
|
167
|
+ }
|
|
|
168
|
+
|
|
|
169
|
+ // Remove an input
|
|
|
170
|
+ $data.destroyInput = function(key) {
|
|
|
171
|
+ $($data.inputs[key]).remove();
|
|
|
172
|
+ delete $data.inputs[key];
|
|
|
173
|
+ $data.inputCount--;
|
|
|
174
|
+ }
|
|
|
175
|
+
|
|
|
176
|
+ // Drop a file into the queue
|
|
|
177
|
+ $data.drop = function(e) {
|
|
|
178
|
+ $data.queue.selected = 0;
|
|
|
179
|
+ $data.queue.replaced = 0;
|
|
|
180
|
+ $data.queue.errors = 0;
|
|
|
181
|
+ $data.queue.queued = 0;
|
|
|
182
|
+
|
|
|
183
|
+ var fileData = e.dataTransfer;
|
|
|
184
|
+
|
|
|
185
|
+ var inputName = fileData.name = 'input' + $data.inputCount++;
|
|
|
186
|
+ // Add a queue item to the queue for each file
|
|
|
187
|
+ var limit = fileData.files.length;
|
|
|
188
|
+ $data.queue.selected = limit;
|
|
|
189
|
+ if (($data.queue.count + limit) > settings.queueSizeLimit && settings.queueSizeLimit !== 0) {
|
|
|
190
|
+ // Check if the queueSizeLimit was reached
|
|
|
191
|
+ if ($.inArray('onError', settings.overrideEvents) < 0) {
|
|
|
192
|
+ alert('The maximum number of queue items has been reached (' + settings.queueSizeLimit + '). Please select fewer files.');
|
|
|
193
|
+ }
|
|
|
194
|
+ // Trigger the onError event
|
|
|
195
|
+ if (typeof settings.onError === 'function') {
|
|
|
196
|
+ settings.onError.call($this, 'QUEUE_LIMIT_EXCEEDED');
|
|
|
197
|
+ }
|
|
|
198
|
+ } else {
|
|
|
199
|
+ // Add a queue item for each file
|
|
|
200
|
+ for (var n = 0; n < limit; n++) {
|
|
|
201
|
+ file = fileData.files[n];
|
|
|
202
|
+ $data.addQueueItem(file);
|
|
|
203
|
+ }
|
|
|
204
|
+ // Save the data to the inputs object
|
|
|
205
|
+ $data.inputs[inputName] = fileData;
|
|
|
206
|
+ }
|
|
|
207
|
+
|
|
|
208
|
+ // Upload the file if auto-uploads are enabled
|
|
|
209
|
+ if (settings.auto) {
|
|
|
210
|
+ methods.upload.call($this);
|
|
|
211
|
+ }
|
|
|
212
|
+
|
|
|
213
|
+ // Trigger the onDrop event
|
|
|
214
|
+ if (typeof settings.onDrop === 'function') {
|
|
|
215
|
+ settings.onDrop.call($this, fileData.files, fileData.files.length);
|
|
|
216
|
+ }
|
|
|
217
|
+
|
|
|
218
|
+ // Stop FireFox from opening the dropped file(s)
|
|
|
219
|
+ e.preventDefault();
|
|
|
220
|
+ e.stopPropagation();
|
|
|
221
|
+ }
|
|
|
222
|
+
|
|
|
223
|
+ // Check if a filename exists in the queue
|
|
|
224
|
+ $data.fileExistsInQueue = function(file) {
|
|
|
225
|
+ for (var key in $data.inputs) {
|
|
|
226
|
+ input = $data.inputs[key];
|
|
|
227
|
+ limit = input.files.length;
|
|
|
228
|
+ for (var n = 0; n < limit; n++) {
|
|
|
229
|
+ existingFile = input.files[n];
|
|
|
230
|
+ // Check if the filename matches
|
|
|
231
|
+ if (existingFile.name == file.name && !existingFile.complete) {
|
|
|
232
|
+ return true;
|
|
|
233
|
+ }
|
|
|
234
|
+ }
|
|
|
235
|
+ }
|
|
|
236
|
+ return false;
|
|
|
237
|
+ }
|
|
|
238
|
+
|
|
|
239
|
+ // Remove an existing file in the queue
|
|
|
240
|
+ $data.removeExistingFile = function(file) {
|
|
|
241
|
+ for (var key in $data.inputs) {
|
|
|
242
|
+ input = $data.inputs[key];
|
|
|
243
|
+ limit = input.files.length;
|
|
|
244
|
+ for (var n = 0; n < limit; n++) {
|
|
|
245
|
+ existingFile = input.files[n];
|
|
|
246
|
+ // Check if the filename matches
|
|
|
247
|
+ if (existingFile.name == file.name && !existingFile.complete) {
|
|
|
248
|
+ $data.queue.replaced++;
|
|
|
249
|
+ methods.cancel.call($this, existingFile, true);
|
|
|
250
|
+ }
|
|
|
251
|
+ }
|
|
|
252
|
+ }
|
|
|
253
|
+ }
|
|
|
254
|
+
|
|
|
255
|
+ // Create the file item template
|
|
|
256
|
+ if (settings.itemTemplate == false) {
|
|
|
257
|
+ $data.queueItem = $('<div class="uploadifive-queue-item">\
|
|
|
258
|
+ <a class="close" href="#">X</a>\
|
|
|
259
|
+ <div><span class="filename"></span><span class="fileinfo"></span></div>\
|
|
|
260
|
+ <div class="progress">\
|
|
|
261
|
+ <div class="progress-bar"></div>\
|
|
|
262
|
+ </div>\
|
|
|
263
|
+ </div>');
|
|
|
264
|
+ } else {
|
|
|
265
|
+ $data.queueItem = $(settings.itemTemplate);
|
|
|
266
|
+ }
|
|
|
267
|
+
|
|
|
268
|
+ // Add an item to the queue
|
|
|
269
|
+ $data.addQueueItem = function(file) {
|
|
|
270
|
+ if ($.inArray('onAddQueueItem', settings.overrideEvents) < 0) {
|
|
|
271
|
+ // Check if the filename already exists in the queue
|
|
|
272
|
+ $data.removeExistingFile(file);
|
|
|
273
|
+ // Create a clone of the queue item template
|
|
|
274
|
+ file.queueItem = $data.queueItem.clone();
|
|
|
275
|
+ // Add an ID to the queue item
|
|
|
276
|
+ file.queueItem.attr('id', settings.id + '-file-' + $data.fileID++);
|
|
|
277
|
+ // Bind the close event to the close button
|
|
|
278
|
+ file.queueItem.find('.close').bind('click', function() {
|
|
|
279
|
+ methods.cancel.call($this, file);
|
|
|
280
|
+ return false;
|
|
|
281
|
+ });
|
|
|
282
|
+ var fileName = file.name;
|
|
|
283
|
+ if (fileName.length > settings.truncateLength && settings.truncateLength != 0) {
|
|
|
284
|
+ fileName = fileName.substring(0, settings.truncateLength) + '...';
|
|
|
285
|
+ }
|
|
|
286
|
+ file.queueItem.find('.filename').html(fileName);
|
|
|
287
|
+ // Add a reference to the file
|
|
|
288
|
+ file.queueItem.data('file', file);
|
|
|
289
|
+ $data.queueEl.append(file.queueItem);
|
|
|
290
|
+ }
|
|
|
291
|
+ // Trigger the addQueueItem event
|
|
|
292
|
+ if (typeof settings.onAddQueueItem === 'function') {
|
|
|
293
|
+ settings.onAddQueueItem.call($this, file);
|
|
|
294
|
+ }
|
|
|
295
|
+ // Check the filesize
|
|
|
296
|
+ if (file.size > settings.fileSizeLimit && settings.fileSizeLimit != 0) {
|
|
|
297
|
+ $data.error('FILE_SIZE_LIMIT_EXCEEDED', file);
|
|
|
298
|
+ } else {
|
|
|
299
|
+ $data.queue.queued++;
|
|
|
300
|
+ $data.queue.count++;
|
|
|
301
|
+ }
|
|
|
302
|
+ }
|
|
|
303
|
+
|
|
|
304
|
+ // Remove an item from the queue
|
|
|
305
|
+ $data.removeQueueItem = function(file, instant, delay) {
|
|
|
306
|
+ // Set the default delay
|
|
|
307
|
+ if (!delay) delay = 0;
|
|
|
308
|
+ var fadeTime = instant ? 0 : 500;
|
|
|
309
|
+ if (file.queueItem) {
|
|
|
310
|
+ if (file.queueItem.find('.fileinfo').html() != ' - Completed') {
|
|
|
311
|
+ file.queueItem.find('.fileinfo').html(' - Cancelled');
|
|
|
312
|
+ }
|
|
|
313
|
+ file.queueItem.find('.progress-bar').width(0);
|
|
|
314
|
+ file.queueItem.delay(delay).fadeOut(fadeTime, function() {
|
|
|
315
|
+ $(this).remove();
|
|
|
316
|
+ });
|
|
|
317
|
+ delete file.queueItem;
|
|
|
318
|
+ $data.queue.count--;
|
|
|
319
|
+ }
|
|
|
320
|
+ }
|
|
|
321
|
+
|
|
|
322
|
+ // Count the number of files that need to be uploaded
|
|
|
323
|
+ $data.filesToUpload = function() {
|
|
|
324
|
+ var filesToUpload = 0;
|
|
|
325
|
+ for (var key in $data.inputs) {
|
|
|
326
|
+ input = $data.inputs[key];
|
|
|
327
|
+ limit = input.files.length;
|
|
|
328
|
+ for (var n = 0; n < limit; n++) {
|
|
|
329
|
+ file = input.files[n];
|
|
|
330
|
+ if (!file.skip && !file.complete) {
|
|
|
331
|
+ filesToUpload++;
|
|
|
332
|
+ }
|
|
|
333
|
+ }
|
|
|
334
|
+ }
|
|
|
335
|
+ return filesToUpload;
|
|
|
336
|
+ }
|
|
|
337
|
+
|
|
|
338
|
+ // Check if a file exists
|
|
|
339
|
+ $data.checkExists = function(file) {
|
|
|
340
|
+ if ($.inArray('onCheck', settings.overrideEvents) < 0) {
|
|
|
341
|
+ // This request needs to be synchronous
|
|
|
342
|
+ $.ajaxSetup({
|
|
|
343
|
+ 'async' : false
|
|
|
344
|
+ });
|
|
|
345
|
+ // Send the filename to the check script
|
|
|
346
|
+ var checkData = $.extend(settings.formData, {filename: file.name});
|
|
|
347
|
+ $.post(settings.checkScript, checkData, function(fileExists) {
|
|
|
348
|
+ file.exists = parseInt(fileExists);
|
|
|
349
|
+ });
|
|
|
350
|
+ if (file.exists) {
|
|
|
351
|
+ if (!confirm('A file named ' + file.name + ' already exists in the upload folder.\nWould you like to replace it?')) {
|
|
|
352
|
+ // If not replacing the file, cancel the upload
|
|
|
353
|
+ methods.cancel.call($this, file);
|
|
|
354
|
+ return true;
|
|
|
355
|
+ }
|
|
|
356
|
+ }
|
|
|
357
|
+ }
|
|
|
358
|
+ // Trigger the check event
|
|
|
359
|
+ if (typeof settings.onCheck === 'function') {
|
|
|
360
|
+ settings.onCheck.call($this, file, file.exists);
|
|
|
361
|
+ }
|
|
|
362
|
+ return false;
|
|
|
363
|
+ }
|
|
|
364
|
+
|
|
|
365
|
+ // Upload a single file
|
|
|
366
|
+ $data.uploadFile = function(file, uploadAll) {
|
|
|
367
|
+ if (!file.skip && !file.complete && !file.uploading) {
|
|
|
368
|
+ file.uploading = true;
|
|
|
369
|
+ $data.uploads.current++;
|
|
|
370
|
+ $data.uploads.attempted++;
|
|
|
371
|
+
|
|
|
372
|
+ // Create a new AJAX request
|
|
|
373
|
+ xhr = file.xhr = new XMLHttpRequest();
|
|
|
374
|
+
|
|
|
375
|
+ // Start the upload
|
|
|
376
|
+ // Use the faster FormData if it exists
|
|
|
377
|
+ if (typeof FormData === 'function' || typeof FormData === 'object') {
|
|
|
378
|
+
|
|
|
379
|
+ // Create a new FormData object
|
|
|
380
|
+ var formData = new FormData();
|
|
|
381
|
+
|
|
|
382
|
+ // Add the form data
|
|
|
383
|
+ formData.append(settings.fileObjName, file);
|
|
|
384
|
+
|
|
|
385
|
+ // Add the rest of the formData
|
|
|
386
|
+ for (i in settings.formData) {
|
|
|
387
|
+ formData.append(i, settings.formData[i]);
|
|
|
388
|
+ }
|
|
|
389
|
+
|
|
|
390
|
+ // Open the AJAX call
|
|
|
391
|
+ xhr.open(settings.method, settings.uploadScript, true);
|
|
|
392
|
+
|
|
|
393
|
+ // On progress function
|
|
|
394
|
+ xhr.upload.addEventListener('progress', function(e) {
|
|
|
395
|
+ if (e.lengthComputable) {
|
|
|
396
|
+ $data.progress(e, file);
|
|
|
397
|
+ }
|
|
|
398
|
+ }, false);
|
|
|
399
|
+
|
|
|
400
|
+ // On complete function
|
|
|
401
|
+ xhr.addEventListener('load', function(e) {
|
|
|
402
|
+ if (this.readyState == 4) {
|
|
|
403
|
+ file.uploading = false;
|
|
|
404
|
+ if (this.status == 200) {
|
|
|
405
|
+ if (file.xhr.responseText !== 'Invalid file type.') {
|
|
|
406
|
+ $data.uploadComplete(e, file, uploadAll);
|
|
|
407
|
+ } else {
|
|
|
408
|
+ $data.error(file.xhr.responseText, file, uploadAll);
|
|
|
409
|
+ }
|
|
|
410
|
+ } else if (this.status == 404) {
|
|
|
411
|
+ $data.error('404_FILE_NOT_FOUND', file, uploadAll);
|
|
|
412
|
+ } else if (this.status == 403) {
|
|
|
413
|
+ $data.error('403_FORBIDDEN', file, uploadAll);
|
|
|
414
|
+ } else {
|
|
|
415
|
+ $data.error('Unknown Error', file, uploadAll);
|
|
|
416
|
+ }
|
|
|
417
|
+ }
|
|
|
418
|
+ });
|
|
|
419
|
+
|
|
|
420
|
+ // Send the form data (multipart/form-data)
|
|
|
421
|
+ xhr.send(formData);
|
|
|
422
|
+
|
|
|
423
|
+ } else {
|
|
|
424
|
+
|
|
|
425
|
+ // Send as binary
|
|
|
426
|
+ var reader = new FileReader();
|
|
|
427
|
+ reader.onload = function(e) {
|
|
|
428
|
+
|
|
|
429
|
+ // Set some file builder variables
|
|
|
430
|
+ var boundary = '-------------------------' + (new Date).getTime(),
|
|
|
431
|
+ dashes = '--',
|
|
|
432
|
+ eol = '\r\n',
|
|
|
433
|
+ binFile = '';
|
|
|
434
|
+
|
|
|
435
|
+ // Build an RFC2388 String
|
|
|
436
|
+ binFile += dashes + boundary + eol;
|
|
|
437
|
+ // Generate the headers
|
|
|
438
|
+ binFile += 'Content-Disposition: form-data; name="' + settings.fileObjName + '"';
|
|
|
439
|
+ if (file.name) {
|
|
|
440
|
+ binFile += '; filename="' + file.name + '"';
|
|
|
441
|
+ }
|
|
|
442
|
+ binFile += eol;
|
|
|
443
|
+ binFile += 'Content-Type: application/octet-stream' + eol + eol;
|
|
|
444
|
+ binFile += e.target.result + eol;
|
|
|
445
|
+
|
|
|
446
|
+ for (key in settings.formData) {
|
|
|
447
|
+ binFile += dashes + boundary + eol;
|
|
|
448
|
+ binFile += 'Content-Disposition: form-data; name="' + key + '"' + eol + eol;
|
|
|
449
|
+ binFile += settings.formData[key] + eol;
|
|
|
450
|
+ }
|
|
|
451
|
+
|
|
|
452
|
+ binFile += dashes + boundary + dashes + eol;
|
|
|
453
|
+
|
|
|
454
|
+ // On progress function
|
|
|
455
|
+ xhr.upload.addEventListener('progress', function(e) {
|
|
|
456
|
+ $data.progress(e, file);
|
|
|
457
|
+ }, false);
|
|
|
458
|
+
|
|
|
459
|
+ // On complete function
|
|
|
460
|
+ xhr.addEventListener('load', function(e) {
|
|
|
461
|
+ file.uploading = false;
|
|
|
462
|
+ var status = this.status;
|
|
|
463
|
+ if (status == 404) {
|
|
|
464
|
+ $data.error('404_FILE_NOT_FOUND', file, uploadAll);
|
|
|
465
|
+ } else {
|
|
|
466
|
+ if (file.xhr.responseText != 'Invalid file type.') {
|
|
|
467
|
+ $data.uploadComplete(e, file, uploadAll);
|
|
|
468
|
+ } else {
|
|
|
469
|
+ $data.error(file.xhr.responseText, file, uploadAll);
|
|
|
470
|
+ }
|
|
|
471
|
+ }
|
|
|
472
|
+ }, false);
|
|
|
473
|
+
|
|
|
474
|
+ // Open the ajax request
|
|
|
475
|
+ var url = settings.uploadScript;
|
|
|
476
|
+ if (settings.method == 'get') {
|
|
|
477
|
+ var params = $(settings.formData).param();
|
|
|
478
|
+ url += params;
|
|
|
479
|
+ }
|
|
|
480
|
+ xhr.open(settings.method, settings.uploadScript, true);
|
|
|
481
|
+ xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary);
|
|
|
482
|
+
|
|
|
483
|
+ // Trigger the uploadFile event
|
|
|
484
|
+ if (typeof settings.onUploadFile === 'function') {
|
|
|
485
|
+ settings.onUploadFile.call($this, file);
|
|
|
486
|
+ }
|
|
|
487
|
+
|
|
|
488
|
+ // Send the file for upload
|
|
|
489
|
+ xhr.sendAsBinary(binFile);
|
|
|
490
|
+ }
|
|
|
491
|
+ reader.readAsBinaryString(file);
|
|
|
492
|
+
|
|
|
493
|
+ }
|
|
|
494
|
+ }
|
|
|
495
|
+ }
|
|
|
496
|
+
|
|
|
497
|
+ // Update a file upload's progress
|
|
|
498
|
+ $data.progress = function(e, file) {
|
|
|
499
|
+ if ($.inArray('onProgress', settings.overrideEvents) < 0) {
|
|
|
500
|
+ if (e.lengthComputable) {
|
|
|
501
|
+ var percent = Math.round((e.loaded / e.total) * 100);
|
|
|
502
|
+ }
|
|
|
503
|
+ file.queueItem.find('.fileinfo').html(' - ' + percent + '%');
|
|
|
504
|
+ file.queueItem.find('.progress-bar').css('width', percent + '%');
|
|
|
505
|
+ }
|
|
|
506
|
+ // Trigger the progress event
|
|
|
507
|
+ if (typeof settings.onProgress === 'function') {
|
|
|
508
|
+ settings.onProgress.call($this, file, e);
|
|
|
509
|
+ }
|
|
|
510
|
+ }
|
|
|
511
|
+
|
|
|
512
|
+ // Trigger an error
|
|
|
513
|
+ $data.error = function(errorType, file, uploadAll) {
|
|
|
514
|
+ if ($.inArray('onError', settings.overrideEvents) < 0) {
|
|
|
515
|
+ // Get the error message
|
|
|
516
|
+ switch(errorType) {
|
|
|
517
|
+ case '404_FILE_NOT_FOUND':
|
|
|
518
|
+ errorMsg = '404 Error';
|
|
|
519
|
+ break;
|
|
|
520
|
+ case '403_FORBIDDEN':
|
|
|
521
|
+ errorMsg = '403 Forbidden';
|
|
|
522
|
+ break;
|
|
|
523
|
+ case 'FORBIDDEN_FILE_TYPE':
|
|
|
524
|
+ errorMsg = 'Forbidden File Type';
|
|
|
525
|
+ break;
|
|
|
526
|
+ case 'FILE_SIZE_LIMIT_EXCEEDED':
|
|
|
527
|
+ errorMsg = 'File Too Large';
|
|
|
528
|
+ break;
|
|
|
529
|
+ default:
|
|
|
530
|
+ errorMsg = 'Unknown Error';
|
|
|
531
|
+ break;
|
|
|
532
|
+ }
|
|
|
533
|
+
|
|
|
534
|
+ // Add the error class to the queue item
|
|
|
535
|
+ file.queueItem.addClass('error')
|
|
|
536
|
+ // Output the error in the queue item
|
|
|
537
|
+ .find('.fileinfo').html(' - ' + errorMsg);
|
|
|
538
|
+ // Hide the
|
|
|
539
|
+ file.queueItem.find('.progress').remove();
|
|
|
540
|
+ }
|
|
|
541
|
+ // Trigger the error event
|
|
|
542
|
+ if (typeof settings.onError === 'function') {
|
|
|
543
|
+ settings.onError.call($this, errorType, file);
|
|
|
544
|
+ }
|
|
|
545
|
+ file.skip = true;
|
|
|
546
|
+ if (errorType == '404_FILE_NOT_FOUND') {
|
|
|
547
|
+ $data.uploads.errors++;
|
|
|
548
|
+ } else {
|
|
|
549
|
+ $data.queue.errors++;
|
|
|
550
|
+ }
|
|
|
551
|
+ if (uploadAll) {
|
|
|
552
|
+ methods.upload.call($this, null, true);
|
|
|
553
|
+ }
|
|
|
554
|
+ }
|
|
|
555
|
+
|
|
|
556
|
+ // Trigger when a single file upload is complete
|
|
|
557
|
+ $data.uploadComplete = function(e, file, uploadAll) {
|
|
|
558
|
+ if ($.inArray('onUploadComplete', settings.overrideEvents) < 0) {
|
|
|
559
|
+ file.queueItem.find('.progress-bar').css('width', '100%');
|
|
|
560
|
+ file.queueItem.find('.fileinfo').html(' - Completed');
|
|
|
561
|
+ file.queueItem.find('.progress').slideUp(250);
|
|
|
562
|
+ file.queueItem.addClass('complete');
|
|
|
563
|
+ }
|
|
|
564
|
+ // Trigger the complete event
|
|
|
565
|
+ if (typeof settings.onUploadComplete === 'function') {
|
|
|
566
|
+ settings.onUploadComplete.call($this, file, file.xhr.responseText);
|
|
|
567
|
+ }
|
|
|
568
|
+ if (settings.removeCompleted) {
|
|
|
569
|
+ setTimeout(function() { methods.cancel.call($this, file); }, 3000);
|
|
|
570
|
+ }
|
|
|
571
|
+ file.complete = true;
|
|
|
572
|
+ $data.uploads.successful++;
|
|
|
573
|
+ $data.uploads.count++;
|
|
|
574
|
+ $data.uploads.current--;
|
|
|
575
|
+ delete file.xhr;
|
|
|
576
|
+ if (uploadAll) {
|
|
|
577
|
+ methods.upload.call($this, null, true);
|
|
|
578
|
+ }
|
|
|
579
|
+ }
|
|
|
580
|
+
|
|
|
581
|
+ // Trigger when all the files are done uploading
|
|
|
582
|
+ $data.queueComplete = function() {
|
|
|
583
|
+ // Trigger the queueComplete event
|
|
|
584
|
+ if (typeof settings.onQueueComplete === 'function') {
|
|
|
585
|
+ settings.onQueueComplete.call($this, $data.uploads);
|
|
|
586
|
+ }
|
|
|
587
|
+ }
|
|
|
588
|
+
|
|
|
589
|
+ // ----------------------
|
|
|
590
|
+ // Initialize UploadiFive
|
|
|
591
|
+ // ----------------------
|
|
|
592
|
+
|
|
|
593
|
+ // Check if HTML5 is available
|
|
|
594
|
+ if (window.File && window.FileList && window.Blob && (window.FileReader || window.FormData)) {
|
|
|
595
|
+ // Assign an ID to the object
|
|
|
596
|
+ settings.id = 'uploadifive-' + $this.attr('id');
|
|
|
597
|
+
|
|
|
598
|
+ // Wrap the file input in a div with overflow set to hidden
|
|
|
599
|
+ $data.button = $('<div id="' + settings.id + '" class="uploadifive-button">' + settings.buttonText + '</div>');
|
|
|
600
|
+ if (settings.buttonClass) $data.button.addClass(settings.buttonClass);
|
|
|
601
|
+
|
|
|
602
|
+ // Style the button wrapper
|
|
|
603
|
+ $data.button.css({
|
|
|
604
|
+ 'height' : settings.height,
|
|
|
605
|
+ 'line-height' : settings.height + 'px',
|
|
|
606
|
+ 'overflow' : 'hidden',
|
|
|
607
|
+ 'position' : 'relative',
|
|
|
608
|
+ 'text-align' : 'center',
|
|
|
609
|
+ 'width' : settings.width
|
|
|
610
|
+ });
|
|
|
611
|
+
|
|
|
612
|
+ // Insert the button above the file input
|
|
|
613
|
+ $this.before($data.button)
|
|
|
614
|
+ // Add the file input to the button
|
|
|
615
|
+ .appendTo($data.button)
|
|
|
616
|
+ // Modify the styles of the file input
|
|
|
617
|
+ .hide();
|
|
|
618
|
+
|
|
|
619
|
+ // Create a new input
|
|
|
620
|
+ $data.createInput.call($this);
|
|
|
621
|
+
|
|
|
622
|
+ // Create the queue container
|
|
|
623
|
+ if (!settings.queueID) {
|
|
|
624
|
+ settings.queueID = settings.id + '-queue';
|
|
|
625
|
+ $data.queueEl = $('<div id="' + settings.queueID + '" class="uploadifive-queue" />');
|
|
|
626
|
+ $data.button.after($data.queueEl);
|
|
|
627
|
+ } else {
|
|
|
628
|
+ $data.queueEl = $('#' + settings.queueID);
|
|
|
629
|
+ }
|
|
|
630
|
+
|
|
|
631
|
+ // Add drag and drop functionality
|
|
|
632
|
+ if (settings.dnd) {
|
|
|
633
|
+ var $dropTarget = settings.dropTarget ? $(settings.dropTarget) : $data.queueEl.get(0);
|
|
|
634
|
+ $dropTarget.addEventListener('dragleave', function(e) {
|
|
|
635
|
+ // Stop FireFox from opening the dropped file(s)
|
|
|
636
|
+ e.preventDefault();
|
|
|
637
|
+ e.stopPropagation();
|
|
|
638
|
+ }, false);
|
|
|
639
|
+ $dropTarget.addEventListener('dragenter', function(e) {
|
|
|
640
|
+ // Stop FireFox from opening the dropped file(s)
|
|
|
641
|
+ e.preventDefault();
|
|
|
642
|
+ e.stopPropagation();
|
|
|
643
|
+ }, false);
|
|
|
644
|
+ $dropTarget.addEventListener('dragover', function(e) {
|
|
|
645
|
+ // Stop FireFox from opening the dropped file(s)
|
|
|
646
|
+ e.preventDefault();
|
|
|
647
|
+ e.stopPropagation();
|
|
|
648
|
+ }, false);
|
|
|
649
|
+ $dropTarget.addEventListener('drop', $data.drop, false);
|
|
|
650
|
+ }
|
|
|
651
|
+
|
|
|
652
|
+ // Send as binary workaround for Chrome
|
|
|
653
|
+ if (!XMLHttpRequest.prototype.sendAsBinary) {
|
|
|
654
|
+ XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
|
|
|
655
|
+ function byteValue(x) {
|
|
|
656
|
+ return x.charCodeAt(0) & 0xff;
|
|
|
657
|
+ }
|
|
|
658
|
+ var ords = Array.prototype.map.call(datastr, byteValue);
|
|
|
659
|
+ var ui8a = new Uint8Array(ords);
|
|
|
660
|
+ this.send(ui8a.buffer);
|
|
|
661
|
+ }
|
|
|
662
|
+ }
|
|
|
663
|
+
|
|
|
664
|
+ // Trigger the oninit event
|
|
|
665
|
+ if (typeof settings.onInit === 'function') {
|
|
|
666
|
+ settings.onInit.call($this);
|
|
|
667
|
+ }
|
|
|
668
|
+
|
|
|
669
|
+ } else {
|
|
|
670
|
+
|
|
|
671
|
+ // Trigger the fallback event
|
|
|
672
|
+ if (typeof settings.onFallback === 'function') {
|
|
|
673
|
+ settings.onFallback.call($this);
|
|
|
674
|
+ }
|
|
|
675
|
+ return false;
|
|
|
676
|
+
|
|
|
677
|
+ }
|
|
|
678
|
+
|
|
|
679
|
+ });
|
|
|
680
|
+
|
|
|
681
|
+ },
|
|
|
682
|
+
|
|
|
683
|
+
|
|
|
684
|
+ // Write some data to the console
|
|
|
685
|
+ debug : function() {
|
|
|
686
|
+
|
|
|
687
|
+ return this.each(function() {
|
|
|
688
|
+
|
|
|
689
|
+ console.log($(this).data('uploadifive'));
|
|
|
690
|
+
|
|
|
691
|
+ });
|
|
|
692
|
+
|
|
|
693
|
+ },
|
|
|
694
|
+
|
|
|
695
|
+ // Clear all the items from the queue
|
|
|
696
|
+ clearQueue : function() {
|
|
|
697
|
+
|
|
|
698
|
+ this.each(function() {
|
|
|
699
|
+
|
|
|
700
|
+ var $this = $(this),
|
|
|
701
|
+ $data = $this.data('uploadifive'),
|
|
|
702
|
+ settings = $data.settings;
|
|
|
703
|
+
|
|
|
704
|
+ for (var key in $data.inputs) {
|
|
|
705
|
+ input = $data.inputs[key];
|
|
|
706
|
+ limit = input.files.length;
|
|
|
707
|
+ for (i = 0; i < limit; i++) {
|
|
|
708
|
+ file = input.files[i];
|
|
|
709
|
+ methods.cancel.call($this, file);
|
|
|
710
|
+ }
|
|
|
711
|
+ }
|
|
|
712
|
+ // Trigger the onClearQueue event
|
|
|
713
|
+ if (typeof settings.onClearQueue === 'function') {
|
|
|
714
|
+ settings.onClearQueue.call($this, $('#' + $data.settings.queueID));
|
|
|
715
|
+ }
|
|
|
716
|
+
|
|
|
717
|
+ });
|
|
|
718
|
+
|
|
|
719
|
+ },
|
|
|
720
|
+
|
|
|
721
|
+ // Cancel a file upload in progress or remove a file from the queue
|
|
|
722
|
+ cancel : function(file, fast) {
|
|
|
723
|
+
|
|
|
724
|
+ this.each(function() {
|
|
|
725
|
+
|
|
|
726
|
+ var $this = $(this),
|
|
|
727
|
+ $data = $this.data('uploadifive'),
|
|
|
728
|
+ settings = $data.settings;
|
|
|
729
|
+
|
|
|
730
|
+ // If user passed a queue item ID instead of file...
|
|
|
731
|
+ if (typeof file === 'string') {
|
|
|
732
|
+ if (!isNaN(file)) {
|
|
|
733
|
+ fileID = 'uploadifive-' + $(this).attr('id') + '-file-' + file;
|
|
|
734
|
+ }
|
|
|
735
|
+ file = $('#' + fileID).data('file');
|
|
|
736
|
+ }
|
|
|
737
|
+
|
|
|
738
|
+ file.skip = true;
|
|
|
739
|
+ $data.filesCancelled++;
|
|
|
740
|
+ if (file.uploading) {
|
|
|
741
|
+ $data.uploads.current--;
|
|
|
742
|
+ file.uploading = false;
|
|
|
743
|
+ file.xhr.abort();
|
|
|
744
|
+ delete file.xhr;
|
|
|
745
|
+ methods.upload.call($this);
|
|
|
746
|
+ }
|
|
|
747
|
+ if ($.inArray('onCancel', settings.overrideEvents) < 0) {
|
|
|
748
|
+ $data.removeQueueItem(file, fast);
|
|
|
749
|
+ }
|
|
|
750
|
+
|
|
|
751
|
+ // Trigger the cancel event
|
|
|
752
|
+ if (typeof settings.onCancel === 'function') {
|
|
|
753
|
+ settings.onCancel.call($this, file);
|
|
|
754
|
+ }
|
|
|
755
|
+
|
|
|
756
|
+ });
|
|
|
757
|
+
|
|
|
758
|
+ },
|
|
|
759
|
+
|
|
|
760
|
+ // Upload the files in the queue
|
|
|
761
|
+ upload : function(file, keepVars) {
|
|
|
762
|
+
|
|
|
763
|
+ this.each(function() {
|
|
|
764
|
+
|
|
|
765
|
+ var $this = $(this),
|
|
|
766
|
+ $data = $this.data('uploadifive'),
|
|
|
767
|
+ settings = $data.settings;
|
|
|
768
|
+
|
|
|
769
|
+ if (file) {
|
|
|
770
|
+
|
|
|
771
|
+ $data.uploadFile.call($this, file);
|
|
|
772
|
+
|
|
|
773
|
+ } else {
|
|
|
774
|
+
|
|
|
775
|
+ // Check if the upload limit was reached
|
|
|
776
|
+ if (($data.uploads.count + $data.uploads.current) < settings.uploadLimit || settings.uploadLimit == 0) {
|
|
|
777
|
+ if (!keepVars) {
|
|
|
778
|
+ $data.uploads.attempted = 0;
|
|
|
779
|
+ $data.uploads.successsful = 0;
|
|
|
780
|
+ $data.uploads.errors = 0;
|
|
|
781
|
+ var filesToUpload = $data.filesToUpload();
|
|
|
782
|
+ // Trigger the onUpload event
|
|
|
783
|
+ if (typeof settings.onUpload === 'function') {
|
|
|
784
|
+ settings.onUpload.call($this, filesToUpload);
|
|
|
785
|
+ }
|
|
|
786
|
+ }
|
|
|
787
|
+
|
|
|
788
|
+ // Loop through the files
|
|
|
789
|
+ $('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').each(function() {
|
|
|
790
|
+ _file = $(this).data('file');
|
|
|
791
|
+ // Check if the simUpload limit was reached
|
|
|
792
|
+ if (($data.uploads.current >= settings.simUploadLimit && settings.simUploadLimit !== 0) || ($data.uploads.current >= settings.uploadLimit && settings.uploadLimit !== 0) || ($data.uploads.count >= settings.uploadLimit && settings.uploadLimit !== 0)) {
|
|
|
793
|
+ return false;
|
|
|
794
|
+ }
|
|
|
795
|
+ if (settings.checkScript) {
|
|
|
796
|
+ // Let the loop know that we're already processing this file
|
|
|
797
|
+ _file.checking = true;
|
|
|
798
|
+ skipFile = $data.checkExists(_file);
|
|
|
799
|
+ _file.checking = false;
|
|
|
800
|
+ if (!skipFile) {
|
|
|
801
|
+ $data.uploadFile(_file, true);
|
|
|
802
|
+ }
|
|
|
803
|
+ } else {
|
|
|
804
|
+ $data.uploadFile(_file, true);
|
|
|
805
|
+ }
|
|
|
806
|
+ });
|
|
|
807
|
+ if ($('#' + settings.queueID).find('.uploadifive-queue-item').not('.error, .complete').size() == 0) {
|
|
|
808
|
+ $data.queueComplete();
|
|
|
809
|
+ }
|
|
|
810
|
+ } else {
|
|
|
811
|
+ if ($data.uploads.current == 0) {
|
|
|
812
|
+ if ($.inArray('onError', settings.overrideEvents) < 0) {
|
|
|
813
|
+ if ($data.filesToUpload() > 0 && settings.uploadLimit != 0) {
|
|
|
814
|
+ alert('The maximum upload limit has been reached.');
|
|
|
815
|
+ }
|
|
|
816
|
+ }
|
|
|
817
|
+ // Trigger the onError event
|
|
|
818
|
+ if (typeof settings.onError === 'function') {
|
|
|
819
|
+ settings.onError.call($this, 'UPLOAD_LIMIT_EXCEEDED', $data.filesToUpload());
|
|
|
820
|
+ }
|
|
|
821
|
+ }
|
|
|
822
|
+ }
|
|
|
823
|
+
|
|
|
824
|
+ }
|
|
|
825
|
+
|
|
|
826
|
+ });
|
|
|
827
|
+
|
|
|
828
|
+ },
|
|
|
829
|
+
|
|
|
830
|
+ // Destroy an instance of UploadiFive
|
|
|
831
|
+ destroy : function() {
|
|
|
832
|
+
|
|
|
833
|
+ this.each(function() {
|
|
|
834
|
+
|
|
|
835
|
+ var $this = $(this),
|
|
|
836
|
+ $data = $this.data('uploadifive'),
|
|
|
837
|
+ settings = $data.settings;
|
|
|
838
|
+
|
|
|
839
|
+ // Clear the queue
|
|
|
840
|
+ methods.clearQueue.call($this);
|
|
|
841
|
+ // Destroy the queue if it was created
|
|
|
842
|
+ if (!settings.queueID) $('#' + settings.queueID).remove();
|
|
|
843
|
+ // Remove extra inputs
|
|
|
844
|
+ $this.siblings('input').remove();
|
|
|
845
|
+ // Show the original file input
|
|
|
846
|
+ $this.show()
|
|
|
847
|
+ // Move the file input out of the button
|
|
|
848
|
+ .insertBefore($data.button);
|
|
|
849
|
+ // Delete the button
|
|
|
850
|
+ $data.button.remove();
|
|
|
851
|
+ // Trigger the destroy event
|
|
|
852
|
+ if (typeof settings.onDestroy === 'function') {
|
|
|
853
|
+ settings.onDestroy.call($this);
|
|
|
854
|
+ }
|
|
|
855
|
+
|
|
|
856
|
+ });
|
|
|
857
|
+
|
|
|
858
|
+ }
|
|
|
859
|
+
|
|
|
860
|
+ }
|
|
|
861
|
+
|
|
|
862
|
+ $.fn.upload = function(method) {
|
|
|
863
|
+
|
|
|
864
|
+ if (methods[method]) {
|
|
|
865
|
+ return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
|
|
|
866
|
+ } else if (typeof method === 'object' || !method) {
|
|
|
867
|
+ return methods.init.apply(this, arguments);
|
|
|
868
|
+ } else {
|
|
|
869
|
+ $.error('The method ' + method + ' does not exist in $.uploadify');
|
|
|
870
|
+ }
|
|
|
871
|
+
|
|
|
872
|
+ }
|
|
|
873
|
+
|
|
|
874
|
+})(jQuery); |