Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Commit

Permalink
Fix querySelectorAll fail on chrome when class list have empty string…
Browse files Browse the repository at this point in the history
… item
  • Loading branch information
tansautn committed Nov 7, 2017
1 parent 84284cc commit 9f81274
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
23 changes: 8 additions & 15 deletions build/html2canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,23 +1114,25 @@ _html2canvas.Parse = function (images, options, cb) {
function getPseudoElementClasses(){
var findPsuedoEls = /:before|:after/;
var sheets = document.styleSheets;
// Don't push empty or all-space string item
var regEx = /^(\s)*$/;
for (var i = 0, j = sheets.length; i < j; i++) {
try {
var rules = sheets[i].cssRules;
for (var k = 0, l = rules.length; k < l; k++) {
if(findPsuedoEls.test(rules[k].selectorText)) {
classes.push(rules[k].selectorText);
// Trim off the :after and :before (or ::after and ::before)
// We don't need two loop for this
var removed = rules[k].selectorText.match(/(^[^:]*)/)[1];
if(!regEx.test(removed)){
classes.push(removed);
}
}
}
}
catch(e) { // will throw security exception for style sheets loaded from external domains
}
}

// Trim off the :after and :before (or ::after and ::before)
for (i = 0, j = classes.length; i < j; i++) {
classes[i] = classes[i].match(/(^[^:]*)/)[1];
}
}

// Using the list of elements we know how pseudo el styles, create fake pseudo elements.
Expand Down Expand Up @@ -1212,15 +1214,6 @@ _html2canvas.Parse = function (images, options, cb) {
}
}

function hasClass (el, className) {
return el.className.indexOf(className) > -1;
}

// Note that this doesn't work in < IE8, but we don't support that anyhow
function nodeListToArray (nodeList) {
return Array.prototype.slice.call(nodeList);
}

function documentWidth () {
return Math.max(
Math.max(doc.body.scrollWidth, doc.documentElement.scrollWidth),
Expand Down
Loading

0 comments on commit 9f81274

Please sign in to comment.