mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Render correct element
This commit is contained in:
parent
314d26f1f1
commit
5137e5f35a
@ -7,6 +7,8 @@
|
||||
|
||||
(function(window, document, undefined){
|
||||
|
||||
var html2canvasNodeAttribute = "data-html2canvas-node";
|
||||
|
||||
window.html2canvas = function(nodeList, options) {
|
||||
options = options || {};
|
||||
if (options.logging) {
|
||||
@ -17,7 +19,9 @@ window.html2canvas = function(nodeList, options) {
|
||||
options.async = typeof(options.async) === "undefined" ? true : options.async;
|
||||
options.removeContainer = typeof(options.removeContainer) === "undefined" ? true : options.removeContainer;
|
||||
|
||||
return renderDocument(document, options, window.innerWidth, window.innerHeight).then(function(canvas) {
|
||||
var node = ((nodeList === undefined) ? [document.documentElement] : ((nodeList.length) ? nodeList : [nodeList]))[0];
|
||||
node.setAttribute(html2canvasNodeAttribute, "true");
|
||||
return renderDocument(node.ownerDocument, options, window.innerWidth, window.innerHeight).then(function(canvas) {
|
||||
if (typeof(options.onrendered) === "function") {
|
||||
log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
|
||||
options.onrendered(canvas);
|
||||
@ -29,9 +33,10 @@ window.html2canvas = function(nodeList, options) {
|
||||
function renderDocument(document, options, windowWidth, windowHeight) {
|
||||
return createWindowClone(document, windowWidth, windowHeight, options).then(function(container) {
|
||||
log("Document cloned");
|
||||
var selector = "[" + html2canvasNodeAttribute + "='true']";
|
||||
document.querySelector(selector).removeAttribute(html2canvasNodeAttribute);
|
||||
var clonedWindow = container.contentWindow;
|
||||
//var element = (nodeList === undefined) ? document.body : nodeList[0];
|
||||
var node = clonedWindow.document.documentElement;
|
||||
var node = clonedWindow.document.querySelector(selector);
|
||||
var support = new Support();
|
||||
var imageLoader = new ImageLoader(options, support);
|
||||
var bounds = NodeParser.prototype.getBounds(node);
|
||||
@ -735,7 +740,7 @@ NodeParser.prototype.isBodyWithTransparentRoot = function(container) {
|
||||
};
|
||||
|
||||
NodeParser.prototype.isRootElement = function(container) {
|
||||
return container.node.nodeName === "HTML";
|
||||
return container.parent === null;
|
||||
};
|
||||
|
||||
NodeParser.prototype.sortStackingContexts = function(stack) {
|
||||
|
4
build/html2canvas.min.js
vendored
4
build/html2canvas.min.js
vendored
File diff suppressed because one or more lines are too long
11
src/core.js
11
src/core.js
@ -1,3 +1,5 @@
|
||||
var html2canvasNodeAttribute = "data-html2canvas-node";
|
||||
|
||||
window.html2canvas = function(nodeList, options) {
|
||||
options = options || {};
|
||||
if (options.logging) {
|
||||
@ -8,7 +10,9 @@ window.html2canvas = function(nodeList, options) {
|
||||
options.async = typeof(options.async) === "undefined" ? true : options.async;
|
||||
options.removeContainer = typeof(options.removeContainer) === "undefined" ? true : options.removeContainer;
|
||||
|
||||
return renderDocument(document, options, window.innerWidth, window.innerHeight).then(function(canvas) {
|
||||
var node = ((nodeList === undefined) ? [document.documentElement] : ((nodeList.length) ? nodeList : [nodeList]))[0];
|
||||
node.setAttribute(html2canvasNodeAttribute, "true");
|
||||
return renderDocument(node.ownerDocument, options, window.innerWidth, window.innerHeight).then(function(canvas) {
|
||||
if (typeof(options.onrendered) === "function") {
|
||||
log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
|
||||
options.onrendered(canvas);
|
||||
@ -20,9 +24,10 @@ window.html2canvas = function(nodeList, options) {
|
||||
function renderDocument(document, options, windowWidth, windowHeight) {
|
||||
return createWindowClone(document, windowWidth, windowHeight, options).then(function(container) {
|
||||
log("Document cloned");
|
||||
var selector = "[" + html2canvasNodeAttribute + "='true']";
|
||||
document.querySelector(selector).removeAttribute(html2canvasNodeAttribute);
|
||||
var clonedWindow = container.contentWindow;
|
||||
//var element = (nodeList === undefined) ? document.body : nodeList[0];
|
||||
var node = clonedWindow.document.documentElement;
|
||||
var node = clonedWindow.document.querySelector(selector);
|
||||
var support = new Support();
|
||||
var imageLoader = new ImageLoader(options, support);
|
||||
var bounds = NodeParser.prototype.getBounds(node);
|
||||
|
@ -149,7 +149,7 @@ NodeParser.prototype.isBodyWithTransparentRoot = function(container) {
|
||||
};
|
||||
|
||||
NodeParser.prototype.isRootElement = function(container) {
|
||||
return container.node.nodeName === "HTML";
|
||||
return container.parent === null;
|
||||
};
|
||||
|
||||
NodeParser.prototype.sortStackingContexts = function(stack) {
|
||||
|
@ -17,7 +17,7 @@ var h2cSelector, h2cOptions;
|
||||
document.write(srcStart + '/src/' + html2canvas[i] + '.js?' + Math.random() + scrEnd);
|
||||
}
|
||||
window.onload = function() {
|
||||
h2cSelector = [document.body];
|
||||
h2cSelector = [document.documentElement];
|
||||
|
||||
if (window.setUp) {
|
||||
window.setUp();
|
||||
|
Loading…
Reference in New Issue
Block a user