mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
don't process pseudo elements for hidden elements; cleanup pseudo elements after render
This commit is contained in:
parent
d3189b8c79
commit
521b190b22
@ -14,6 +14,14 @@ function h2clog(a) {
|
|||||||
|
|
||||||
_html2canvas.Util = {};
|
_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){
|
_html2canvas.Util.trimText = (function(native){
|
||||||
return function(input){
|
return function(input){
|
||||||
if(native) { return native.apply( input ); }
|
if(native) { return native.apply( input ); }
|
||||||
|
@ -170,7 +170,7 @@ _html2canvas.Parse = function (images, options) {
|
|||||||
textList.forEach(function(word, index) {
|
textList.forEach(function(word, index) {
|
||||||
if (/.*[\u4E00-\u9FA5].*$/.test(word)) {
|
if (/.*[\u4E00-\u9FA5].*$/.test(word)) {
|
||||||
word = word.split("");
|
word = word.split("");
|
||||||
word.unshift(index, 1)
|
word.unshift(index, 1);
|
||||||
textList.splice.apply(textList, word);
|
textList.splice.apply(textList, word);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -212,10 +212,12 @@ _html2canvas.Preload = function( options ) {
|
|||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var uid = 0, injectStyle;
|
var uid = 0, injectStyle;
|
||||||
function injectPseudoElements(el) {
|
function injectPseudoElements(el) {
|
||||||
|
if(!_html2canvas.Util.isElementVisible(el)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var before = getPseudoElement(el, ':before'),
|
var before = getPseudoElement(el, ':before'),
|
||||||
after = getPseudoElement(el, ':after');
|
after = getPseudoElement(el, ':after');
|
||||||
if(!before && !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) {
|
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) { return; }
|
||||||
@ -380,19 +393,14 @@ _html2canvas.Preload = function( options ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(injectStyle) {
|
cleanupPseudoElements();
|
||||||
injectStyle.parentNode.removeChild(injectStyle);
|
|
||||||
injectStyle = undefined;
|
|
||||||
|
|
||||||
[].slice.apply(element.all || element.getElementsByTagName('*'))
|
|
||||||
.forEach(removePseudoElements);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
renderingDone: function() {
|
renderingDone: function() {
|
||||||
if (timeoutTimer) {
|
if (timeoutTimer) {
|
||||||
window.clearTimeout(timeoutTimer);
|
window.clearTimeout(timeoutTimer);
|
||||||
}
|
}
|
||||||
|
cleanupPseudoElements();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user