|
204 | 204 | }
|
205 | 205 | },
|
206 | 206 |
|
207 |
| - // Scales the given image (img HTML element) |
208 |
| - // using the given options. |
209 |
| - // Returns a canvas object if the canvas option is true |
210 |
| - // and the browser supports canvas, else the scaled image: |
211 |
| - _scaleImage: function (img, options) { |
212 |
| - options = options || {}; |
213 |
| - var canvas = document.createElement('canvas'), |
214 |
| - scale = Math.min( |
215 |
| - (options.maxWidth || img.width) / img.width, |
216 |
| - (options.maxHeight || img.height) / img.height |
217 |
| - ); |
218 |
| - if (scale >= 1) { |
219 |
| - scale = Math.max( |
220 |
| - (options.minWidth || img.width) / img.width, |
221 |
| - (options.minHeight || img.height) / img.height |
222 |
| - ); |
223 |
| - } |
224 |
| - img.width = parseInt(img.width * scale, 10); |
225 |
| - img.height = parseInt(img.height * scale, 10); |
226 |
| - if (!options.canvas || !canvas.getContext) { |
227 |
| - return img; |
228 |
| - } |
229 |
| - canvas.width = img.width; |
230 |
| - canvas.height = img.height; |
231 |
| - canvas.getContext('2d') |
232 |
| - .drawImage(img, 0, 0, img.width, img.height); |
233 |
| - return canvas; |
234 |
| - }, |
235 |
| - |
236 | 207 | _createObjectURL: function (file) {
|
237 | 208 | var undef = 'undefined',
|
238 | 209 | urlAPI = (typeof window.createObjectURL !== undef && window) ||
|
|
264 | 235 | return false;
|
265 | 236 | },
|
266 | 237 |
|
267 |
| - // Loads an image for a given File object. |
268 |
| - // Invokes the callback with an img or optional canvas |
269 |
| - // element (if supported by the browser) as parameter: |
270 |
| - _loadImage: function (file, callback, options) { |
271 |
| - var that = this, |
272 |
| - url, |
273 |
| - img; |
274 |
| - if (!options || !options.fileTypes || |
275 |
| - options.fileTypes.test(file.type)) { |
276 |
| - url = this._createObjectURL(file); |
277 |
| - img = $('<img>').bind('load', function () { |
278 |
| - $(this).unbind('load'); |
279 |
| - that._revokeObjectURL(url); |
280 |
| - callback(that._scaleImage(img[0], options)); |
281 |
| - }).prop('src', url); |
282 |
| - if (!url) { |
283 |
| - this._loadFile(file, function (url) { |
284 |
| - img.prop('src', url); |
285 |
| - }); |
286 |
| - } |
287 |
| - } |
288 |
| - }, |
289 |
| - |
290 | 238 | // Link handler, that allows to download files
|
291 | 239 | // by drag & drop of the links to the desktop:
|
292 | 240 | _enableDragToDesktop: function () {
|
|
406 | 354 | text: false,
|
407 | 355 | icons: {primary: 'ui-icon-cancel'}
|
408 | 356 | });
|
409 |
| - tmpl.find('.preview').each(function (index, node) { |
410 |
| - that._loadImage( |
411 |
| - files[index], |
412 |
| - function (img) { |
413 |
| - $(img).hide().appendTo(node).fadeIn(); |
414 |
| - }, |
415 |
| - { |
416 |
| - maxWidth: options.previewMaxWidth, |
417 |
| - maxHeight: options.previewMaxHeight, |
418 |
| - fileTypes: options.previewFileTypes, |
419 |
| - canvas: options.previewAsCanvas |
420 |
| - } |
421 |
| - ); |
422 |
| - }); |
423 | 357 | return tmpl;
|
424 | 358 | },
|
425 | 359 |
|
|
0 commit comments