mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
rewrote image handling from using an array to an object
The image loading done in Preload.js used an array to store image src and image object as 2 consecutive entries in that array. Using the src as an index in a hash allows direct instead of a linear search and also allows to store more data. * improved cleanup of images loaded with the proxy * this also adds a timeout for the image loading phase, after that running image requests are aborted and the rendering is started
This commit is contained in:
38
src/Parse.js
38
src/Parse.js
@ -48,7 +48,7 @@ html2canvas.Parse = function (element, images, opts) {
|
||||
childrenLen;
|
||||
|
||||
|
||||
images = images || [];
|
||||
images = images || {};
|
||||
|
||||
// Test whether we can use ranges to measure bounding boxes
|
||||
// Opera doesn't provide valid bounds.height/bottom even though it supports the method.
|
||||
@ -514,28 +514,13 @@ html2canvas.Parse = function (element, images, opts) {
|
||||
|
||||
}
|
||||
|
||||
function loadImage (src){
|
||||
|
||||
var imgIndex = -1,
|
||||
i,
|
||||
imgLen;
|
||||
if (images.indexOf){
|
||||
imgIndex = images.indexOf(src);
|
||||
}else{
|
||||
for(i = 0, imgLen = images.length; i < imgLen.length; i+=1){
|
||||
if(images[i] === src) {
|
||||
imgIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (imgIndex > -1){
|
||||
return images[imgIndex+1];
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
function loadImage (src){
|
||||
var img = images[src];
|
||||
if (img && img.succeeded === true) {
|
||||
return img.img;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1004,8 +989,7 @@ html2canvas.Parse = function (element, images, opts) {
|
||||
|
||||
}
|
||||
}else{
|
||||
|
||||
html2canvas.log("Error loading background:" + background_image);
|
||||
html2canvas.log("html2canvas: Error loading background:" + background_image);
|
||||
//console.log(images);
|
||||
}
|
||||
|
||||
@ -1164,8 +1148,8 @@ html2canvas.Parse = function (element, images, opts) {
|
||||
bounds.height - (borders[0].width + borders[2].width + paddingTop + paddingBottom) //dh
|
||||
);
|
||||
|
||||
}else {
|
||||
html2canvas.log("Error loading <img>:" + imgSrc);
|
||||
}else{
|
||||
html2canvas.log("html2canvas: Error loading <img>:" + imgSrc);
|
||||
}
|
||||
break;
|
||||
case "INPUT":
|
||||
|
Reference in New Issue
Block a user