|
17 | 17 | // Loads an image for a given File object.
|
18 | 18 | // Invokes the callback with an img or optional canvas
|
19 | 19 | // element (if supported by the browser) as parameter:
|
20 |
| - var loadImage = function (file, callback, options) { |
| 20 | + function loadImage (file, callback, options) { |
21 | 21 | var img = document.createElement('img')
|
22 | 22 | var url
|
23 |
| - var oUrl |
24 |
| - img.onerror = callback |
25 |
| - img.onload = function () { |
26 |
| - if (oUrl && !(options && options.noRevoke)) { |
27 |
| - loadImage.revokeObjectURL(oUrl) |
28 |
| - } |
29 |
| - if (callback) { |
30 |
| - callback(loadImage.scale(img, options)) |
31 |
| - } |
| 23 | + img.onerror = function (event) { |
| 24 | + return loadImage.onerror(img, event, file, callback, options) |
| 25 | + } |
| 26 | + img.onload = function (event) { |
| 27 | + return loadImage.onload(img, event, file, callback, options) |
32 | 28 | }
|
33 | 29 | if (loadImage.isInstanceOf('Blob', file) ||
|
34 | 30 | // Files are also Blob instances, but some browsers
|
35 | 31 | // (Firefox 3.6) support the File API but not Blobs:
|
36 | 32 | loadImage.isInstanceOf('File', file)) {
|
37 |
| - url = oUrl = loadImage.createObjectURL(file) |
| 33 | + url = img._objectURL = loadImage.createObjectURL(file) |
38 | 34 | // Store the file type for resize processing:
|
39 | 35 | img._type = file.type
|
40 | 36 | } else if (typeof file === 'string') {
|
|
53 | 49 | var target = e.target
|
54 | 50 | if (target && target.result) {
|
55 | 51 | img.src = target.result
|
56 |
| - } else { |
57 |
| - if (callback) { |
58 |
| - callback(e) |
59 |
| - } |
| 52 | + } else if (callback) { |
| 53 | + callback(e) |
60 | 54 | }
|
61 | 55 | })
|
62 | 56 | }
|
|
71 | 65 | return Object.prototype.toString.call(obj) === '[object ' + type + ']'
|
72 | 66 | }
|
73 | 67 |
|
| 68 | + loadImage.onerror = function (img, event, file, callback, options) { |
| 69 | + if (callback) { |
| 70 | + callback.call(img, event) |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + loadImage.onload = function (img, event, file, callback, options) { |
| 75 | + if (img._objectURL && !(options && options.noRevoke)) { |
| 76 | + loadImage.revokeObjectURL(img._objectURL) |
| 77 | + } |
| 78 | + if (callback) { |
| 79 | + callback(loadImage.scale(img, options)) |
| 80 | + } |
| 81 | + } |
| 82 | + |
74 | 83 | // Transform image coordinates, allows to override e.g.
|
75 | 84 | // the canvas orientation based on the orientation option,
|
76 | 85 | // gets canvas, options passed as arguments:
|
|
0 commit comments