Skip to content

Commit 95b4694

Browse files
committed
Add url to load/error event handler params.
1 parent 79fdc82 commit 95b4694

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

js/load-image.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
var img = document.createElement('img')
2929
var url
3030
img.onerror = function (event) {
31-
return loadImage.onerror(img, event, file, callback, options)
31+
return loadImage.onerror(img, event, file, url, callback, options)
3232
}
3333
img.onload = function (event) {
34-
return loadImage.onload(img, event, file, callback, options)
34+
return loadImage.onload(img, event, file, url, callback, options)
3535
}
3636
if (typeof file === 'string') {
3737
loadImage.fetchBlob(
@@ -58,7 +58,7 @@
5858
// (Firefox 3.6) support the File API but not Blobs:
5959
loadImage.isInstanceOf('File', file)
6060
) {
61-
url = img._objectURL = loadImage.createObjectURL(file)
61+
url = loadImage.createObjectURL(file)
6262
if (url) {
6363
img.src = url
6464
return img
@@ -83,13 +83,12 @@
8383
/**
8484
* Helper function to revoke an object URL
8585
*
86-
* @param {HTMLImageElement} img Image element
86+
* @param {string} url Blob Object URL
8787
* @param {object} [options] Options object
8888
*/
89-
function revokeHelper(img, options) {
90-
if (img._objectURL && !(options && options.noRevoke)) {
91-
loadImage.revokeObjectURL(img._objectURL)
92-
delete img._objectURL
89+
function revokeHelper(url, options) {
90+
if (url && url.slice(0, 5) === 'blob:' && !(options && options.noRevoke)) {
91+
loadImage.revokeObjectURL(url)
9392
}
9493
}
9594

@@ -109,15 +108,15 @@
109108
callback(img, data)
110109
}
111110

112-
loadImage.onerror = function (img, event, file, callback, options) {
113-
revokeHelper(img, options)
111+
loadImage.onerror = function (img, event, file, url, callback, options) {
112+
revokeHelper(url, options)
114113
if (callback) {
115114
callback.call(img, event)
116115
}
117116
}
118117

119-
loadImage.onload = function (img, event, file, callback, options) {
120-
revokeHelper(img, options)
118+
loadImage.onload = function (img, event, file, url, callback, options) {
119+
revokeHelper(url, options)
121120
if (callback) {
122121
loadImage.transform(img, options, callback, file, {
123122
originalWidth: img.naturalWidth || img.width,

0 commit comments

Comments
 (0)