fix crash if an img tag has no src, fix undefined variables

This commit is contained in:
MoyuScript 2011-12-17 19:50:27 +01:00
parent a661952fc1
commit 553f84b51b

View File

@ -25,7 +25,8 @@ html2canvas.Preload = function(element, opts){
doc = element.ownerDocument, doc = element.ownerDocument,
domImages = doc.images, // TODO probably should limit it to images present in the element only domImages = doc.images, // TODO probably should limit it to images present in the element only
imgLen = domImages.length, imgLen = domImages.length,
link = doc.createElement("a"); link = doc.createElement("a"),
timeoutTimer;
link.href = window.location.href; link.href = window.location.href;
pageOrigin = link.protocol + link.host; pageOrigin = link.protocol + link.host;
@ -214,7 +215,7 @@ html2canvas.Preload = function(element, opts){
methods = { methods = {
loadImage: function( src ) { loadImage: function( src ) {
var img; var img;
if ( images[src] === undefined ) { if ( src && images[src] === undefined ) {
if ( src.match(/data:image\/.*;base64,/i) ) { if ( src.match(/data:image\/.*;base64,/i) ) {
//Base64 src //Base64 src
@ -257,7 +258,7 @@ html2canvas.Preload = function(element, opts){
}, },
cleanupDOM: function(cause) { cleanupDOM: function(cause) {
var img; var img, src;
if (!images.cleanupDone) { if (!images.cleanupDone) {
if (cause && typeof cause === "string") { if (cause && typeof cause === "string") {
html2canvas.log("html2canvas: Cleanup because: " + cause); html2canvas.log("html2canvas: Cleanup because: " + cause);
@ -320,10 +321,7 @@ html2canvas.Preload = function(element, opts){
this.log('html2canvas: Preload: Finding images'); this.log('html2canvas: Preload: Finding images');
// load <img> images // load <img> images
for (i = 0; i < imgLen; i+=1){ for (i = 0; i < imgLen; i+=1){
var imgSrc = domImages[i].getAttribute( "src" ); methods.loadImage( domImages[i].getAttribute( "src" ) );
if ( imgSrc ) {
methods.loadImage( imgSrc );
}
} }
images.firstRun = false; images.firstRun = false;