|
11 | 11 |
|
12 | 12 | /* global define, webkitURL, module */ |
13 | 13 |
|
14 | | -;(function($) { |
| 14 | +;(function ($) { |
15 | 15 | 'use strict' |
16 | 16 |
|
17 | 17 | /** |
|
27 | 27 | function loadImage(file, callback, options) { |
28 | 28 | var img = document.createElement('img') |
29 | 29 | var url |
30 | | - img.onerror = function(event) { |
| 30 | + img.onerror = function (event) { |
31 | 31 | return loadImage.onerror(img, event, file, callback, options) |
32 | 32 | } |
33 | | - img.onload = function(event) { |
| 33 | + img.onload = function (event) { |
34 | 34 | return loadImage.onload(img, event, file, callback, options) |
35 | 35 | } |
36 | 36 | if (typeof file === 'string') { |
37 | 37 | loadImage.fetchBlob( |
38 | 38 | file, |
39 | | - function(blob) { |
| 39 | + function (blob) { |
40 | 40 | if (blob && loadImage.isInstanceOf('Blob', blob)) { |
41 | 41 | // eslint-disable-next-line no-param-reassign |
42 | 42 | file = blob |
|
63 | 63 | img.src = url |
64 | 64 | return img |
65 | 65 | } |
66 | | - return loadImage.readFile(file, function(e) { |
| 66 | + return loadImage.readFile(file, function (e) { |
67 | 67 | var target = e.target |
68 | 68 | if (target && target.result) { |
69 | 69 | img.src = target.result |
|
96 | 96 | // If the callback given to this function returns a blob, it is used as image |
97 | 97 | // source instead of the original url and overrides the file argument used in |
98 | 98 | // the onload and onerror event callbacks: |
99 | | - loadImage.fetchBlob = function(url, callback) { |
| 99 | + loadImage.fetchBlob = function (url, callback) { |
100 | 100 | callback() |
101 | 101 | } |
102 | 102 |
|
103 | | - loadImage.isInstanceOf = function(type, obj) { |
| 103 | + loadImage.isInstanceOf = function (type, obj) { |
104 | 104 | // Cross-frame instanceof check |
105 | 105 | return Object.prototype.toString.call(obj) === '[object ' + type + ']' |
106 | 106 | } |
107 | 107 |
|
108 | | - loadImage.transform = function(img, options, callback, file, data) { |
| 108 | + loadImage.transform = function (img, options, callback, file, data) { |
109 | 109 | callback(img, data) |
110 | 110 | } |
111 | 111 |
|
112 | | - loadImage.onerror = function(img, event, file, callback, options) { |
| 112 | + loadImage.onerror = function (img, event, file, callback, options) { |
113 | 113 | revokeHelper(img, options) |
114 | 114 | if (callback) { |
115 | 115 | callback.call(img, event) |
116 | 116 | } |
117 | 117 | } |
118 | 118 |
|
119 | | - loadImage.onload = function(img, event, file, callback, options) { |
| 119 | + loadImage.onload = function (img, event, file, callback, options) { |
120 | 120 | revokeHelper(img, options) |
121 | 121 | if (callback) { |
122 | 122 | loadImage.transform(img, options, callback, file, { |
|
126 | 126 | } |
127 | 127 | } |
128 | 128 |
|
129 | | - loadImage.createObjectURL = function(file) { |
| 129 | + loadImage.createObjectURL = function (file) { |
130 | 130 | return urlAPI ? urlAPI.createObjectURL(file) : false |
131 | 131 | } |
132 | 132 |
|
133 | | - loadImage.revokeObjectURL = function(url) { |
| 133 | + loadImage.revokeObjectURL = function (url) { |
134 | 134 | return urlAPI ? urlAPI.revokeObjectURL(url) : false |
135 | 135 | } |
136 | 136 |
|
137 | 137 | // Loads a given File object via FileReader interface, |
138 | 138 | // invokes the callback with the event object (load or error). |
139 | 139 | // The result can be read via event.target.result: |
140 | | - loadImage.readFile = function(file, callback, method) { |
| 140 | + loadImage.readFile = function (file, callback, method) { |
141 | 141 | if ($.FileReader) { |
142 | 142 | var fileReader = new FileReader() |
143 | 143 | fileReader.onload = fileReader.onerror = callback |
|
152 | 152 | } |
153 | 153 |
|
154 | 154 | if (typeof define === 'function' && define.amd) { |
155 | | - define(function() { |
| 155 | + define(function () { |
156 | 156 | return loadImage |
157 | 157 | }) |
158 | 158 | } else if (typeof module === 'object' && module.exports) { |
|
0 commit comments