Skip to content

Commit b24c43b

Browse files
committed
Fixed file loading on browsers supporting the File API but not Blobs (e.g. Firefox 3.6).
1 parent 19c8e8c commit b24c43b

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

load-image.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* JavaScript Load Image 1.1.3
2+
* JavaScript Load Image 1.1.4
33
* https://github.com/blueimp/JavaScript-Load-Image
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -10,7 +10,7 @@
1010
*/
1111

1212
/*jslint nomen: true */
13-
/*global window, document, URL, webkitURL, Blob, FileReader, define */
13+
/*global window, document, URL, webkitURL, Blob, File, FileReader, define */
1414

1515
(function ($) {
1616
'use strict';
@@ -21,20 +21,22 @@
2121
var loadImage = function (file, callback, options) {
2222
var img = document.createElement('img'),
2323
url,
24-
isFile;
25-
if (window.Blob && file instanceof Blob) {
26-
url = loadImage.createObjectURL(file);
27-
isFile = true;
28-
} else {
29-
url = file;
30-
}
24+
oUrl;
3125
img.onerror = callback;
3226
img.onload = function () {
33-
if (isFile) {
34-
loadImage.revokeObjectURL(url);
27+
if (oUrl) {
28+
loadImage.revokeObjectURL(oUrl);
3529
}
3630
callback(loadImage.scale(img, options));
3731
};
32+
if ((window.Blob && file instanceof Blob) ||
33+
// Files are also Blob instances, but some browsers
34+
// (Firefox 3.6) support the File API but not Blobs:
35+
(window.File && file instanceof File)) {
36+
url = oUrl = loadImage.createObjectURL(file);
37+
} else {
38+
url = file;
39+
}
3840
if (url) {
3941
img.src = url;
4042
return img;

load-image.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "blueimp-load-image",
3-
"version": "1.1.3",
3+
"version": "1.1.4",
44
"title": "JavaScript Load Image",
55
"description": "JavaScript Load Image is a function to load images provided as File or Blob objects or via URL. It returns an optionally scaled HTML img or canvas element.",
66
"keywords": [

0 commit comments

Comments
 (0)