77
88( function ( window , document , undefined ) {
99
10+ var html2canvasNodeAttribute = "data-html2canvas-node" ;
11+
1012window . html2canvas = function ( nodeList , options ) {
1113 options = options || { } ;
1214 if ( options . logging ) {
@@ -17,7 +19,9 @@ window.html2canvas = function(nodeList, options) {
1719 options . async = typeof ( options . async ) === "undefined" ? true : options . async ;
1820 options . removeContainer = typeof ( options . removeContainer ) === "undefined" ? true : options . removeContainer ;
1921
20- return renderDocument ( document , options , window . innerWidth , window . innerHeight ) . then ( function ( canvas ) {
22+ var node = ( ( nodeList === undefined ) ? [ document . documentElement ] : ( ( nodeList . length ) ? nodeList : [ nodeList ] ) ) [ 0 ] ;
23+ node . setAttribute ( html2canvasNodeAttribute , "true" ) ;
24+ return renderDocument ( node . ownerDocument , options , window . innerWidth , window . innerHeight ) . then ( function ( canvas ) {
2125 if ( typeof ( options . onrendered ) === "function" ) {
2226 log ( "options.onrendered is deprecated, html2canvas returns a Promise containing the canvas" ) ;
2327 options . onrendered ( canvas ) ;
@@ -29,9 +33,10 @@ window.html2canvas = function(nodeList, options) {
2933function renderDocument ( document , options , windowWidth , windowHeight ) {
3034 return createWindowClone ( document , windowWidth , windowHeight , options ) . then ( function ( container ) {
3135 log ( "Document cloned" ) ;
36+ var selector = "[" + html2canvasNodeAttribute + "='true']" ;
37+ document . querySelector ( selector ) . removeAttribute ( html2canvasNodeAttribute ) ;
3238 var clonedWindow = container . contentWindow ;
33- //var element = (nodeList === undefined) ? document.body : nodeList[0];
34- var node = clonedWindow . document . documentElement ;
39+ var node = clonedWindow . document . querySelector ( selector ) ;
3540 var support = new Support ( ) ;
3641 var imageLoader = new ImageLoader ( options , support ) ;
3742 var bounds = NodeParser . prototype . getBounds ( node ) ;
@@ -735,7 +740,7 @@ NodeParser.prototype.isBodyWithTransparentRoot = function(container) {
735740} ;
736741
737742NodeParser . prototype . isRootElement = function ( container ) {
738- return container . node . nodeName === "HTML" ;
743+ return container . parent === null ;
739744} ;
740745
741746NodeParser . prototype . sortStackingContexts = function ( stack ) {
0 commit comments