avatars_for_rails 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. data/{lib/generators/avatars_for_rails/templates/public → app/assets}/images/Jcrop.gif +0 -0
  2. data/{lib/generators/avatars_for_rails/templates/public → app/assets}/images/cancel.png +0 -0
  3. data/avatars_for_rails.gemspec +1 -1
  4. data/vendor/assets/javascripts/jquery.fileupload-ui.js +333 -63
  5. data/vendor/assets/javascripts/jquery.fileupload.js +654 -173
  6. data/vendor/assets/stylesheets/jquery.fileupload-ui.css +91 -21
  7. metadata +27 -46
  8. data/lib/generators/avatars_for_rails/templates/public/images/pbar-ani.gif +0 -0
  9. data/lib/generators/avatars_for_rails/templates/public/images/rails.png +0 -0
  10. data/lib/generators/avatars_for_rails/templates/public/javascripts/application.js +0 -2
  11. data/lib/generators/avatars_for_rails/templates/public/javascripts/avatars.js +0 -8
  12. data/lib/generators/avatars_for_rails/templates/public/javascripts/controls.js +0 -965
  13. data/lib/generators/avatars_for_rails/templates/public/javascripts/dragdrop.js +0 -974
  14. data/lib/generators/avatars_for_rails/templates/public/javascripts/effects.js +0 -1123
  15. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery-ui.min.js +0 -401
  16. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.Jcrop.min.js +0 -163
  17. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.fileupload-ui.js +0 -529
  18. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.fileupload.js +0 -956
  19. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.form.js +0 -815
  20. data/lib/generators/avatars_for_rails/templates/public/javascripts/jquery.js +0 -7179
  21. data/lib/generators/avatars_for_rails/templates/public/javascripts/prototype.js +0 -6001
  22. data/lib/generators/avatars_for_rails/templates/public/javascripts/rails.js +0 -158
  23. data/lib/generators/avatars_for_rails/templates/public/stylesheets/.gitkeep +0 -0
  24. data/lib/generators/avatars_for_rails/templates/public/stylesheets/avatars.css +0 -115
  25. data/lib/generators/avatars_for_rails/templates/public/stylesheets/jquery.Jcrop.css +0 -35
  26. data/lib/generators/avatars_for_rails/templates/public/stylesheets/jquery.fileupload-ui.css +0 -140
@@ -1,956 +0,0 @@
1
- /*
2
- * jQuery File Upload Plugin 4.4.2
3
- * https://github.com/blueimp/jQuery-File-Upload
4
- *
5
- * Copyright 2010, Sebastian Tschan
6
- * https://blueimp.net
7
- *
8
- * Licensed under the MIT license:
9
- * http://creativecommons.org/licenses/MIT/
10
- */
11
-
12
- /*jslint browser: true */
13
- /*global XMLHttpRequestUpload, File, FileReader, FormData, ProgressEvent, unescape, jQuery, upload */
14
-
15
- (function ($) {
16
- 'use strict';
17
-
18
- var defaultNamespace = 'file_upload',
19
- undef = 'undefined',
20
- func = 'function',
21
- FileUpload,
22
- methods,
23
-
24
- MultiLoader = function (callBack, numOrList) {
25
- var loaded = 0,
26
- list = [];
27
- if (numOrList) {
28
- if (numOrList.length) {
29
- list = numOrList;
30
- } else {
31
- list[numOrList - 1] = null;
32
- }
33
- }
34
- this.complete = function () {
35
- loaded += 1;
36
- if (loaded === list.length) {
37
- callBack(list);
38
- loaded = 0;
39
- list = [];
40
- }
41
- };
42
- this.push = function (item) {
43
- list.push(item);
44
- };
45
- this.getList = function () {
46
- return list;
47
- };
48
- },
49
-
50
- SequenceHandler = function () {
51
- var sequence = [];
52
- this.push = function (callBack) {
53
- sequence.push(callBack);
54
- if (sequence.length === 1) {
55
- callBack();
56
- }
57
- };
58
- this.next = function () {
59
- sequence.shift();
60
- if (sequence.length) {
61
- sequence[0]();
62
- }
63
- };
64
- };
65
-
66
- FileUpload = function (container) {
67
- var fileUpload = this,
68
- uploadForm,
69
- fileInput,
70
- settings = {
71
- namespace: defaultNamespace,
72
- uploadFormFilter: function (index) {
73
- return true;
74
- },
75
- fileInputFilter: function (index) {
76
- return true;
77
- },
78
- cssClass: defaultNamespace,
79
- dragDropSupport: true,
80
- dropZone: container,
81
- url: function (form) {
82
- return form.attr('action');
83
- },
84
- method: function (form) {
85
- return form.attr('method');
86
- },
87
- fieldName: function (input) {
88
- return input.attr('name');
89
- },
90
- formData: function (form) {
91
- return form.serializeArray();
92
- },
93
- requestHeaders: null,
94
- multipart: true,
95
- multiFileRequest: false,
96
- withCredentials: false,
97
- forceIframeUpload: false,
98
- sequentialUploads: false,
99
- maxChunkSize: null,
100
- maxFileReaderSize: 50000000
101
- },
102
- documentListeners = {},
103
- dropZoneListeners = {},
104
- protocolRegExp = /^http(s)?:\/\//,
105
- optionsReference,
106
- multiLoader = new MultiLoader(function (list) {
107
- if (typeof settings.onLoadAll === func) {
108
- settings.onLoadAll(list);
109
- }
110
- }),
111
- sequenceHandler = new SequenceHandler(),
112
-
113
- completeNext = function () {
114
- multiLoader.complete();
115
- sequenceHandler.next();
116
- },
117
-
118
- isXHRUploadCapable = function () {
119
- return typeof XMLHttpRequest !== undef && typeof XMLHttpRequestUpload !== undef &&
120
- typeof File !== undef && (!settings.multipart || typeof FormData !== undef ||
121
- (typeof FileReader !== undef && typeof XMLHttpRequest.prototype.sendAsBinary === func));
122
- },
123
-
124
- initEventHandlers = function () {
125
- if (settings.dragDropSupport) {
126
- if (typeof settings.onDocumentDragEnter === func) {
127
- documentListeners['dragenter.' + settings.namespace] = function (e) {
128
- settings.onDocumentDragEnter(e);
129
- };
130
- }
131
- if (typeof settings.onDocumentDragLeave === func) {
132
- documentListeners['dragleave.' + settings.namespace] = function (e) {
133
- settings.onDocumentDragLeave(e);
134
- };
135
- }
136
- documentListeners['dragover.' + settings.namespace] = fileUpload.onDocumentDragOver;
137
- documentListeners['drop.' + settings.namespace] = fileUpload.onDocumentDrop;
138
- $(document).bind(documentListeners);
139
- if (typeof settings.onDragEnter === func) {
140
- dropZoneListeners['dragenter.' + settings.namespace] = function (e) {
141
- settings.onDragEnter(e);
142
- };
143
- }
144
- if (typeof settings.onDragLeave === func) {
145
- dropZoneListeners['dragleave.' + settings.namespace] = function (e) {
146
- settings.onDragLeave(e);
147
- };
148
- }
149
- dropZoneListeners['dragover.' + settings.namespace] = fileUpload.onDragOver;
150
- dropZoneListeners['drop.' + settings.namespace] = fileUpload.onDrop;
151
- settings.dropZone.bind(dropZoneListeners);
152
- }
153
- fileInput.bind('change.' + settings.namespace, fileUpload.onChange);
154
- },
155
-
156
- removeEventHandlers = function () {
157
- $.each(documentListeners, function (key, value) {
158
- $(document).unbind(key, value);
159
- });
160
- $.each(dropZoneListeners, function (key, value) {
161
- settings.dropZone.unbind(key, value);
162
- });
163
- fileInput.unbind('change.' + settings.namespace);
164
- },
165
-
166
- isChunkedUpload = function (settings) {
167
- return typeof settings.uploadedBytes !== undef;
168
- },
169
-
170
- createProgressEvent = function (lengthComputable, loaded, total) {
171
- var event;
172
- if (typeof document.createEvent === func && typeof ProgressEvent !== undef) {
173
- event = document.createEvent('ProgressEvent');
174
- event.initProgressEvent(
175
- 'progress',
176
- false,
177
- false,
178
- lengthComputable,
179
- loaded,
180
- total
181
- );
182
- } else {
183
- event = {
184
- lengthComputable: true,
185
- loaded: loaded,
186
- total: total
187
- };
188
- }
189
- return event;
190
- },
191
-
192
- getProgressTotal = function (files, index, settings) {
193
- var i,
194
- total;
195
- if (typeof settings.progressTotal === undef) {
196
- if (files[index]) {
197
- total = files[index].size;
198
- settings.progressTotal = total ? total : 1;
199
- } else {
200
- total = 0;
201
- for (i = 0; i < files.length; i += 1) {
202
- total += files[i].size;
203
- }
204
- settings.progressTotal = total;
205
- }
206
- }
207
- return settings.progressTotal;
208
- },
209
-
210
- handleGlobalProgress = function (event, files, index, xhr, settings) {
211
- var progressEvent,
212
- loaderList,
213
- globalLoaded = 0,
214
- globalTotal = 0;
215
- if (event.lengthComputable && typeof settings.onProgressAll === func) {
216
- settings.progressLoaded = parseInt(
217
- event.loaded / event.total * getProgressTotal(files, index, settings),
218
- 10
219
- );
220
- loaderList = multiLoader.getList();
221
- $.each(loaderList, function (index, item) {
222
- // item is an array with [files, index, xhr, settings]
223
- globalLoaded += item[3].progressLoaded || 0;
224
- globalTotal += getProgressTotal(item[0], item[1], item[3]);
225
- });
226
- progressEvent = createProgressEvent(
227
- true,
228
- globalLoaded,
229
- globalTotal
230
- );
231
- settings.onProgressAll(progressEvent, loaderList);
232
- }
233
- },
234
-
235
- handleLoadEvent = function (event, files, index, xhr, settings) {
236
- var progressEvent;
237
- if (isChunkedUpload(settings)) {
238
- settings.uploadedBytes += settings.chunkSize;
239
- progressEvent = createProgressEvent(
240
- true,
241
- settings.uploadedBytes,
242
- files[index].size
243
- );
244
- if (typeof settings.onProgress === func) {
245
- settings.onProgress(progressEvent, files, index, xhr, settings);
246
- }
247
- handleGlobalProgress(progressEvent, files, index, xhr, settings);
248
- if (settings.uploadedBytes < files[index].size) {
249
- if (typeof settings.resumeUpload === func) {
250
- settings.resumeUpload(
251
- event,
252
- files,
253
- index,
254
- xhr,
255
- settings,
256
- function () {
257
- upload(event, files, index, xhr, settings, true);
258
- }
259
- );
260
- } else {
261
- upload(event, files, index, xhr, settings, true);
262
- }
263
- return;
264
- }
265
- }
266
- settings.progressLoaded = getProgressTotal(files, index, settings);
267
- if (typeof settings.onLoad === func) {
268
- settings.onLoad(event, files, index, xhr, settings);
269
- }
270
- completeNext();
271
- },
272
-
273
- handleProgressEvent = function (event, files, index, xhr, settings) {
274
- var progressEvent = event;
275
- if (isChunkedUpload(settings) && event.lengthComputable) {
276
- progressEvent = createProgressEvent(
277
- true,
278
- settings.uploadedBytes + parseInt(event.loaded / event.total * settings.chunkSize, 10),
279
- files[index].size
280
- );
281
- }
282
- if (typeof settings.onProgress === func) {
283
- settings.onProgress(progressEvent, files, index, xhr, settings);
284
- }
285
- handleGlobalProgress(progressEvent, files, index, xhr, settings);
286
- },
287
-
288
- initUploadEventHandlers = function (files, index, xhr, settings) {
289
- if (xhr.upload) {
290
- xhr.upload.onprogress = function (e) {
291
- handleProgressEvent(e, files, index, xhr, settings);
292
- };
293
- }
294
- xhr.onload = function (e) {
295
- handleLoadEvent(e, files, index, xhr, settings);
296
- };
297
- xhr.onabort = function (e) {
298
- settings.progressTotal = settings.progressLoaded;
299
- if (typeof settings.onAbort === func) {
300
- settings.onAbort(e, files, index, xhr, settings);
301
- }
302
- completeNext();
303
- };
304
- xhr.onerror = function (e) {
305
- settings.progressTotal = settings.progressLoaded;
306
- if (typeof settings.onError === func) {
307
- settings.onError(e, files, index, xhr, settings);
308
- }
309
- completeNext();
310
- };
311
- },
312
-
313
- getUrl = function (settings) {
314
- if (typeof settings.url === func) {
315
- return settings.url(settings.uploadForm || uploadForm);
316
- }
317
- return settings.url;
318
- },
319
-
320
- getMethod = function (settings) {
321
- if (typeof settings.method === func) {
322
- return settings.method(settings.uploadForm || uploadForm);
323
- }
324
- return settings.method;
325
- },
326
-
327
- getFieldName = function (settings) {
328
- if (typeof settings.fieldName === func) {
329
- return settings.fieldName(settings.fileInput || fileInput);
330
- }
331
- return settings.fieldName;
332
- },
333
-
334
- getFormData = function (settings) {
335
- var formData;
336
- if (typeof settings.formData === func) {
337
- return settings.formData(settings.uploadForm || uploadForm);
338
- } else if ($.isArray(settings.formData)) {
339
- return settings.formData;
340
- } else if (settings.formData) {
341
- formData = [];
342
- $.each(settings.formData, function (name, value) {
343
- formData.push({name: name, value: value});
344
- });
345
- return formData;
346
- }
347
- return [];
348
- },
349
-
350
- isSameDomain = function (url) {
351
- if (protocolRegExp.test(url)) {
352
- var host = location.host,
353
- indexStart = location.protocol.length + 2,
354
- index = url.indexOf(host, indexStart),
355
- pathIndex = index + host.length;
356
- if ((index === indexStart || index === url.indexOf('@', indexStart) + 1) &&
357
- (url.length === pathIndex || $.inArray(url.charAt(pathIndex), ['/', '?', '#']) !== -1)) {
358
- return true;
359
- }
360
- return false;
361
- }
362
- return true;
363
- },
364
-
365
- initUploadRequest = function (files, index, xhr, settings) {
366
- var file = files[index],
367
- url = getUrl(settings),
368
- sameDomain = isSameDomain(url);
369
- xhr.open(getMethod(settings), url, true);
370
- if (sameDomain) {
371
- xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
372
- if (!settings.multipart || isChunkedUpload(settings)) {
373
- xhr.setRequestHeader('X-File-Name', file.name);
374
- xhr.setRequestHeader('X-File-Type', file.type);
375
- xhr.setRequestHeader('X-File-Size', file.size);
376
- if (!isChunkedUpload(settings)) {
377
- xhr.setRequestHeader('Content-Type', file.type);
378
- } else if (!settings.multipart) {
379
- xhr.setRequestHeader('Content-Type', 'application/octet-stream');
380
- }
381
- }
382
- } else if (settings.withCredentials) {
383
- xhr.withCredentials = true;
384
- }
385
- if ($.isArray(settings.requestHeaders)) {
386
- $.each(settings.requestHeaders, function (index, header) {
387
- xhr.setRequestHeader(header.name, header.value);
388
- });
389
- } else if (settings.requestHeaders) {
390
- $.each(settings.requestHeaders, function (name, value) {
391
- xhr.setRequestHeader(name, value);
392
- });
393
- }
394
- },
395
-
396
- formDataUpload = function (files, xhr, settings) {
397
- var formData = new FormData(),
398
- i;
399
- $.each(getFormData(settings), function (index, field) {
400
- formData.append(field.name, field.value);
401
- });
402
- for (i = 0; i < files.length; i += 1) {
403
- formData.append(getFieldName(settings), files[i]);
404
- }
405
- xhr.send(formData);
406
- },
407
-
408
- loadFileContent = function (file, callBack) {
409
- file.reader = new FileReader();
410
- file.reader.onload = callBack;
411
- file.reader.readAsBinaryString(file);
412
- },
413
-
414
- utf8encode = function (str) {
415
- return unescape(encodeURIComponent(str));
416
- },
417
-
418
- buildMultiPartFormData = function (boundary, files, filesFieldName, fields) {
419
- var doubleDash = '--',
420
- crlf = '\r\n',
421
- formData = '',
422
- buffer = [];
423
- $.each(fields, function (index, field) {
424
- formData += doubleDash + boundary + crlf +
425
- 'Content-Disposition: form-data; name="' +
426
- utf8encode(field.name) +
427
- '"' + crlf + crlf +
428
- utf8encode(field.value) + crlf;
429
- });
430
- $.each(files, function (index, file) {
431
- formData += doubleDash + boundary + crlf +
432
- 'Content-Disposition: form-data; name="' +
433
- utf8encode(filesFieldName) +
434
- '"; filename="' + utf8encode(file.name) + '"' + crlf +
435
- 'Content-Type: ' + utf8encode(file.type) + crlf + crlf;
436
- buffer.push(formData);
437
- buffer.push(file.reader.result);
438
- delete file.reader;
439
- formData = crlf;
440
- });
441
- formData += doubleDash + boundary + doubleDash + crlf;
442
- buffer.push(formData);
443
- return buffer.join('');
444
- },
445
-
446
- fileReaderUpload = function (files, xhr, settings) {
447
- var boundary = '----MultiPartFormBoundary' + (new Date()).getTime(),
448
- loader,
449
- i;
450
- xhr.setRequestHeader('Content-Type', 'multipart/form-data; boundary=' + boundary);
451
- loader = new MultiLoader(function () {
452
- xhr.sendAsBinary(buildMultiPartFormData(
453
- boundary,
454
- files,
455
- getFieldName(settings),
456
- getFormData(settings)
457
- ));
458
- }, files.length);
459
- for (i = 0; i < files.length; i += 1) {
460
- loadFileContent(files[i], loader.complete);
461
- }
462
- },
463
-
464
- getBlob = function (file, settings) {
465
- var blob,
466
- ub = settings.uploadedBytes,
467
- mcs = settings.maxChunkSize;
468
- if (file && typeof file.slice === func && (ub || (mcs && mcs < file.size))) {
469
- settings.uploadedBytes = ub = ub || 0;
470
- blob = file.slice(ub, mcs || file.size - ub);
471
- settings.chunkSize = blob.size;
472
- return blob;
473
- }
474
- return file;
475
- },
476
-
477
- upload = function (event, files, index, xhr, settings, nextChunk) {
478
- var send;
479
- send = function () {
480
- if (!nextChunk) {
481
- if (typeof settings.onSend === func &&
482
- settings.onSend(event, files, index, xhr, settings) === false) {
483
- completeNext();
484
- return;
485
- }
486
- }
487
- var blob = getBlob(files[index], settings),
488
- filesToUpload;
489
- initUploadEventHandlers(files, index, xhr, settings);
490
- initUploadRequest(files, index, xhr, settings);
491
- if (!settings.multipart) {
492
- if (xhr.upload) {
493
- xhr.send(blob);
494
- } else {
495
- $.error('Browser does not support XHR file uploads');
496
- }
497
- } else {
498
- filesToUpload = (typeof index === 'number') ? [blob] : files;
499
- if (typeof FormData !== undef) {
500
- formDataUpload(filesToUpload, xhr, settings);
501
- } else if (typeof FileReader !== undef && typeof xhr.sendAsBinary === func) {
502
- fileReaderUpload(filesToUpload, xhr, settings);
503
- } else {
504
- $.error('Browser does not support multipart/form-data XHR file uploads');
505
- }
506
- }
507
- };
508
- if (!nextChunk) {
509
- multiLoader.push(Array.prototype.slice.call(arguments, 1));
510
- if (settings.sequentialUploads) {
511
- sequenceHandler.push(send);
512
- return;
513
- }
514
- }
515
- send();
516
- },
517
-
518
- handleUpload = function (event, files, input, form, index) {
519
- var xhr = new XMLHttpRequest(),
520
- uploadSettings = $.extend({}, settings);
521
- uploadSettings.fileInput = input;
522
- uploadSettings.uploadForm = form;
523
- if (typeof uploadSettings.initUpload === func) {
524
- uploadSettings.initUpload(
525
- event,
526
- files,
527
- index,
528
- xhr,
529
- uploadSettings,
530
- function () {
531
- upload(event, files, index, xhr, uploadSettings);
532
- }
533
- );
534
- } else {
535
- upload(event, files, index, xhr, uploadSettings);
536
- }
537
- },
538
-
539
- handleLegacyGlobalProgress = function (event, files, index, iframe, settings) {
540
- var total = 0,
541
- progressEvent;
542
- if (typeof index === undef) {
543
- $.each(files, function (index, file) {
544
- total += file.size ? file.size : 1;
545
- });
546
- } else {
547
- total = files[index].size ? files[index].size : 1;
548
- }
549
- progressEvent = createProgressEvent(true, total, total);
550
- settings.progressLoaded = total;
551
- handleGlobalProgress(progressEvent, files, index, iframe, settings);
552
- },
553
-
554
- legacyUploadFormDataInit = function (input, form, settings) {
555
- var formData = getFormData(settings);
556
- form.find(':input').not(':disabled')
557
- .attr('disabled', true)
558
- .addClass(settings.namespace + '_disabled');
559
- $.each(formData, function (index, field) {
560
- $('<input type="hidden"/>')
561
- .attr('name', field.name)
562
- .val(field.value)
563
- .addClass(settings.namespace + '_form_data')
564
- .appendTo(form);
565
- });
566
- input
567
- .attr('name', getFieldName(settings))
568
- .appendTo(form);
569
- },
570
-
571
- legacyUploadFormDataReset = function (input, form, settings) {
572
- input.detach();
573
- form.find('.' + settings.namespace + '_disabled')
574
- .removeAttr('disabled')
575
- .removeClass(settings.namespace + '_disabled');
576
- form.find('.' + settings.namespace + '_form_data').remove();
577
- },
578
-
579
- legacyUpload = function (event, files, input, form, iframe, settings, index) {
580
- var send;
581
- send = function () {
582
- if (typeof settings.onSend === func && settings.onSend(event, files, index, iframe, settings) === false) {
583
- completeNext();
584
- return;
585
- }
586
- var originalAction = form.attr('action'),
587
- originalMethod = form.attr('method'),
588
- originalTarget = form.attr('target');
589
- iframe
590
- .unbind('abort')
591
- .bind('abort', function (e) {
592
- iframe.readyState = 0;
593
- // javascript:false as iframe src prevents warning popups on HTTPS in IE6
594
- // concat is used here to prevent the "Script URL" JSLint error:
595
- iframe.unbind('load').attr('src', 'javascript'.concat(':false;'));
596
- handleLegacyGlobalProgress(e, files, index, iframe, settings);
597
- if (typeof settings.onAbort === func) {
598
- settings.onAbort(e, files, index, iframe, settings);
599
- }
600
- completeNext();
601
- })
602
- .unbind('load')
603
- .bind('load', function (e) {
604
- iframe.readyState = 4;
605
- handleLegacyGlobalProgress(e, files, index, iframe, settings);
606
- if (typeof settings.onLoad === func) {
607
- settings.onLoad(e, files, index, iframe, settings);
608
- }
609
- // Fix for IE endless progress bar activity bug
610
- // (happens on form submits to iframe targets):
611
- $('<iframe src="javascript:false;" style="display:none;"></iframe>')
612
- .appendTo(form).remove();
613
- completeNext();
614
- });
615
- form
616
- .attr('action', getUrl(settings))
617
- .attr('method', getMethod(settings))
618
- .attr('target', iframe.attr('name'));
619
- legacyUploadFormDataInit(input, form, settings);
620
- iframe.readyState = 2;
621
- form.get(0).submit();
622
- legacyUploadFormDataReset(input, form, settings);
623
- form
624
- .attr('action', originalAction)
625
- .attr('method', originalMethod)
626
- .attr('target', originalTarget);
627
- };
628
- multiLoader.push([files, index, iframe, settings]);
629
- if (settings.sequentialUploads) {
630
- sequenceHandler.push(send);
631
- } else {
632
- send();
633
- }
634
- },
635
-
636
- handleLegacyUpload = function (event, input, form, index) {
637
- if (!(event && input && form)) {
638
- $.error('Iframe based File Upload requires a file input change event');
639
- return;
640
- }
641
- // javascript:false as iframe src prevents warning popups on HTTPS in IE6:
642
- var iframe = $('<iframe src="javascript:false;" style="display:none;" name="iframe_' +
643
- settings.namespace + '_' + (new Date()).getTime() + '"></iframe>'),
644
- uploadSettings = $.extend({}, settings),
645
- files = event.target && event.target.files;
646
- files = files ? Array.prototype.slice.call(files, 0) : [{name: input.val(), type: null, size: null}];
647
- index = files.length === 1 ? 0 : index;
648
- uploadSettings.fileInput = input;
649
- uploadSettings.uploadForm = form;
650
- iframe.readyState = 0;
651
- iframe.abort = function () {
652
- iframe.trigger('abort');
653
- };
654
- iframe.bind('load', function () {
655
- iframe.unbind('load');
656
- if (typeof uploadSettings.initUpload === func) {
657
- uploadSettings.initUpload(
658
- event,
659
- files,
660
- index,
661
- iframe,
662
- uploadSettings,
663
- function () {
664
- legacyUpload(event, files, input, form, iframe, uploadSettings, index);
665
- }
666
- );
667
- } else {
668
- legacyUpload(event, files, input, form, iframe, uploadSettings, index);
669
- }
670
- }).appendTo(form);
671
- },
672
-
673
- canHandleXHRUploadSize = function (files) {
674
- var bytes = 0,
675
- totalBytes = 0,
676
- i;
677
- if (settings.multipart && typeof FormData === undef) {
678
- for (i = 0; i < files.length; i += 1) {
679
- bytes = files[i].size;
680
- if (bytes > settings.maxFileReaderSize) {
681
- return false;
682
- }
683
- totalBytes += bytes;
684
- }
685
- if (settings.multiFileRequest && totalBytes > settings.maxFileReaderSize) {
686
- return false;
687
- }
688
- }
689
- return true;
690
- },
691
-
692
- handleFiles = function (event, files, input, form) {
693
- if (!canHandleXHRUploadSize(files)) {
694
- handleLegacyUpload(event, input, form);
695
- return;
696
- }
697
- var i;
698
- files = Array.prototype.slice.call(files, 0);
699
- if (settings.multiFileRequest && settings.multipart && files.length) {
700
- handleUpload(event, files, input, form);
701
- } else {
702
- for (i = 0; i < files.length; i += 1) {
703
- handleUpload(event, files, input, form, i);
704
- }
705
- }
706
- },
707
-
708
- initUploadForm = function () {
709
- uploadForm = (container.is('form') ? container : container.find('form'))
710
- .filter(settings.uploadFormFilter);
711
- },
712
-
713
- initFileInput = function () {
714
- fileInput = (uploadForm.length ? uploadForm : container).find('input:file')
715
- .filter(settings.fileInputFilter);
716
- },
717
-
718
- replaceFileInput = function (input) {
719
- var inputClone = input.clone(true);
720
- $('<form/>').append(inputClone).get(0).reset();
721
- input.after(inputClone).detach();
722
- initFileInput();
723
- };
724
-
725
- this.onDocumentDragOver = function (e) {
726
- if (typeof settings.onDocumentDragOver === func &&
727
- settings.onDocumentDragOver(e) === false) {
728
- return false;
729
- }
730
- e.preventDefault();
731
- };
732
-
733
- this.onDocumentDrop = function (e) {
734
- if (typeof settings.onDocumentDrop === func &&
735
- settings.onDocumentDrop(e) === false) {
736
- return false;
737
- }
738
- e.preventDefault();
739
- };
740
-
741
- this.onDragOver = function (e) {
742
- if (typeof settings.onDragOver === func &&
743
- settings.onDragOver(e) === false) {
744
- return false;
745
- }
746
- var dataTransfer = e.originalEvent.dataTransfer;
747
- if (dataTransfer && dataTransfer.files) {
748
- dataTransfer.dropEffect = dataTransfer.effectAllowed = 'copy';
749
- e.preventDefault();
750
- }
751
- };
752
-
753
- this.onDrop = function (e) {
754
- if (typeof settings.onDrop === func &&
755
- settings.onDrop(e) === false) {
756
- return false;
757
- }
758
- var dataTransfer = e.originalEvent.dataTransfer;
759
- if (dataTransfer && dataTransfer.files && isXHRUploadCapable()) {
760
- handleFiles(e, dataTransfer.files);
761
- }
762
- e.preventDefault();
763
- };
764
-
765
- this.onChange = function (e) {
766
- if (typeof settings.onChange === func &&
767
- settings.onChange(e) === false) {
768
- return false;
769
- }
770
- var input = $(e.target),
771
- form = $(e.target.form);
772
- if (form.length === 1) {
773
- input.data(defaultNamespace + '_form', form);
774
- replaceFileInput(input);
775
- } else {
776
- form = input.data(defaultNamespace + '_form');
777
- }
778
- if (!settings.forceIframeUpload && e.target.files && isXHRUploadCapable()) {
779
- handleFiles(e, e.target.files, input, form);
780
- } else {
781
- handleLegacyUpload(e, input, form);
782
- }
783
- };
784
-
785
- this.init = function (options) {
786
- if (options) {
787
- $.extend(settings, options);
788
- optionsReference = options;
789
- }
790
- initUploadForm();
791
- initFileInput();
792
- if (container.data(settings.namespace)) {
793
- $.error('FileUpload with namespace "' + settings.namespace + '" already assigned to this element');
794
- return;
795
- }
796
- container
797
- .data(settings.namespace, fileUpload)
798
- .addClass(settings.cssClass);
799
- settings.dropZone.not(container).addClass(settings.cssClass);
800
- initEventHandlers();
801
- if (typeof settings.init === func) {
802
- settings.init();
803
- }
804
- };
805
-
806
- this.options = function (options) {
807
- var oldCssClass,
808
- oldDropZone,
809
- uploadFormFilterUpdate,
810
- fileInputFilterUpdate;
811
- if (typeof options === undef) {
812
- return $.extend({}, settings);
813
- }
814
- if (optionsReference) {
815
- $.extend(optionsReference, options);
816
- }
817
- removeEventHandlers();
818
- $.each(options, function (name, value) {
819
- switch (name) {
820
- case 'namespace':
821
- $.error('The FileUpload namespace cannot be updated.');
822
- return;
823
- case 'uploadFormFilter':
824
- uploadFormFilterUpdate = true;
825
- fileInputFilterUpdate = true;
826
- break;
827
- case 'fileInputFilter':
828
- fileInputFilterUpdate = true;
829
- break;
830
- case 'cssClass':
831
- oldCssClass = settings.cssClass;
832
- break;
833
- case 'dropZone':
834
- oldDropZone = settings.dropZone;
835
- break;
836
- }
837
- settings[name] = value;
838
- });
839
- if (uploadFormFilterUpdate) {
840
- initUploadForm();
841
- }
842
- if (fileInputFilterUpdate) {
843
- initFileInput();
844
- }
845
- if (typeof oldCssClass !== undef) {
846
- container
847
- .removeClass(oldCssClass)
848
- .addClass(settings.cssClass);
849
- (oldDropZone ? oldDropZone : settings.dropZone).not(container)
850
- .removeClass(oldCssClass);
851
- settings.dropZone.not(container).addClass(settings.cssClass);
852
- } else if (oldDropZone) {
853
- oldDropZone.not(container).removeClass(settings.cssClass);
854
- settings.dropZone.not(container).addClass(settings.cssClass);
855
- }
856
- initEventHandlers();
857
- };
858
-
859
- this.option = function (name, value) {
860
- var options;
861
- if (typeof value === undef) {
862
- return settings[name];
863
- }
864
- options = {};
865
- options[name] = value;
866
- fileUpload.options(options);
867
- };
868
-
869
- this.destroy = function () {
870
- if (typeof settings.destroy === func) {
871
- settings.destroy();
872
- }
873
- removeEventHandlers();
874
- container
875
- .removeData(settings.namespace)
876
- .removeClass(settings.cssClass);
877
- settings.dropZone.not(container).removeClass(settings.cssClass);
878
- };
879
-
880
- this.upload = function (files) {
881
- if (typeof files.length === undef) {
882
- files = [files];
883
- }
884
- handleFiles(null, files);
885
- };
886
- };
887
-
888
- methods = {
889
- init : function (options) {
890
- return this.each(function () {
891
- (new FileUpload($(this))).init(options);
892
- });
893
- },
894
-
895
- option: function (option, value, namespace) {
896
- namespace = namespace ? namespace : defaultNamespace;
897
- var fileUpload = $(this).data(namespace);
898
- if (fileUpload) {
899
- if (!option) {
900
- return fileUpload.options();
901
- } else if (typeof option === 'string' && typeof value === undef) {
902
- return fileUpload.option(option);
903
- }
904
- } else {
905
- $.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
906
- }
907
- return this.each(function () {
908
- var fu = $(this).data(namespace);
909
- if (fu) {
910
- if (typeof option === 'string') {
911
- fu.option(option, value);
912
- } else {
913
- fu.options(option);
914
- }
915
- } else {
916
- $.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
917
- }
918
- });
919
- },
920
-
921
- destroy: function (namespace) {
922
- namespace = namespace ? namespace : defaultNamespace;
923
- return this.each(function () {
924
- var fileUpload = $(this).data(namespace);
925
- if (fileUpload) {
926
- fileUpload.destroy();
927
- } else {
928
- $.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
929
- }
930
- });
931
- },
932
-
933
- upload: function (files, namespace) {
934
- namespace = namespace ? namespace : defaultNamespace;
935
- return this.each(function () {
936
- var fileUpload = $(this).data(namespace);
937
- if (fileUpload) {
938
- fileUpload.upload(files);
939
- } else {
940
- $.error('No FileUpload with namespace "' + namespace + '" assigned to this element');
941
- }
942
- });
943
- }
944
- };
945
-
946
- $.fn.fileUpload = function (method) {
947
- if (methods[method]) {
948
- return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
949
- } else if (typeof method === 'object' || !method) {
950
- return methods.init.apply(this, arguments);
951
- } else {
952
- $.error('Method "' + method + '" does not exist on jQuery.fileUpload');
953
- }
954
- };
955
-
956
- }(jQuery));