jquery-file-upload-rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.md +55 -0
  4. data/Rakefile +32 -0
  5. data/app/views/jquery_file_upload/basic_plus_ui/_download.html.erb +43 -0
  6. data/app/views/jquery_file_upload/basic_plus_ui/_form.html.haml +35 -0
  7. data/app/views/jquery_file_upload/basic_plus_ui/_upload.html.erb +32 -0
  8. data/config/locales/jquery_file_upload.cs.yml +16 -0
  9. data/config/locales/jquery_file_upload.en.yml +16 -0
  10. data/lib/jquery-file-upload-rails.rb +1 -0
  11. data/lib/jquery_file_upload/rails.rb +6 -0
  12. data/lib/jquery_file_upload/rails/version.rb +5 -0
  13. data/test/dummy/README.rdoc +28 -0
  14. data/test/dummy/app/assets/javascripts/application.js +13 -0
  15. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  16. data/test/dummy/app/controllers/application_controller.rb +5 -0
  17. data/test/dummy/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  19. data/test/dummy/bin/bundle +3 -0
  20. data/test/dummy/bin/rails +4 -0
  21. data/test/dummy/bin/rake +4 -0
  22. data/test/dummy/config.ru +4 -0
  23. data/test/dummy/config/application.rb +22 -0
  24. data/test/dummy/config/boot.rb +5 -0
  25. data/test/dummy/config/database.yml +25 -0
  26. data/test/dummy/config/environment.rb +5 -0
  27. data/test/dummy/config/environments/development.rb +29 -0
  28. data/test/dummy/config/environments/production.rb +80 -0
  29. data/test/dummy/config/environments/test.rb +36 -0
  30. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  31. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  32. data/test/dummy/config/initializers/inflections.rb +16 -0
  33. data/test/dummy/config/initializers/mime_types.rb +5 -0
  34. data/test/dummy/config/initializers/secret_token.rb +12 -0
  35. data/test/dummy/config/initializers/session_store.rb +3 -0
  36. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  37. data/test/dummy/config/locales/en.yml +23 -0
  38. data/test/dummy/config/routes.rb +56 -0
  39. data/test/dummy/db/test.sqlite3 +0 -0
  40. data/test/jquery_file_upload_rails_test.rb +7 -0
  41. data/test/test_helper.rb +15 -0
  42. data/vendor/assets/images/jquery-file-upload/loading.gif +0 -0
  43. data/vendor/assets/images/jquery-file-upload/progressbar.gif +0 -0
  44. data/vendor/assets/javascripts/jquery-file-upload/app.js +101 -0
  45. data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui-no-widget.js.coffee +35 -0
  46. data/vendor/assets/javascripts/jquery-file-upload/basic-plus-ui.js.coffee +38 -0
  47. data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.postmessage-transport.js +118 -0
  48. data/vendor/assets/javascripts/jquery-file-upload/cors/jquery.xdr-transport.js +87 -0
  49. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-angular.js +428 -0
  50. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-audio.js +106 -0
  51. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-image.js +295 -0
  52. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-jquery-ui.js +144 -0
  53. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-process.js +172 -0
  54. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-ui.js +699 -0
  55. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-validate.js +120 -0
  56. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload-video.js +106 -0
  57. data/vendor/assets/javascripts/jquery-file-upload/jquery.fileupload.js +1416 -0
  58. data/vendor/assets/javascripts/jquery-file-upload/jquery.iframe-transport.js +210 -0
  59. data/vendor/assets/javascripts/jquery-file-upload/main.js.coffee +4 -0
  60. data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.js +95 -0
  61. data/vendor/assets/javascripts/jquery-file-upload/vendor/canvas-to-blob/canvas-to-blob.min.js +1 -0
  62. data/vendor/assets/javascripts/jquery-file-upload/vendor/jquery.ui.widget.js +530 -0
  63. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/demo.js +138 -0
  64. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif-map.js +384 -0
  65. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-exif.js +299 -0
  66. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-ios.js +181 -0
  67. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-meta.js +137 -0
  68. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image-orientation.js +159 -0
  69. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.js +276 -0
  70. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/load-image.min.js +1 -0
  71. data/vendor/assets/javascripts/jquery-file-upload/vendor/load-image/vendor/jquery.Jcrop.js +1694 -0
  72. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/compile.js +84 -0
  73. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/demo.js +48 -0
  74. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/runtime.js +47 -0
  75. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.js +87 -0
  76. data/vendor/assets/javascripts/jquery-file-upload/vendor/templates/tmpl.min.js +1 -0
  77. data/vendor/assets/stylesheets/jquery-file-upload/demo-ie8.css +21 -0
  78. data/vendor/assets/stylesheets/jquery-file-upload/demo.css +67 -0
  79. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-noscript.css +22 -0
  80. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui-noscript.css +17 -0
  81. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload-ui.css.scss +57 -0
  82. data/vendor/assets/stylesheets/jquery-file-upload/jquery.fileupload.css +36 -0
  83. data/vendor/assets/stylesheets/jquery-file-upload/style.css +15 -0
  84. metadata +196 -0
@@ -0,0 +1,137 @@
1
+ /*
2
+ * JavaScript Load Image Meta 1.0.1
3
+ * https://github.com/blueimp/JavaScript-Load-Image
4
+ *
5
+ * Copyright 2013, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Image meta data handling implementation
9
+ * based on the help and contribution of
10
+ * Achim Stöhr.
11
+ *
12
+ * Licensed under the MIT license:
13
+ * http://www.opensource.org/licenses/MIT
14
+ */
15
+
16
+ /*jslint continue:true */
17
+ /*global define, window, DataView, Blob, Uint8Array, console */
18
+
19
+ (function (factory) {
20
+ 'use strict';
21
+ if (typeof define === 'function' && define.amd) {
22
+ // Register as an anonymous AMD module:
23
+ define(['load-image'], factory);
24
+ } else {
25
+ // Browser globals:
26
+ factory(window.loadImage);
27
+ }
28
+ }(function (loadImage) {
29
+ 'use strict';
30
+
31
+ var hasblobSlice = window.Blob && (Blob.prototype.slice ||
32
+ Blob.prototype.webkitSlice || Blob.prototype.mozSlice);
33
+
34
+ loadImage.blobSlice = hasblobSlice && function () {
35
+ var slice = this.slice || this.webkitSlice || this.mozSlice;
36
+ return slice.apply(this, arguments);
37
+ };
38
+
39
+ loadImage.metaDataParsers = {
40
+ jpeg: {
41
+ 0xffe1: [] // APP1 marker
42
+ }
43
+ };
44
+
45
+ // Parses image meta data and calls the callback with an object argument
46
+ // with the following properties:
47
+ // * imageHead: The complete image head as ArrayBuffer (Uint8Array for IE10)
48
+ // The options arguments accepts an object and supports the following properties:
49
+ // * maxMetaDataSize: Defines the maximum number of bytes to parse.
50
+ // * disableImageHead: Disables creating the imageHead property.
51
+ loadImage.parseMetaData = function (file, callback, options) {
52
+ options = options || {};
53
+ var that = this,
54
+ // 256 KiB should contain all EXIF/ICC/IPTC segments:
55
+ maxMetaDataSize = options.maxMetaDataSize || 262144,
56
+ data = {},
57
+ noMetaData = !(window.DataView && file && file.size >= 12 &&
58
+ file.type === 'image/jpeg' && loadImage.blobSlice);
59
+ if (noMetaData || !loadImage.readFile(
60
+ loadImage.blobSlice.call(file, 0, maxMetaDataSize),
61
+ function (e) {
62
+ // Note on endianness:
63
+ // Since the marker and length bytes in JPEG files are always
64
+ // stored in big endian order, we can leave the endian parameter
65
+ // of the DataView methods undefined, defaulting to big endian.
66
+ var buffer = e.target.result,
67
+ dataView = new DataView(buffer),
68
+ offset = 2,
69
+ maxOffset = dataView.byteLength - 4,
70
+ headLength = offset,
71
+ markerBytes,
72
+ markerLength,
73
+ parsers,
74
+ i;
75
+ // Check for the JPEG marker (0xffd8):
76
+ if (dataView.getUint16(0) === 0xffd8) {
77
+ while (offset < maxOffset) {
78
+ markerBytes = dataView.getUint16(offset);
79
+ // Search for APPn (0xffeN) and COM (0xfffe) markers,
80
+ // which contain application-specific meta-data like
81
+ // Exif, ICC and IPTC data and text comments:
82
+ if ((markerBytes >= 0xffe0 && markerBytes <= 0xffef) ||
83
+ markerBytes === 0xfffe) {
84
+ // The marker bytes (2) are always followed by
85
+ // the length bytes (2), indicating the length of the
86
+ // marker segment, which includes the length bytes,
87
+ // but not the marker bytes, so we add 2:
88
+ markerLength = dataView.getUint16(offset + 2) + 2;
89
+ if (offset + markerLength > dataView.byteLength) {
90
+ console.log('Invalid meta data: Invalid segment size.');
91
+ break;
92
+ }
93
+ parsers = loadImage.metaDataParsers.jpeg[markerBytes];
94
+ if (parsers) {
95
+ for (i = 0; i < parsers.length; i += 1) {
96
+ parsers[i].call(
97
+ that,
98
+ dataView,
99
+ offset,
100
+ markerLength,
101
+ data,
102
+ options
103
+ );
104
+ }
105
+ }
106
+ offset += markerLength;
107
+ headLength = offset;
108
+ } else {
109
+ // Not an APPn or COM marker, probably safe to
110
+ // assume that this is the end of the meta data
111
+ break;
112
+ }
113
+ }
114
+ // Meta length must be longer than JPEG marker (2)
115
+ // plus APPn marker (2), followed by length bytes (2):
116
+ if (!options.disableImageHead && headLength > 6) {
117
+ if (buffer.slice) {
118
+ data.imageHead = buffer.slice(0, headLength);
119
+ } else {
120
+ // Workaround for IE10, which does not yet
121
+ // support ArrayBuffer.slice:
122
+ data.imageHead = new Uint8Array(buffer)
123
+ .subarray(0, headLength);
124
+ }
125
+ }
126
+ } else {
127
+ console.log('Invalid JPEG file: Missing JPEG marker.');
128
+ }
129
+ callback(data);
130
+ },
131
+ 'readAsArrayBuffer'
132
+ )) {
133
+ callback(data);
134
+ }
135
+ };
136
+
137
+ }));
@@ -0,0 +1,159 @@
1
+ /*
2
+ * JavaScript Load Image Orientation 1.0.0
3
+ * https://github.com/blueimp/JavaScript-Load-Image
4
+ *
5
+ * Copyright 2013, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*global define, window */
13
+
14
+ (function (factory) {
15
+ 'use strict';
16
+ if (typeof define === 'function' && define.amd) {
17
+ // Register as an anonymous AMD module:
18
+ define(['load-image'], factory);
19
+ } else {
20
+ // Browser globals:
21
+ factory(window.loadImage);
22
+ }
23
+ }(function (loadImage) {
24
+ 'use strict';
25
+
26
+ var originalHasCanvasOptionMethod = loadImage.hasCanvasOption;
27
+
28
+ // This method is used to determine if the target image
29
+ // should be a canvas element:
30
+ loadImage.hasCanvasOption = function (options) {
31
+ return originalHasCanvasOptionMethod(options) || options.orientation;
32
+ };
33
+
34
+ // Transform image orientation based on
35
+ // the given EXIF orientation option:
36
+ loadImage.transformCoordinates = function (canvas, options) {
37
+ var ctx = canvas.getContext('2d'),
38
+ width = canvas.width,
39
+ height = canvas.height,
40
+ orientation = options.orientation;
41
+ if (!orientation) {
42
+ return;
43
+ }
44
+ if (orientation > 4) {
45
+ canvas.width = height;
46
+ canvas.height = width;
47
+ }
48
+ switch (orientation) {
49
+ case 2:
50
+ // horizontal flip
51
+ ctx.translate(width, 0);
52
+ ctx.scale(-1, 1);
53
+ break;
54
+ case 3:
55
+ // 180° rotate left
56
+ ctx.translate(width, height);
57
+ ctx.rotate(Math.PI);
58
+ break;
59
+ case 4:
60
+ // vertical flip
61
+ ctx.translate(0, height);
62
+ ctx.scale(1, -1);
63
+ break;
64
+ case 5:
65
+ // vertical flip + 90 rotate right
66
+ ctx.rotate(0.5 * Math.PI);
67
+ ctx.scale(1, -1);
68
+ break;
69
+ case 6:
70
+ // 90° rotate right
71
+ ctx.rotate(0.5 * Math.PI);
72
+ ctx.translate(0, -height);
73
+ break;
74
+ case 7:
75
+ // horizontal flip + 90 rotate right
76
+ ctx.rotate(0.5 * Math.PI);
77
+ ctx.translate(width, -height);
78
+ ctx.scale(-1, 1);
79
+ break;
80
+ case 8:
81
+ // 90° rotate left
82
+ ctx.rotate(-0.5 * Math.PI);
83
+ ctx.translate(-width, 0);
84
+ break;
85
+ }
86
+ };
87
+
88
+ // Transforms coordinate and dimension options
89
+ // based on the given orientation option:
90
+ loadImage.getTransformedOptions = function (options) {
91
+ if (!options.orientation || options.orientation === 1) {
92
+ return options;
93
+ }
94
+ var newOptions = {},
95
+ i;
96
+ for (i in options) {
97
+ if (options.hasOwnProperty(i)) {
98
+ newOptions[i] = options[i];
99
+ }
100
+ }
101
+ switch (options.orientation) {
102
+ case 2:
103
+ // horizontal flip
104
+ newOptions.left = options.right;
105
+ newOptions.right = options.left;
106
+ break;
107
+ case 3:
108
+ // 180° rotate left
109
+ newOptions.left = options.right;
110
+ newOptions.top = options.bottom;
111
+ newOptions.right = options.left;
112
+ newOptions.bottom = options.top;
113
+ break;
114
+ case 4:
115
+ // vertical flip
116
+ newOptions.top = options.bottom;
117
+ newOptions.bottom = options.top;
118
+ break;
119
+ case 5:
120
+ // vertical flip + 90 rotate right
121
+ newOptions.left = options.top;
122
+ newOptions.top = options.left;
123
+ newOptions.right = options.bottom;
124
+ newOptions.bottom = options.right;
125
+ break;
126
+ case 6:
127
+ // 90° rotate right
128
+ newOptions.left = options.top;
129
+ newOptions.top = options.right;
130
+ newOptions.right = options.bottom;
131
+ newOptions.bottom = options.left;
132
+ break;
133
+ case 7:
134
+ // horizontal flip + 90 rotate right
135
+ newOptions.left = options.bottom;
136
+ newOptions.top = options.right;
137
+ newOptions.right = options.top;
138
+ newOptions.bottom = options.left;
139
+ break;
140
+ case 8:
141
+ // 90° rotate left
142
+ newOptions.left = options.bottom;
143
+ newOptions.top = options.left;
144
+ newOptions.right = options.top;
145
+ newOptions.bottom = options.right;
146
+ break;
147
+ }
148
+ if (options.orientation > 4) {
149
+ newOptions.maxWidth = options.maxHeight;
150
+ newOptions.maxHeight = options.maxWidth;
151
+ newOptions.minWidth = options.minHeight;
152
+ newOptions.minHeight = options.minWidth;
153
+ newOptions.sourceWidth = options.sourceHeight;
154
+ newOptions.sourceHeight = options.sourceWidth;
155
+ }
156
+ return newOptions;
157
+ };
158
+
159
+ }));
@@ -0,0 +1,276 @@
1
+ /*
2
+ * JavaScript Load Image 1.9.0
3
+ * https://github.com/blueimp/JavaScript-Load-Image
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ */
11
+
12
+ /*jslint nomen: true */
13
+ /*global define, window, document, URL, webkitURL, Blob, File, FileReader */
14
+
15
+ (function ($) {
16
+ 'use strict';
17
+
18
+ // Loads an image for a given File object.
19
+ // Invokes the callback with an img or optional canvas
20
+ // element (if supported by the browser) as parameter:
21
+ var loadImage = function (file, callback, options) {
22
+ var img = document.createElement('img'),
23
+ url,
24
+ oUrl;
25
+ img.onerror = callback;
26
+ img.onload = function () {
27
+ if (oUrl && !(options && options.noRevoke)) {
28
+ loadImage.revokeObjectURL(oUrl);
29
+ }
30
+ if (callback) {
31
+ callback(loadImage.scale(img, options));
32
+ }
33
+ };
34
+ if (loadImage.isInstanceOf('Blob', file) ||
35
+ // Files are also Blob instances, but some browsers
36
+ // (Firefox 3.6) support the File API but not Blobs:
37
+ loadImage.isInstanceOf('File', file)) {
38
+ url = oUrl = loadImage.createObjectURL(file);
39
+ // Store the file type for resize processing:
40
+ img._type = file.type;
41
+ } else if (typeof file === 'string') {
42
+ url = file;
43
+ if (options && options.crossOrigin) {
44
+ img.crossOrigin = options.crossOrigin;
45
+ }
46
+ } else {
47
+ return false;
48
+ }
49
+ if (url) {
50
+ img.src = url;
51
+ return img;
52
+ }
53
+ return loadImage.readFile(file, function (e) {
54
+ var target = e.target;
55
+ if (target && target.result) {
56
+ img.src = target.result;
57
+ } else {
58
+ if (callback) {
59
+ callback(e);
60
+ }
61
+ }
62
+ });
63
+ },
64
+ // The check for URL.revokeObjectURL fixes an issue with Opera 12,
65
+ // which provides URL.createObjectURL but doesn't properly implement it:
66
+ urlAPI = (window.createObjectURL && window) ||
67
+ (window.URL && URL.revokeObjectURL && URL) ||
68
+ (window.webkitURL && webkitURL);
69
+
70
+ loadImage.isInstanceOf = function (type, obj) {
71
+ // Cross-frame instanceof check
72
+ return Object.prototype.toString.call(obj) === '[object ' + type + ']';
73
+ };
74
+
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;
80
+ };
81
+
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;
86
+ };
87
+
88
+ // Canvas render method, allows to override the
89
+ // rendering e.g. to work around issues on iOS:
90
+ loadImage.renderImageToCanvas = function (
91
+ canvas,
92
+ img,
93
+ sourceX,
94
+ sourceY,
95
+ sourceWidth,
96
+ sourceHeight,
97
+ destX,
98
+ destY,
99
+ destWidth,
100
+ destHeight
101
+ ) {
102
+ canvas.getContext('2d').drawImage(
103
+ img,
104
+ sourceX,
105
+ sourceY,
106
+ sourceWidth,
107
+ sourceHeight,
108
+ destX,
109
+ destY,
110
+ destWidth,
111
+ destHeight
112
+ );
113
+ return canvas;
114
+ };
115
+
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)
123
+ // using the given options.
124
+ // Returns a canvas object if the browser supports canvas
125
+ // and the hasCanvasOption method returns true or a canvas
126
+ // object is passed as image, else the scaled image:
127
+ loadImage.scale = function (img, options) {
128
+ options = options || {};
129
+ var canvas = document.createElement('canvas'),
130
+ useCanvas = img.getContext ||
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;
192
+ if (useCanvas && maxWidth && maxHeight && options.crop) {
193
+ destWidth = maxWidth;
194
+ destHeight = maxHeight;
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
+ }
206
+ }
207
+ } else {
208
+ if (options.contain || options.cover) {
209
+ minWidth = maxWidth = maxWidth || minWidth;
210
+ minHeight = maxHeight = maxHeight || minHeight;
211
+ }
212
+ if (options.cover) {
213
+ scaleDown();
214
+ scaleUp();
215
+ } else {
216
+ scaleUp();
217
+ scaleDown();
218
+ }
219
+ }
220
+ if (useCanvas) {
221
+ canvas.width = destWidth;
222
+ canvas.height = destHeight;
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
+ );
239
+ }
240
+ img.width = destWidth;
241
+ img.height = destHeight;
242
+ return img;
243
+ };
244
+
245
+ loadImage.createObjectURL = function (file) {
246
+ return urlAPI ? urlAPI.createObjectURL(file) : false;
247
+ };
248
+
249
+ loadImage.revokeObjectURL = function (url) {
250
+ return urlAPI ? urlAPI.revokeObjectURL(url) : false;
251
+ };
252
+
253
+ // Loads a given File object via FileReader interface,
254
+ // invokes the callback with the event object (load or error).
255
+ // The result can be read via event.target.result:
256
+ loadImage.readFile = function (file, callback, method) {
257
+ if (window.FileReader) {
258
+ var fileReader = new FileReader();
259
+ fileReader.onload = fileReader.onerror = callback;
260
+ method = method || 'readAsDataURL';
261
+ if (fileReader[method]) {
262
+ fileReader[method](file);
263
+ return fileReader;
264
+ }
265
+ }
266
+ return false;
267
+ };
268
+
269
+ if (typeof define === 'function' && define.amd) {
270
+ define(function () {
271
+ return loadImage;
272
+ });
273
+ } else {
274
+ $.loadImage = loadImage;
275
+ }
276
+ }(this));