mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Fix #503
This commit is contained in:
parent
db88784655
commit
399ae9f33d
22
dist/html2canvas.js
vendored
22
dist/html2canvas.js
vendored
@ -690,10 +690,28 @@ function smallImage() {
|
|||||||
return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isIE9() {
|
||||||
|
return document.documentMode && document.documentMode <= 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cloneNodeIE9(node, javascriptEnabled) {
|
||||||
|
var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
|
||||||
|
|
||||||
|
var child = node.firstChild;
|
||||||
|
while(child) {
|
||||||
|
if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') {
|
||||||
|
clone.appendChild(cloneNodeIE9(child, javascriptEnabled));
|
||||||
|
}
|
||||||
|
child = child.nextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
function createWindowClone(ownerDocument, containerDocument, width, height, options, x ,y) {
|
function createWindowClone(ownerDocument, containerDocument, width, height, options, x ,y) {
|
||||||
labelCanvasElements(ownerDocument);
|
labelCanvasElements(ownerDocument);
|
||||||
var documentElement = ownerDocument.documentElement.cloneNode(true),
|
var documentElement = isIE9() ? cloneNodeIE9(ownerDocument.documentElement, options.javascriptEnabled) : ownerDocument.documentElement.cloneNode(true);
|
||||||
container = containerDocument.createElement("iframe");
|
var container = containerDocument.createElement("iframe");
|
||||||
|
|
||||||
container.className = "html2canvas-container";
|
container.className = "html2canvas-container";
|
||||||
container.style.visibility = "hidden";
|
container.style.visibility = "hidden";
|
||||||
|
4
dist/html2canvas.min.js
vendored
4
dist/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
22
src/core.js
22
src/core.js
@ -126,10 +126,28 @@ function smallImage() {
|
|||||||
return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
return "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isIE9() {
|
||||||
|
return document.documentMode && document.documentMode <= 9;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cloneNodeIE9(node, javascriptEnabled) {
|
||||||
|
var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
|
||||||
|
|
||||||
|
var child = node.firstChild;
|
||||||
|
while(child) {
|
||||||
|
if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') {
|
||||||
|
clone.appendChild(cloneNodeIE9(child, javascriptEnabled));
|
||||||
|
}
|
||||||
|
child = child.nextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clone;
|
||||||
|
}
|
||||||
|
|
||||||
function createWindowClone(ownerDocument, containerDocument, width, height, options, x ,y) {
|
function createWindowClone(ownerDocument, containerDocument, width, height, options, x ,y) {
|
||||||
labelCanvasElements(ownerDocument);
|
labelCanvasElements(ownerDocument);
|
||||||
var documentElement = ownerDocument.documentElement.cloneNode(true),
|
var documentElement = isIE9() ? cloneNodeIE9(ownerDocument.documentElement, options.javascriptEnabled) : ownerDocument.documentElement.cloneNode(true);
|
||||||
container = containerDocument.createElement("iframe");
|
var container = containerDocument.createElement("iframe");
|
||||||
|
|
||||||
container.className = "html2canvas-container";
|
container.className = "html2canvas-container";
|
||||||
container.style.visibility = "hidden";
|
container.style.visibility = "hidden";
|
||||||
|
1
tests/mocha/clone.js
Normal file
1
tests/mocha/clone.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
document.querySelector("#block").className += "class";
|
66
tests/mocha/ie9-clonenode-bug.html
Normal file
66
tests/mocha/ie9-clonenode-bug.html
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head lang="en">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Proxy tests</title>
|
||||||
|
<link rel="stylesheet" href="lib/mocha.css" />
|
||||||
|
<script src="../assets/jquery-1.6.2.js"></script>
|
||||||
|
<script src="lib/expect.js"></script>
|
||||||
|
<script src="lib/mocha.js"></script>
|
||||||
|
<style>
|
||||||
|
#block {
|
||||||
|
background: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
#block.class {
|
||||||
|
background: green;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div style="width: 200px; height:200px;" id="block"></div>
|
||||||
|
<script src="../../dist/html2canvas.js"></script>
|
||||||
|
<script src="clone.js"></script>
|
||||||
|
<div id="mocha"></div>
|
||||||
|
<script>mocha.setup('bdd')</script>
|
||||||
|
<script>
|
||||||
|
// https://github.com/niklasvh/html2canvas/issues/503
|
||||||
|
describe("Document clone should not re-execute javascript", function() {
|
||||||
|
it("with mutating className", function (done) {
|
||||||
|
this.timeout(10000);
|
||||||
|
html2canvas(document.querySelector("#block")).then(function (canvas) {
|
||||||
|
expect(canvas.width).to.equal(200);
|
||||||
|
expect(canvas.height).to.equal(200);
|
||||||
|
validCanvasPixels(canvas);
|
||||||
|
done();
|
||||||
|
}).catch(function (error) {
|
||||||
|
done(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
function validCanvasPixels(canvas) {
|
||||||
|
var ctx = canvas.getContext("2d");
|
||||||
|
var data = ctx.getImageData(0, 0, canvas.width, canvas.height).data;
|
||||||
|
for (var i = 0, len = data.length; i < len; i+=4) {
|
||||||
|
if (data[i] !== 0 || data[i+1] !== 128 || data[i+2] !== 0 || data[i+3] !== 255) {
|
||||||
|
expect().fail("Invalid canvas data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
mocha.checkLeaks();
|
||||||
|
mocha.globals(['jQuery']);
|
||||||
|
if (window.mochaPhantomJS) {
|
||||||
|
mochaPhantomJS.run();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
mocha.run();
|
||||||
|
}
|
||||||
|
mocha.suite.afterAll(function() {
|
||||||
|
document.body.setAttribute('data-complete', 'true');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user