jquery.fileupload-rails 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,37 @@
1
1
  /*
2
- * jQuery File Upload Plugin 5.5.2
2
+ * jQuery File Upload Plugin 5.9
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2010, Sebastian Tschan
6
6
  * https://blueimp.net
7
7
  *
8
8
  * Licensed under the MIT license:
9
- * http://creativecommons.org/licenses/MIT/
9
+ * http://www.opensource.org/licenses/MIT
10
10
  */
11
11
 
12
12
  /*jslint nomen: true, unparam: true, regexp: true */
13
- /*global document, XMLHttpRequestUpload, Blob, File, FormData, location, jQuery */
13
+ /*global define, window, document, Blob, FormData, location */
14
14
 
15
- (function ($) {
15
+ (function (factory) {
16
16
  'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define([
20
+ 'jquery',
21
+ 'jquery.ui.widget'
22
+ ], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(window.jQuery);
26
+ }
27
+ }(function ($) {
28
+ 'use strict';
29
+
30
+ // The FileReader API is not actually used, but works as feature detection,
31
+ // as e.g. Safari supports XHR file uploads via the FormData API,
32
+ // but not non-multipart XHR file uploads:
33
+ $.support.xhrFileUpload = !!(window.XMLHttpRequestUpload && window.FileReader);
34
+ $.support.xhrFormDataFileUpload = !!window.FormData;
17
35
 
18
36
  // The fileupload widget listens for change events on file input fields defined
19
37
  // via fileInput setting and paste or drop events of the given dropZone.
@@ -62,6 +80,12 @@
62
80
  limitConcurrentUploads: undefined,
63
81
  // Set the following option to true to force iframe transport uploads:
64
82
  forceIframeTransport: false,
83
+ // Set the following option to the location of a redirect url on the
84
+ // origin server, for cross-domain iframe transport uploads:
85
+ redirect: undefined,
86
+ // The parameter name for the redirect url, sent as part of the form
87
+ // data and set to 'redirect' if this option is empty:
88
+ redirectParamName: undefined,
65
89
  // Set the following option to the location of a postMessage window,
66
90
  // to enable postMessage transport uploads:
67
91
  postMessage: undefined,
@@ -147,13 +171,18 @@
147
171
  },
148
172
 
149
173
  // A list of options that require a refresh after assigning a new value:
150
- _refreshOptionsList: ['namespace', 'dropZone', 'fileInput'],
174
+ _refreshOptionsList: [
175
+ 'namespace',
176
+ 'dropZone',
177
+ 'fileInput',
178
+ 'multipart',
179
+ 'forceIframeTransport'
180
+ ],
151
181
 
152
182
  _isXHRUpload: function (options) {
153
- var undef = 'undefined';
154
183
  return !options.forceIframeTransport &&
155
- typeof XMLHttpRequestUpload !== undef && typeof File !== undef &&
156
- (!options.multipart || typeof FormData !== undef);
184
+ ((!options.multipart && $.support.xhrFileUpload) ||
185
+ $.support.xhrFormDataFileUpload);
157
186
  },
158
187
 
159
188
  _getFormData: function (options) {
@@ -210,10 +239,15 @@
210
239
  xhr = options.xhr ? options.xhr() : $.ajaxSettings.xhr();
211
240
  // Accesss to the native XHR object is required to add event listeners
212
241
  // for the upload progress event:
213
- if (xhr.upload && xhr.upload.addEventListener) {
214
- xhr.upload.addEventListener('progress', function (e) {
242
+ if (xhr.upload) {
243
+ $(xhr.upload).bind('progress', function (e) {
244
+ var oe = e.originalEvent;
245
+ // Make sure the progress event properties get copied over:
246
+ e.lengthComputable = oe.lengthComputable;
247
+ e.loaded = oe.loaded;
248
+ e.total = oe.total;
215
249
  that._onProgress(e, options);
216
- }, false);
250
+ });
217
251
  options.xhr = function () {
218
252
  return xhr;
219
253
  };
@@ -222,8 +256,10 @@
222
256
 
223
257
  _initXHRData: function (options) {
224
258
  var formData,
225
- file = options.files[0];
226
- if (!options.multipart || options.blob) {
259
+ file = options.files[0],
260
+ // Ignore non-multipart setting if not supported:
261
+ multipart = options.multipart || !$.support.xhrFileUpload;
262
+ if (!multipart || options.blob) {
227
263
  // For non-multipart uploads and chunked uploads,
228
264
  // file meta data is not part of the request body,
229
265
  // so we transmit this data as part of the HTTP headers.
@@ -239,13 +275,13 @@
239
275
  // Non-chunked non-multipart upload:
240
276
  options.contentType = file.type;
241
277
  options.data = file;
242
- } else if (!options.multipart) {
278
+ } else if (!multipart) {
243
279
  // Chunked non-multipart upload:
244
280
  options.contentType = 'application/octet-stream';
245
281
  options.data = options.blob;
246
282
  }
247
283
  }
248
- if (options.multipart && typeof FormData !== 'undefined') {
284
+ if (multipart && $.support.xhrFormDataFileUpload) {
249
285
  if (options.postMessage) {
250
286
  // window.postMessage does not allow sending FormData
251
287
  // objects, so we just add the File/Blob objects to
@@ -275,14 +311,14 @@
275
311
  });
276
312
  }
277
313
  if (options.blob) {
278
- formData.append(options.paramName, options.blob);
314
+ formData.append(options.paramName, options.blob, file.name);
279
315
  } else {
280
316
  $.each(options.files, function (index, file) {
281
317
  // File objects are also Blob instances.
282
318
  // This check allows the tests to run with
283
319
  // dummy objects:
284
320
  if (file instanceof Blob) {
285
- formData.append(options.paramName, file);
321
+ formData.append(options.paramName, file, file.name);
286
322
  }
287
323
  });
288
324
  }
@@ -298,6 +334,14 @@
298
334
  options.dataType = 'iframe ' + (options.dataType || '');
299
335
  // The iframe transport accepts a serialized array as form data:
300
336
  options.formData = this._getFormData(options);
337
+ // Add redirect url to form data on cross-domain uploads:
338
+ if (options.redirect && $('<a></a>').prop('href', options.url)
339
+ .prop('host') !== location.host) {
340
+ options.formData.push({
341
+ name: options.redirectParamName || 'redirect',
342
+ value: options.redirect
343
+ });
344
+ }
301
345
  },
302
346
 
303
347
  _initDataSettings: function (options) {
@@ -716,17 +760,19 @@
716
760
  },
717
761
 
718
762
  _initEventHandlers: function () {
719
- var ns = this.options.namespace || this.widgetName;
720
- this.options.dropZone
721
- .bind('dragover.' + ns, {fileupload: this}, this._onDragOver)
722
- .bind('drop.' + ns, {fileupload: this}, this._onDrop)
723
- .bind('paste.' + ns, {fileupload: this}, this._onPaste);
763
+ var ns = this.options.namespace;
764
+ if (this._isXHRUpload(this.options)) {
765
+ this.options.dropZone
766
+ .bind('dragover.' + ns, {fileupload: this}, this._onDragOver)
767
+ .bind('drop.' + ns, {fileupload: this}, this._onDrop)
768
+ .bind('paste.' + ns, {fileupload: this}, this._onPaste);
769
+ }
724
770
  this.options.fileInput
725
771
  .bind('change.' + ns, {fileupload: this}, this._onChange);
726
772
  },
727
773
 
728
774
  _destroyEventHandlers: function () {
729
- var ns = this.options.namespace || this.widgetName;
775
+ var ns = this.options.namespace;
730
776
  this.options.dropZone
731
777
  .unbind('dragover.' + ns, this._onDragOver)
732
778
  .unbind('drop.' + ns, this._onDrop)
@@ -735,43 +781,38 @@
735
781
  .unbind('change.' + ns, this._onChange);
736
782
  },
737
783
 
738
- _beforeSetOption: function (key, value) {
739
- this._destroyEventHandlers();
740
- },
741
-
742
- _afterSetOption: function (key, value) {
743
- var options = this.options;
744
- if (!options.fileInput) {
745
- options.fileInput = $();
746
- }
747
- if (!options.dropZone) {
748
- options.dropZone = $();
749
- }
750
- this._initEventHandlers();
751
- },
752
-
753
784
  _setOption: function (key, value) {
754
785
  var refresh = $.inArray(key, this._refreshOptionsList) !== -1;
755
786
  if (refresh) {
756
- this._beforeSetOption(key, value);
787
+ this._destroyEventHandlers();
757
788
  }
758
789
  $.Widget.prototype._setOption.call(this, key, value);
759
790
  if (refresh) {
760
- this._afterSetOption(key, value);
791
+ this._initSpecialOptions();
792
+ this._initEventHandlers();
761
793
  }
762
794
  },
763
795
 
764
- _create: function () {
796
+ _initSpecialOptions: function () {
765
797
  var options = this.options;
766
798
  if (options.fileInput === undefined) {
767
799
  options.fileInput = this.element.is('input:file') ?
768
800
  this.element : this.element.find('input:file');
769
- } else if (!options.fileInput) {
770
- options.fileInput = $();
801
+ } else if (!(options.fileInput instanceof $)) {
802
+ options.fileInput = $(options.fileInput);
771
803
  }
772
- if (!options.dropZone) {
773
- options.dropZone = $();
804
+ if (!(options.dropZone instanceof $)) {
805
+ options.dropZone = $(options.dropZone);
774
806
  }
807
+ },
808
+
809
+ _create: function () {
810
+ var options = this.options,
811
+ dataOpts = $.extend({}, this.element.data());
812
+ dataOpts[this.widgetName] = undefined;
813
+ $.extend(options, dataOpts);
814
+ options.namespace = options.namespace || this.widgetName;
815
+ this._initSpecialOptions();
775
816
  this._slots = [];
776
817
  this._sequence = this._getXHRPromise(true);
777
818
  this._sending = this._active = this._loaded = this._total = 0;
@@ -822,4 +863,4 @@
822
863
 
823
864
  });
824
865
 
825
- }(jQuery));
866
+ }));
@@ -1,18 +1,27 @@
1
1
  /*
2
- * jQuery Iframe Transport Plugin 1.2.5
2
+ * jQuery Iframe Transport Plugin 1.3
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
6
6
  * https://blueimp.net
7
7
  *
8
8
  * Licensed under the MIT license:
9
- * http://creativecommons.org/licenses/MIT/
9
+ * http://www.opensource.org/licenses/MIT
10
10
  */
11
11
 
12
12
  /*jslint unparam: true, nomen: true */
13
- /*global jQuery, document */
13
+ /*global define, window, document */
14
14
 
15
- (function ($) {
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define(['jquery'], factory);
20
+ } else {
21
+ // Browser globals:
22
+ factory(window.jQuery);
23
+ }
24
+ }(function ($) {
16
25
  'use strict';
17
26
 
18
27
  // Helper variable to create unique names for the transport iframes:
@@ -153,4 +162,4 @@
153
162
  }
154
163
  });
155
164
 
156
- }(jQuery));
165
+ }));
@@ -1,18 +1,27 @@
1
1
  /*
2
- * jQuery postMessage Transport Plugin 1.0
2
+ * jQuery postMessage Transport Plugin 1.1
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
6
6
  * https://blueimp.net
7
7
  *
8
8
  * Licensed under the MIT license:
9
- * http://creativecommons.org/licenses/MIT/
9
+ * http://www.opensource.org/licenses/MIT
10
10
  */
11
11
 
12
12
  /*jslint unparam: true, nomen: true */
13
- /*global jQuery, window, document */
13
+ /*global define, window, document */
14
14
 
15
- (function ($) {
15
+ (function (factory) {
16
+ 'use strict';
17
+ if (typeof define === 'function' && define.amd) {
18
+ // Register as an anonymous AMD module:
19
+ define(['jquery'], factory);
20
+ } else {
21
+ // Browser globals:
22
+ factory(window.jQuery);
23
+ }
24
+ }(function ($) {
16
25
  'use strict';
17
26
 
18
27
  var counter = 0,
@@ -105,4 +114,4 @@
105
114
  }
106
115
  });
107
116
 
108
- }(jQuery));
117
+ }));
@@ -1,24 +1,33 @@
1
1
  /*
2
- * jQuery XDomainRequest Transport Plugin 1.0.1
2
+ * jQuery XDomainRequest Transport Plugin 1.1.2
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
6
6
  * https://blueimp.net
7
7
  *
8
8
  * Licensed under the MIT license:
9
- * http://creativecommons.org/licenses/MIT/
9
+ * http://www.opensource.org/licenses/MIT
10
10
  *
11
11
  * Based on Julian Aubourg's ajaxHooks xdr.js:
12
12
  * https://github.com/jaubourg/ajaxHooks/
13
13
  */
14
14
 
15
15
  /*jslint unparam: true */
16
- /*global jQuery, window, XDomainRequest */
16
+ /*global define, window, XDomainRequest */
17
17
 
18
- (function ($) {
18
+ (function (factory) {
19
19
  'use strict';
20
- if (window.XDomainRequest) {
21
- jQuery.ajaxTransport(function (s) {
20
+ if (typeof define === 'function' && define.amd) {
21
+ // Register as an anonymous AMD module:
22
+ define(['jquery'], factory);
23
+ } else {
24
+ // Browser globals:
25
+ factory(window.jQuery);
26
+ }
27
+ }(function ($) {
28
+ 'use strict';
29
+ if (window.XDomainRequest && !$.support.cors) {
30
+ $.ajaxTransport(function (s) {
22
31
  if (s.crossDomain && s.async) {
23
32
  if (s.timeout) {
24
33
  s.xdrTimeout = s.timeout;
@@ -28,7 +37,7 @@
28
37
  return {
29
38
  send: function (headers, completeCallback) {
30
39
  function callback(status, statusText, responses, responseHeaders) {
31
- xdr.onload = xdr.onerror = xdr.ontimeout = jQuery.noop;
40
+ xdr.onload = xdr.onerror = xdr.ontimeout = $.noop;
32
41
  xdr = null;
33
42
  completeCallback(status, statusText, responses, responseHeaders);
34
43
  }
@@ -65,7 +74,7 @@
65
74
  },
66
75
  abort: function () {
67
76
  if (xdr) {
68
- xdr.onerror = jQuery.noop();
77
+ xdr.onerror = $.noop();
69
78
  xdr.abort();
70
79
  }
71
80
  }
@@ -73,4 +82,4 @@
73
82
  }
74
83
  });
75
84
  }
76
- }(jQuery));
85
+ }));
@@ -1,16 +1,22 @@
1
1
  @charset 'UTF-8';
2
2
  /*
3
- * jQuery File Upload UI Plugin CSS 5.0.6
3
+ * jQuery File Upload UI Plugin CSS 6.3
4
4
  * https://github.com/blueimp/jQuery-File-Upload
5
5
  *
6
6
  * Copyright 2010, Sebastian Tschan
7
7
  * https://blueimp.net
8
8
  *
9
9
  * Licensed under the MIT license:
10
- * http://creativecommons.org/licenses/MIT/
10
+ * http://www.opensource.org/licenses/MIT
11
11
  */
12
12
 
13
- .fileupload-buttonbar .ui-button input {
13
+ .fileinput-button {
14
+ position: relative;
15
+ overflow: hidden;
16
+ float: left;
17
+ margin-right: 4px;
18
+ }
19
+ .fileinput-button input {
14
20
  position: absolute;
15
21
  top: 0;
16
22
  right: 0;
@@ -19,82 +25,60 @@
19
25
  border-width: 0 0 100px 200px;
20
26
  opacity: 0;
21
27
  filter: alpha(opacity=0);
22
- -o-transform: translate(250px, -50px) scale(1);
23
28
  -moz-transform: translate(-300px, 0) scale(4);
24
29
  direction: ltr;
25
30
  cursor: pointer;
26
31
  }
27
-
28
- .fileinput-button {
29
- overflow: hidden;
30
- }
31
-
32
- /* Fix for IE 6: */
33
- *html .fileinput-button {
34
- padding: 2px 0;
35
- }
36
-
37
- /* Fix for IE 7: */
38
- *+html .fileinput-button {
39
- padding: 2px 0;
40
- }
41
-
42
- .fileupload-buttonbar {
43
- padding: 0.2em 0.4em;
44
- }
45
-
46
- .fileupload-buttonbar .ui-button {
47
- vertical-align: middle;
48
- }
49
-
50
- .fileupload-content {
51
- padding: 0.2em 0.4em;
52
- border-top-width: 0;
32
+ .fileupload-buttonbar .btn,
33
+ .fileupload-buttonbar .toggle {
34
+ margin-bottom: 5px;
53
35
  }
54
-
55
- .fileupload-content .ui-progressbar {
36
+ .files .progress {
56
37
  width: 200px;
57
- height: 20px;
58
- }
59
-
60
- .fileupload-content .ui-progressbar-value {
61
- background: url(pbar-ani.gif);
62
- }
63
-
64
- .fileupload-content .fileupload-progressbar {
65
- width: 400px;
66
- margin: 10px 0;
67
- }
68
-
69
- .files {
70
- margin: 10px 0;
71
- border-collapse: collapse;
72
38
  }
73
-
74
- .files td {
75
- padding: 5px;
76
- border-spacing: 5px;
39
+ .progress-animated .bar {
40
+ background: url(../img/progressbar.gif) !important;
41
+ filter: none;
77
42
  }
78
-
79
- .files img {
80
- border: none;
43
+ .fileupload-loading {
44
+ position: absolute;
45
+ left: 50%;
46
+ width: 128px;
47
+ height: 128px;
48
+ background: url(../img/loading.gif) center no-repeat;
49
+ display: none;
81
50
  }
82
-
83
- .files .name {
84
- padding: 0 10px;
51
+ .fileupload-processing .fileupload-loading {
52
+ display: block;
85
53
  }
86
54
 
87
- .files .size {
88
- padding: 0 10px 0 0;
89
- text-align: right;
90
- white-space: nowrap;
55
+ /* Fix for IE 6: */
56
+ *html .fileinput-button {
57
+ line-height: 22px;
58
+ margin: 1px -3px 0 0;
91
59
  }
92
60
 
93
- .ui-state-disabled .ui-state-disabled {
94
- opacity: 1;
95
- filter: alpha(opacity=100);
61
+ /* Fix for IE 7: */
62
+ *+html .fileinput-button {
63
+ margin: 1px 0 0 0;
64
+ }
65
+
66
+ @media (max-width: 480px) {
67
+ .files .btn span {
68
+ display: none;
69
+ }
70
+ .files .preview * {
71
+ width: 40px;
72
+ }
73
+ .files .name * {
74
+ width: 80px;
75
+ display: inline-block;
76
+ word-wrap: break-word;
77
+ }
78
+ .files .progress {
79
+ width: 20px;
80
+ }
81
+ .files .delete {
82
+ width: 60px;
83
+ }
96
84
  }
97
-
98
- .ui-state-disabled input {
99
- cursor: default;
100
- }