|
1 | 1 | /*
|
2 |
| - * JavaScript Load Image 1.3.2 |
| 2 | + * JavaScript Load Image 1.4 |
3 | 3 | * https://github.com/blueimp/JavaScript-Load-Image
|
4 | 4 | *
|
5 | 5 | * Copyright 2011, Sebastian Tschan
|
|
30 | 30 | if (oUrl && !(options && options.noRevoke)) {
|
31 | 31 | loadImage.revokeObjectURL(oUrl);
|
32 | 32 | }
|
33 |
| - callback(loadImage.scale(img, options)); |
| 33 | + if (callback) { |
| 34 | + callback(loadImage.scale(img, options)); |
| 35 | + } |
34 | 36 | };
|
35 |
| - if ((window.Blob && file instanceof Blob) || |
36 |
| - // Files are also Blob instances, but some browsers |
37 |
| - // (Firefox 3.6) support the File API but not Blobs: |
38 |
| - (window.File && file instanceof File)) { |
| 37 | + if (loadImage.isInstanceOf('Blob', file) || |
| 38 | + // Files are also Blob instances, but some browsers |
| 39 | + // (Firefox 3.6) support the File API but not Blobs: |
| 40 | + loadImage.isInstanceOf('File', file)) { |
39 | 41 | url = oUrl = loadImage.createObjectURL(file);
|
40 | 42 | // Store the file type for resize processing:
|
41 | 43 | img._type = file.type;
|
42 | 44 | } else if (typeof file === 'string') {
|
43 | 45 | url = file;
|
| 46 | + if (options && options.crossOrigin) { |
| 47 | + img.crossOrigin = options.crossOrigin; |
| 48 | + } |
| 49 | + } else { |
| 50 | + return img; |
44 | 51 | }
|
45 | 52 | if (url) {
|
46 | 53 | img.src = url;
|
|
51 | 58 | if (target && target.result) {
|
52 | 59 | img.src = target.result;
|
53 | 60 | } else {
|
54 |
| - callback(e); |
| 61 | + if (callback) { |
| 62 | + callback(e); |
| 63 | + } |
55 | 64 | }
|
56 | 65 | });
|
57 | 66 | },
|
|
61 | 70 | (window.URL && URL.revokeObjectURL && URL) ||
|
62 | 71 | (window.webkitURL && webkitURL);
|
63 | 72 |
|
| 73 | + loadImage.isInstanceOf = function (type, obj) { |
| 74 | + // Cross-frame instanceof check |
| 75 | + return Object.prototype.toString.call(obj) === '[object ' + type + ']'; |
| 76 | + }; |
| 77 | + |
64 | 78 | // Detects subsampling in JPEG images:
|
65 | 79 | loadImage.detectSubsampling = function (img) {
|
66 | 80 | var iw = img.width,
|
|
0 commit comments