initial support for multiple background images

Adding code from http://jsbin.com/ebigux/latest
This commit is contained in:
Andy Edinborough 2012-12-28 11:53:15 -06:00
parent fb0e7ca29d
commit 8fe61a43b0

View File

@ -94,6 +94,7 @@ _html2canvas.Preload = function( options ) {
var contents = _html2canvas.Util.Children(el), var contents = _html2canvas.Util.Children(el),
i, i,
background_image, background_image,
background_images,
src, src,
img, img,
elNodeType = false; elNodeType = false;
@ -122,34 +123,55 @@ _html2canvas.Preload = function( options ) {
}catch(e) { }catch(e) {
h2clog("html2canvas: failed to get background-image - Exception: " + e.message); h2clog("html2canvas: failed to get background-image - Exception: " + e.message);
} }
if ( background_image && background_image !== "1" && background_image !== "none" ) {
// TODO add multi image background support background_images = parseBackgroundImage(background_image);
while(!!(background_image = background_images.shift())) {
if (/^(-webkit|-o|-moz|-ms|linear)-/.test( background_image )) { if ( background_image.value && background_image.value !== "1" && background_image.value !== "none" ) {
if (/^(-webkit|-o|-moz|-ms|linear)-/.test( background_image.method )) {
img = _html2canvas.Generate.Gradient( background_image, _html2canvas.Util.Bounds( el ) ); img = _html2canvas.Generate.Gradient( background_image.value, _html2canvas.Util.Bounds( el ) );
if ( img !== undefined ){ if ( img !== undefined ){
images[background_image] = { images[background_image] = {
img: img, img: img,
succeeded: true succeeded: true
}; };
images.numTotal++; images.numTotal++;
images.numLoaded++; images.numLoaded++;
start(); start();
}
} else {
src = _html2canvas.Util.backgroundImage(background_image.definition);
methods.loadImage(src);
} }
} else {
src = _html2canvas.Util.backgroundImage(background_image.match(/data:image\/.*;base64,/i) ? background_image : background_image.split(",")[0]);
methods.loadImage(src);
} }
} }
} }
} }
function parseBackgroundImage(value) {
var rxBackgroundImage = /([a-z\-]+)\((("[^"]+)|([^)]+))\)/i,
match, results = [], n = 0;
if(!value) return results;
while(n++ < 100 && !!(match = value.match(rxBackgroundImage))) {
var def = match[2];
if(def.substr(0,1) === '"') {
def = def.substr(1, def.length-2);
}
results.push({
method: match[1],
definition: def,
value: match[0]
});
value = value.replace(match[0],'');
}
return results;
}
function setImageLoadHandlers(img, imageObj) { function setImageLoadHandlers(img, imageObj) {
img.onload = function() { img.onload = function() {
if ( imageObj.timer !== undefined ) { if ( imageObj.timer !== undefined ) {