|
75 | 75 | } |
76 | 76 | } |
77 | 77 |
|
| 78 | + /** |
| 79 | + * Cross-frame instanceof check. |
| 80 | + * |
| 81 | + * @param {string} type Instance type |
| 82 | + * @param {object} obj Object instance |
| 83 | + * @returns {boolean} Returns true if the object is of the given instance. |
| 84 | + */ |
| 85 | + function isInstanceOf(type, obj) { |
| 86 | + // Cross-frame instanceof check |
| 87 | + return Object.prototype.toString.call(obj) === '[object ' + type + ']' |
| 88 | + } |
| 89 | + |
78 | 90 | /** |
79 | 91 | * Loads an image for a given File object. |
80 | 92 | * |
|
122 | 134 | */ |
123 | 135 | function fetchBlobCallback(blob, err) { |
124 | 136 | if (err && $.console) console.log(err) // eslint-disable-line no-console |
125 | | - if (blob && loadImage.isInstanceOf('Blob', blob)) { |
| 137 | + if (blob && isInstanceOf('Blob', blob)) { |
126 | 138 | file = blob // eslint-disable-line no-param-reassign |
127 | 139 | url = createObjectURL(file) |
128 | 140 | } else { |
|
156 | 168 | fetchBlobCallback() |
157 | 169 | } |
158 | 170 | return img |
159 | | - } else if ( |
160 | | - loadImage.isInstanceOf('Blob', file) || |
161 | | - // Files are also Blob instances, but some browsers |
162 | | - // (Firefox 3.6) support the File API but not Blobs: |
163 | | - loadImage.isInstanceOf('File', file) |
164 | | - ) { |
| 171 | + } else if (isInstanceOf('Blob', file) || isInstanceOf('File', file)) { |
165 | 172 | url = createObjectURL(file) |
166 | 173 | if (url) { |
167 | 174 | img.src = url |
|
196 | 203 | callback() |
197 | 204 | } |
198 | 205 |
|
199 | | - loadImage.isInstanceOf = function (type, obj) { |
200 | | - // Cross-frame instanceof check |
201 | | - return Object.prototype.toString.call(obj) === '[object ' + type + ']' |
202 | | - } |
203 | | - |
204 | 206 | loadImage.transform = function (img, options, callback, file, data) { |
205 | 207 | callback(img, data) |
206 | 208 | } |
207 | 209 |
|
208 | 210 | loadImage.global = $ |
209 | 211 | loadImage.readFile = readFile |
| 212 | + loadImage.isInstanceOf = isInstanceOf |
210 | 213 | loadImage.createObjectURL = createObjectURL |
211 | 214 | loadImage.revokeObjectURL = revokeObjectURL |
212 | 215 |
|
|
0 commit comments