|
1 | 1 | /*
|
2 |
| - * JavaScript Load Image 1.1.2 |
| 2 | + * JavaScript Load Image 1.1.3 |
3 | 3 | * https://github.com/blueimp/JavaScript-Load-Image
|
4 | 4 | *
|
5 | 5 | * Copyright 2011, Sebastian Tschan
|
|
10 | 10 | */
|
11 | 11 |
|
12 | 12 | /*jslint nomen: true */
|
13 |
| -/*global window, document, Blob, URL, webkitURL, FileReader, define */ |
| 13 | +/*global window, document, URL, webkitURL, Blob, FileReader, define */ |
14 | 14 |
|
15 | 15 | (function ($) {
|
16 | 16 | 'use strict';
|
|
22 | 22 | var img = document.createElement('img'),
|
23 | 23 | url,
|
24 | 24 | isFile;
|
25 |
| - if (file instanceof Blob) { |
| 25 | + if (window.Blob && file instanceof Blob) { |
26 | 26 | url = loadImage.createObjectURL(file);
|
27 | 27 | isFile = true;
|
28 | 28 | } else {
|
|
44 | 44 | });
|
45 | 45 | }
|
46 | 46 | },
|
47 |
| - undef = 'undefined'; |
| 47 | + urlAPI = (window.createObjectURL && window) || |
| 48 | + (window.URL && URL) || (window.webkitURL && webkitURL); |
48 | 49 |
|
49 | 50 | // Scales the given image (img HTML element)
|
50 | 51 | // using the given options.
|
|
80 | 81 | };
|
81 | 82 |
|
82 | 83 | loadImage.createObjectURL = function (file) {
|
83 |
| - var urlAPI = (typeof window.createObjectURL !== undef && window) || |
84 |
| - (typeof URL !== undef && URL) || |
85 |
| - (typeof webkitURL !== undef && webkitURL); |
86 | 84 | return urlAPI ? urlAPI.createObjectURL(file) : false;
|
87 | 85 | };
|
88 | 86 |
|
89 | 87 | loadImage.revokeObjectURL = function (url) {
|
90 |
| - var urlAPI = (typeof window.revokeObjectURL !== undef && window) || |
91 |
| - (typeof URL !== undef && URL) || |
92 |
| - (typeof webkitURL !== undef && webkitURL); |
93 | 88 | return urlAPI ? urlAPI.revokeObjectURL(url) : false;
|
94 | 89 | };
|
95 | 90 |
|
96 | 91 | // Loads a given File object via FileReader interface,
|
97 | 92 | // invokes the callback with a data url:
|
98 | 93 | loadImage.readFile = function (file, callback) {
|
99 |
| - if (typeof FileReader !== undef && |
100 |
| - FileReader.prototype.readAsDataURL) { |
| 94 | + if (window.FileReader && FileReader.prototype.readAsDataURL) { |
101 | 95 | var fileReader = new FileReader();
|
102 | 96 | fileReader.onload = function (e) {
|
103 | 97 | callback(e.target.result);
|
|
108 | 102 | return false;
|
109 | 103 | };
|
110 | 104 |
|
111 |
| - if (typeof define !== undef && define.amd) { |
| 105 | + if (typeof define !== 'undefined' && define.amd) { |
112 | 106 | // Register as an AMD module:
|
113 | 107 | define('loadImage', function () {
|
114 | 108 | return loadImage;
|
|
0 commit comments