don't process pseudo elements for hidden elements; cleanup pseudo elements after render

This commit is contained in:
Andy Edinborough 2013-01-11 10:46:53 -06:00
parent d73e53fbf0
commit 2b0db917e3
3 changed files with 26 additions and 10 deletions

View File

@ -14,6 +14,14 @@ function h2clog(a) {
_html2canvas.Util = {};
_html2canvas.Util.isElementVisible = function (element) {
return (
_html2canvas.Util.getCSS( element, 'display' ) !== "none" &&
_html2canvas.Util.getCSS( element, 'visibility' ) !== "hidden" &&
!element.hasAttribute( "data-html2canvas-ignore" )
);
};
_html2canvas.Util.trimText = (function(native){
return function(input){
if(native) { return native.apply( input ); }

View File

@ -170,7 +170,7 @@ _html2canvas.Parse = function (images, options) {
textList.forEach(function(word, index) {
if (/.*[\u4E00-\u9FA5].*$/.test(word)) {
word = word.split("");
word.unshift(index, 1)
word.unshift(index, 1);
textList.splice.apply(textList, word);
}
});

View File

@ -212,10 +212,12 @@ _html2canvas.Preload = function( options ) {
*/
}
var uid = 0, injectStyle;
function injectPseudoElements(el) {
if(!_html2canvas.Util.isElementVisible(el)) {
return;
}
var before = getPseudoElement(el, ':before'),
after = getPseudoElement(el, ':after');
if(!before && !after) {
@ -258,6 +260,17 @@ _html2canvas.Preload = function( options ) {
}
}
function cleanupPseudoElements(){
if(!injectStyle) {
return;
}
injectStyle.parentNode.removeChild(injectStyle);
injectStyle = undefined;
[].slice.apply(element.all || element.getElementsByTagName('*'))
.forEach(removePseudoElements);
}
function getPseudoElement(el, which) {
var elStyle = window.getComputedStyle(el, which);
if(!elStyle || !elStyle.content) { return; }
@ -380,19 +393,14 @@ _html2canvas.Preload = function( options ) {
}
}
if(injectStyle) {
injectStyle.parentNode.removeChild(injectStyle);
injectStyle = undefined;
[].slice.apply(element.all || element.getElementsByTagName('*'))
.forEach(removePseudoElements);
}
cleanupPseudoElements();
},
renderingDone: function() {
if (timeoutTimer) {
window.clearTimeout(timeoutTimer);
}
cleanupPseudoElements();
}
};