Fix empty content getting rendered on firefox/IE

This commit is contained in:
Niklas von Hertzen 2013-01-11 19:31:05 +02:00
parent 2b0db917e3
commit 3032dc6ce0

View File

@ -129,9 +129,9 @@ _html2canvas.Preload = function( options ) {
for(var imageIndex = background_images.length; imageIndex-- > 0;) { for(var imageIndex = background_images.length; imageIndex-- > 0;) {
background_image = background_images[imageIndex]; background_image = background_images[imageIndex];
if(!background_image || if(!background_image ||
!background_image.method || !background_image.method ||
!background_image.args || !background_image.args ||
background_image.args.length === 0 ) { background_image.args.length === 0 ) {
continue; continue;
} }
@ -223,7 +223,7 @@ _html2canvas.Preload = function( options ) {
if(!before && !after) { if(!before && !after) {
return; return;
} }
if(!el.id) { if(!el.id) {
el.id = '__html2canvas__' + (uid++); el.id = '__html2canvas__' + (uid++);
} }
if(!injectStyle) { if(!injectStyle) {
@ -261,8 +261,8 @@ _html2canvas.Preload = function( options ) {
} }
function cleanupPseudoElements(){ function cleanupPseudoElements(){
if(!injectStyle) { if(!injectStyle) {
return; return;
} }
injectStyle.parentNode.removeChild(injectStyle); injectStyle.parentNode.removeChild(injectStyle);
injectStyle = undefined; injectStyle = undefined;
@ -271,11 +271,14 @@ _html2canvas.Preload = function( options ) {
.forEach(removePseudoElements); .forEach(removePseudoElements);
} }
function indexedProperty(property) {
return (!isNaN(window.parseInt(property, 10)));
}
function getPseudoElement(el, which) { function getPseudoElement(el, which) {
var elStyle = window.getComputedStyle(el, which); var elStyle = window.getComputedStyle(el, which);
if(!elStyle || !elStyle.content) { return; } if(!elStyle || !elStyle.content || elStyle.content === "none") { return; }
var content = elStyle.content + '',
var content = elStyle.content + '',
first = content.substr( 0, 1 ); first = content.substr( 0, 1 );
//strips quotes //strips quotes
if(first === content.substr( content.length - 1 ) && first.match(/'|"/)) { if(first === content.substr( content.length - 1 ) && first.match(/'|"/)) {
@ -286,9 +289,7 @@ _html2canvas.Preload = function( options ) {
elps = document.createElement( isImage ? 'img' : 'span' ); elps = document.createElement( isImage ? 'img' : 'span' );
elps.className = '__html2canvas__' + which.substr(1); elps.className = '__html2canvas__' + which.substr(1);
Object.keys(elStyle).forEach(function(prop) { Object.keys(elStyle).filter(indexedProperty).forEach(function(prop) {
//skip indexed properties
if(!isNaN(parseInt(prop, 10))) { return; }
elps.style[prop] = elStyle[prop]; elps.style[prop] = elStyle[prop];
}); });
if(isImage) { if(isImage) {