s3_cors_fileupload 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -2
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +19 -19
  5. data/README.md +13 -1
  6. data/lib/generators/s3_cors_fileupload/install/templates/s3_uploads.js +1 -2
  7. data/lib/generators/s3_cors_fileupload/install/templates/source_file.rb +1 -1
  8. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_download.html.erb +19 -16
  9. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_upload.html.erb +31 -26
  10. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/_template_uploaded.html.erb +18 -13
  11. data/lib/generators/s3_cors_fileupload/install/templates/views/erb/index.html.erb +1 -1
  12. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_download.html.haml +16 -21
  13. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_upload.html.haml +15 -18
  14. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/_template_uploaded.html.haml +12 -13
  15. data/lib/generators/s3_cors_fileupload/install/templates/views/haml/index.html.haml +1 -1
  16. data/lib/s3_cors_fileupload/rails/form_helper.rb +16 -14
  17. data/lib/s3_cors_fileupload/version.rb +3 -3
  18. data/vendor/assets/javascripts/s3_cors_fileupload/index.js +4 -1
  19. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-image.js +213 -0
  20. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-process.js +164 -0
  21. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-ui.js +62 -228
  22. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload-validate.js +116 -0
  23. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.fileupload.js +212 -84
  24. data/vendor/assets/javascripts/s3_cors_fileupload/jquery.iframe-transport.js +24 -4
  25. data/vendor/assets/javascripts/s3_cors_fileupload/vendor/jquery.ui.widget.js +1 -1
  26. data/vendor/assets/javascripts/s3_cors_fileupload/vendor/load-image.js +138 -172
  27. data/vendor/assets/javascripts/s3_cors_fileupload/vendor/tmpl.js +3 -4
  28. data/vendor/assets/stylesheets/jquery.fileupload-ui.css.erb +12 -28
  29. metadata +5 -2
@@ -1,5 +1,5 @@
1
1
  /*
2
- * jQuery Iframe Transport Plugin 1.6.1
2
+ * jQuery Iframe Transport Plugin 1.7
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
@@ -61,9 +61,10 @@
61
61
  // IE versions below IE8 cannot set the name property of
62
62
  // elements that have already been added to the DOM,
63
63
  // so we set the name along with the iframe HTML markup:
64
+ counter += 1;
64
65
  iframe = $(
65
66
  '<iframe src="javascript:false;" name="iframe-transport-' +
66
- (counter += 1) + '"></iframe>'
67
+ counter + '"></iframe>'
67
68
  ).bind('load', function () {
68
69
  var fileInputClones,
69
70
  paramNames = $.isArray(options.paramName) ?
@@ -96,7 +97,12 @@
96
97
  // (happens on form submits to iframe targets):
97
98
  $('<iframe src="javascript:false;"></iframe>')
98
99
  .appendTo(form);
99
- form.remove();
100
+ window.setTimeout(function () {
101
+ // Removing the form in a setTimeout call
102
+ // allows Chrome's developer tools to display
103
+ // the response result
104
+ form.remove();
105
+ }, 0);
100
106
  });
101
107
  form
102
108
  .prop('target', iframe.prop('name'))
@@ -164,7 +170,15 @@
164
170
  });
165
171
 
166
172
  // The iframe transport returns the iframe content document as response.
167
- // The following adds converters from iframe to text, json, html, and script:
173
+ // The following adds converters from iframe to text, json, html, xml
174
+ // and script.
175
+ // Please note that the Content-Type for JSON responses has to be text/plain
176
+ // or text/html, if the browser doesn't include application/json in the
177
+ // Accept header, else IE will show a download dialog.
178
+ // The Content-Type for XML responses on the other hand has to be always
179
+ // application/xml or text/xml, so IE properly parses the XML response.
180
+ // See also
181
+ // https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
168
182
  $.ajaxSetup({
169
183
  converters: {
170
184
  'iframe text': function (iframe) {
@@ -176,6 +190,12 @@
176
190
  'iframe html': function (iframe) {
177
191
  return iframe && $(iframe[0].body).html();
178
192
  },
193
+ 'iframe xml': function (iframe) {
194
+ var xmlDoc = iframe && iframe[0];
195
+ return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
196
+ $.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
197
+ $(xmlDoc.body).html());
198
+ },
179
199
  'iframe script': function (iframe) {
180
200
  return iframe && $.globalEval($(iframe[0].body).text());
181
201
  }
@@ -1,5 +1,5 @@
1
1
  /*
2
- * jQuery UI Widget 1.10.1+amd
2
+ * jQuery UI Widget 1.10.3+amd
3
3
  * https://github.com/blueimp/jQuery-File-Upload
4
4
  *
5
5
  * Copyright 2013 jQuery Foundation and other contributors
@@ -1,19 +1,16 @@
1
1
  /*
2
- * JavaScript Load Image 1.5
2
+ * JavaScript Load Image 1.9.0
3
3
  * https://github.com/blueimp/JavaScript-Load-Image
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
6
6
  * https://blueimp.net
7
7
  *
8
- * iOS image scaling fixes based on
9
- * https://github.com/stomita/ios-imagefile-megapixel
10
- *
11
8
  * Licensed under the MIT license:
12
9
  * http://www.opensource.org/licenses/MIT
13
10
  */
14
11
 
15
- /*jslint nomen: true, bitwise: true */
16
- /*global window, document, URL, webkitURL, Blob, File, FileReader, define */
12
+ /*jslint nomen: true */
13
+ /*global define, window, document, URL, webkitURL, Blob, File, FileReader */
17
14
 
18
15
  (function ($) {
19
16
  'use strict';
@@ -75,54 +72,21 @@
75
72
  return Object.prototype.toString.call(obj) === '[object ' + type + ']';
76
73
  };
77
74
 
78
- // Detects subsampling in JPEG images:
79
- loadImage.detectSubsampling = function (img) {
80
- var canvas,
81
- context;
82
- if (img.width * img.height > 1024 * 1024) { // only consider mexapixel images
83
- canvas = document.createElement('canvas');
84
- canvas.width = canvas.height = 1;
85
- context = canvas.getContext('2d');
86
- context.drawImage(img, -img.width + 1, 0);
87
- // subsampled image becomes half smaller in rendering size.
88
- // check alpha channel value to confirm image is covering edge pixel or not.
89
- // if alpha value is 0 image is not covering, hence subsampled.
90
- return context.getImageData(0, 0, 1, 1).data[3] === 0;
91
- }
92
- return false;
75
+ // Transform image coordinates, allows to override e.g.
76
+ // the canvas orientation based on the orientation option,
77
+ // gets canvas, options passed as arguments:
78
+ loadImage.transformCoordinates = function () {
79
+ return;
93
80
  };
94
81
 
95
- // Detects vertical squash in JPEG images:
96
- loadImage.detectVerticalSquash = function (img, correctedHeight) {
97
- var canvas = document.createElement('canvas'),
98
- context = canvas.getContext('2d'),
99
- data,
100
- sy,
101
- ey,
102
- py,
103
- alpha;
104
- canvas.width = 1;
105
- canvas.height = correctedHeight;
106
- context.drawImage(img, 0, 0);
107
- data = context.getImageData(0, 0, 1, correctedHeight).data;
108
- // search image edge pixel position in case it is squashed vertically:
109
- sy = 0;
110
- ey = correctedHeight;
111
- py = correctedHeight;
112
- while (py > sy) {
113
- alpha = data[(py - 1) * 4 + 3];
114
- if (alpha === 0) {
115
- ey = py;
116
- } else {
117
- sy = py;
118
- }
119
- py = (ey + sy) >> 1;
120
- }
121
- return (py / correctedHeight) || 1;
82
+ // Returns transformed options, allows to override e.g.
83
+ // coordinate and dimension options based on the orientation:
84
+ loadImage.getTransformedOptions = function (options) {
85
+ return options;
122
86
  };
123
87
 
124
- // Renders image to canvas while working around iOS image scaling bugs:
125
- // https://github.com/blueimp/JavaScript-Load-Image/issues/13
88
+ // Canvas render method, allows to override the
89
+ // rendering e.g. to work around issues on iOS:
126
90
  loadImage.renderImageToCanvas = function (
127
91
  canvas,
128
92
  img,
@@ -135,144 +99,143 @@
135
99
  destWidth,
136
100
  destHeight
137
101
  ) {
138
- var context = canvas.getContext('2d'),
139
- tmpCanvas = document.createElement('canvas'),
140
- tileSize = tmpCanvas.width = tmpCanvas.height = 1024,
141
- tmpContext = tmpCanvas.getContext('2d'),
142
- vertSquashRatio,
143
- tileX,
144
- tileY;
145
- context.save();
146
- if (loadImage.detectSubsampling(img)) {
147
- sourceWidth /= 2;
148
- sourceHeight /= 2;
149
- }
150
- vertSquashRatio = loadImage.detectVerticalSquash(img, sourceHeight);
151
- destWidth = Math.ceil(tileSize * destWidth / sourceWidth);
152
- destHeight = Math.ceil(
153
- tileSize * destHeight / sourceHeight / vertSquashRatio
102
+ canvas.getContext('2d').drawImage(
103
+ img,
104
+ sourceX,
105
+ sourceY,
106
+ sourceWidth,
107
+ sourceHeight,
108
+ destX,
109
+ destY,
110
+ destWidth,
111
+ destHeight
154
112
  );
155
- destY = 0;
156
- tileY = 0;
157
- while (tileY < sourceHeight) {
158
- destX = 0;
159
- tileX = 0;
160
- while (tileX < sourceWidth) {
161
- tmpContext.clearRect(0, 0, tileSize, tileSize);
162
- tmpContext.drawImage(
163
- img,
164
- sourceX,
165
- sourceY,
166
- sourceWidth,
167
- sourceHeight,
168
- -tileX,
169
- -tileY,
170
- sourceWidth,
171
- sourceHeight
172
- );
173
- context.drawImage(
174
- tmpCanvas,
175
- 0,
176
- 0,
177
- tileSize,
178
- tileSize,
179
- destX,
180
- destY,
181
- destWidth,
182
- destHeight
183
- );
184
- tileX += tileSize;
185
- destX += destWidth;
186
- }
187
- tileY += tileSize;
188
- destY += destHeight;
189
- }
190
- context.restore();
113
+ return canvas;
191
114
  };
192
115
 
193
- // Scales the given image (img or canvas HTML element)
116
+ // This method is used to determine if the target image
117
+ // should be a canvas element:
118
+ loadImage.hasCanvasOption = function (options) {
119
+ return options.canvas || options.crop;
120
+ };
121
+
122
+ // Scales and/or crops the given image (img or canvas HTML element)
194
123
  // using the given options.
195
124
  // Returns a canvas object if the browser supports canvas
196
- // and the canvas or crop option is true or a canvas object
197
- // is passed as image, else the scaled image:
125
+ // and the hasCanvasOption method returns true or a canvas
126
+ // object is passed as image, else the scaled image:
198
127
  loadImage.scale = function (img, options) {
199
128
  options = options || {};
200
129
  var canvas = document.createElement('canvas'),
201
130
  useCanvas = img.getContext ||
202
- ((options.canvas || options.crop) && canvas.getContext),
203
- width = img.width,
204
- height = img.height,
205
- maxWidth = options.maxWidth,
206
- maxHeight = options.maxHeight,
207
- sourceWidth = width,
208
- sourceHeight = height,
209
- sourceX = 0,
210
- sourceY = 0,
211
- destX = 0,
212
- destY = 0,
213
- destWidth,
214
- destHeight,
215
- scale;
131
+ (loadImage.hasCanvasOption(options) && canvas.getContext),
132
+ width = img.naturalWidth || img.width,
133
+ height = img.naturalHeight || img.height,
134
+ destWidth = width,
135
+ destHeight = height,
136
+ maxWidth,
137
+ maxHeight,
138
+ minWidth,
139
+ minHeight,
140
+ sourceWidth,
141
+ sourceHeight,
142
+ sourceX,
143
+ sourceY,
144
+ tmp,
145
+ scaleUp = function () {
146
+ var scale = Math.max(
147
+ (minWidth || destWidth) / destWidth,
148
+ (minHeight || destHeight) / destHeight
149
+ );
150
+ if (scale > 1) {
151
+ destWidth = Math.ceil(destWidth * scale);
152
+ destHeight = Math.ceil(destHeight * scale);
153
+ }
154
+ },
155
+ scaleDown = function () {
156
+ var scale = Math.min(
157
+ (maxWidth || destWidth) / destWidth,
158
+ (maxHeight || destHeight) / destHeight
159
+ );
160
+ if (scale < 1) {
161
+ destWidth = Math.ceil(destWidth * scale);
162
+ destHeight = Math.ceil(destHeight * scale);
163
+ }
164
+ };
165
+ if (useCanvas) {
166
+ options = loadImage.getTransformedOptions(options);
167
+ sourceX = options.left || 0;
168
+ sourceY = options.top || 0;
169
+ if (options.sourceWidth) {
170
+ sourceWidth = options.sourceWidth;
171
+ if (options.right !== undefined && options.left === undefined) {
172
+ sourceX = width - sourceWidth - options.right;
173
+ }
174
+ } else {
175
+ sourceWidth = width - sourceX - (options.right || 0);
176
+ }
177
+ if (options.sourceHeight) {
178
+ sourceHeight = options.sourceHeight;
179
+ if (options.bottom !== undefined && options.top === undefined) {
180
+ sourceY = height - sourceHeight - options.bottom;
181
+ }
182
+ } else {
183
+ sourceHeight = height - sourceY - (options.bottom || 0);
184
+ }
185
+ destWidth = sourceWidth;
186
+ destHeight = sourceHeight;
187
+ }
188
+ maxWidth = options.maxWidth;
189
+ maxHeight = options.maxHeight;
190
+ minWidth = options.minWidth;
191
+ minHeight = options.minHeight;
216
192
  if (useCanvas && maxWidth && maxHeight && options.crop) {
217
193
  destWidth = maxWidth;
218
194
  destHeight = maxHeight;
219
- if (width / height < maxWidth / maxHeight) {
220
- sourceHeight = maxHeight * width / maxWidth;
221
- sourceY = (height - sourceHeight) / 2;
222
- } else {
223
- sourceWidth = maxWidth * height / maxHeight;
224
- sourceX = (width - sourceWidth) / 2;
195
+ tmp = sourceWidth / sourceHeight - maxWidth / maxHeight;
196
+ if (tmp < 0) {
197
+ sourceHeight = maxHeight * sourceWidth / maxWidth;
198
+ if (options.top === undefined && options.bottom === undefined) {
199
+ sourceY = (height - sourceHeight) / 2;
200
+ }
201
+ } else if (tmp > 0) {
202
+ sourceWidth = maxWidth * sourceHeight / maxHeight;
203
+ if (options.left === undefined && options.right === undefined) {
204
+ sourceX = (width - sourceWidth) / 2;
205
+ }
225
206
  }
226
207
  } else {
227
- destWidth = width;
228
- destHeight = height;
229
- scale = Math.max(
230
- (options.minWidth || destWidth) / destWidth,
231
- (options.minHeight || destHeight) / destHeight
232
- );
233
- if (scale > 1) {
234
- destWidth = Math.ceil(destWidth * scale);
235
- destHeight = Math.ceil(destHeight * scale);
208
+ if (options.contain || options.cover) {
209
+ minWidth = maxWidth = maxWidth || minWidth;
210
+ minHeight = maxHeight = maxHeight || minHeight;
236
211
  }
237
- scale = Math.min(
238
- (maxWidth || destWidth) / destWidth,
239
- (maxHeight || destHeight) / destHeight
240
- );
241
- if (scale < 1) {
242
- destWidth = Math.ceil(destWidth * scale);
243
- destHeight = Math.ceil(destHeight * scale);
212
+ if (options.cover) {
213
+ scaleDown();
214
+ scaleUp();
215
+ } else {
216
+ scaleUp();
217
+ scaleDown();
244
218
  }
245
219
  }
246
220
  if (useCanvas) {
247
221
  canvas.width = destWidth;
248
222
  canvas.height = destHeight;
249
- if (img._type === 'image/jpeg') {
250
- loadImage.renderImageToCanvas(
251
- canvas,
252
- img,
253
- sourceX,
254
- sourceY,
255
- sourceWidth,
256
- sourceHeight,
257
- destX,
258
- destY,
259
- destWidth,
260
- destHeight
261
- );
262
- } else {
263
- canvas.getContext('2d').drawImage(
264
- img,
265
- sourceX,
266
- sourceY,
267
- sourceWidth,
268
- sourceHeight,
269
- destX,
270
- destY,
271
- destWidth,
272
- destHeight
273
- );
274
- }
275
- return canvas;
223
+ loadImage.transformCoordinates(
224
+ canvas,
225
+ options
226
+ );
227
+ return loadImage.renderImageToCanvas(
228
+ canvas,
229
+ img,
230
+ sourceX,
231
+ sourceY,
232
+ sourceWidth,
233
+ sourceHeight,
234
+ 0,
235
+ 0,
236
+ destWidth,
237
+ destHeight
238
+ );
276
239
  }
277
240
  img.width = destWidth;
278
241
  img.height = destHeight;
@@ -290,12 +253,15 @@
290
253
  // Loads a given File object via FileReader interface,
291
254
  // invokes the callback with the event object (load or error).
292
255
  // The result can be read via event.target.result:
293
- loadImage.readFile = function (file, callback) {
294
- if (window.FileReader && FileReader.prototype.readAsDataURL) {
256
+ loadImage.readFile = function (file, callback, method) {
257
+ if (window.FileReader) {
295
258
  var fileReader = new FileReader();
296
259
  fileReader.onload = fileReader.onerror = callback;
297
- fileReader.readAsDataURL(file);
298
- return fileReader;
260
+ method = method || 'readAsDataURL';
261
+ if (fileReader[method]) {
262
+ fileReader[method](file);
263
+ return fileReader;
264
+ }
299
265
  }
300
266
  return false;
301
267
  };
@@ -1,5 +1,5 @@
1
1
  /*
2
- * JavaScript Templates 2.1.0
2
+ * JavaScript Templates 2.2.0
3
3
  * https://github.com/blueimp/JavaScript-Templates
4
4
  *
5
5
  * Copyright 2011, Sebastian Tschan
@@ -15,7 +15,6 @@
15
15
  /*jslint evil: true, regexp: true */
16
16
  /*global document, define */
17
17
 
18
-
19
18
  (function ($) {
20
19
  "use strict";
21
20
  var tmpl = function (str, data) {
@@ -49,7 +48,7 @@
49
48
  if (p2 === "=") {
50
49
  return "'+_e(" + p3 + ")+'";
51
50
  }
52
- return "'+(" + p3 + "||'')+'";
51
+ return "'+" + p3 + "+'";
53
52
  }
54
53
  if (p4) { // evaluation start tag: {%
55
54
  return "';";
@@ -67,7 +66,7 @@
67
66
  "'" : "&#39;"
68
67
  };
69
68
  tmpl.encode = function (s) {
70
- return String(s || "").replace(
69
+ return String(s).replace(
71
70
  tmpl.encReg,
72
71
  function (c) {
73
72
  return tmpl.encMap[c] || "";