diff --git a/src/Parse.js b/src/Parse.js index c5e3745..114afff 100644 --- a/src/Parse.js +++ b/src/Parse.js @@ -10,20 +10,13 @@ * New function for traversing elements */ -_html2canvas.Parse = function (element, images, options) { +_html2canvas.Parse = function ( images, options ) { window.scroll(0,0); - // select body by default - if (element === undefined) { - element = document.body; - } - - var support = { rangeBounds: false - }, - + element = (( options.elements === undefined ) ? document.body : options.elements[0]), // select body by default needReorder = false, numDraws = 0, fontData = {}, diff --git a/src/Preload.js b/src/Preload.js index 905ff4a..9ab1904 100644 --- a/src/Preload.js +++ b/src/Preload.js @@ -6,7 +6,7 @@ Released under MIT License */ -_html2canvas.Preload = function(element, options){ +_html2canvas.Preload = function( options ) { var images = { numLoaded: 0, // also failed are counted here @@ -18,6 +18,7 @@ _html2canvas.Preload = function(element, options){ methods, i, count = 0, + element = options.elements[0] || document.body, doc = element.ownerDocument, domImages = doc.images, // TODO probably should limit it to images present in the element only imgLen = domImages.length, @@ -35,8 +36,6 @@ _html2canvas.Preload = function(element, options){ - element = element || doc.body; - function isSameOrigin(url){ link.href = url; link.href = link.href; // YES, BELIEVE IT OR NOT, that is required for IE9 - http://jsfiddle.net/niklasvh/2e48b/ @@ -47,12 +46,7 @@ _html2canvas.Preload = function(element, options){ function start(){ h2clog("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")"); if (!images.firstRun && images.numLoaded >= images.numTotal){ - - /* - this.log('Finished loading '+this.imagesLoaded+' images, Started parsing'); - this.bodyOverflow = document.getElementsByTagName('body')[0].style.overflow; - document.getElementsByTagName('body')[0].style.overflow = "hidden"; - */ + if (typeof options.complete === "function"){ options.complete(images); } diff --git a/src/Renderer.js b/src/Renderer.js index e3fe243..eaf4422 100644 --- a/src/Renderer.js +++ b/src/Renderer.js @@ -174,7 +174,7 @@ _html2canvas.Renderer = function(parseQueue, options){ // this.canvasRenderStorage(queue,this.ctx); queueLen = options.elements.length; - + if (queueLen === 1) { if (typeof options.elements[ 0 ] === "object" && options.elements[ 0 ].nodeName !== "BODY" && usingFlashcanvas === false) { // crop image to the bounds of selected (single) element diff --git a/src/Util.js b/src/Util.js index 18b328d..2c22d5f 100644 --- a/src/Util.js +++ b/src/Util.js @@ -14,6 +14,7 @@ html2canvas = function( elements, opts ) { options = { // general logging: false, + elements: elements, // preload options proxy: "http://html2canvas.appspot.com/", @@ -40,20 +41,21 @@ html2canvas = function( elements, opts ) { _html2canvas.logging = options.logging; options.complete = function( images ) { + if (typeof options.onpreloaded === "function") { if ( options.onpreloaded( images ) === false ) { return; } } - queue = _html2canvas.Parse( elements, images, options); + queue = _html2canvas.Parse( images, options ); if (typeof options.onparsed === "function") { if ( options.onparsed( queue ) === false ) { return; } } - - canvas = _html2canvas.Renderer(queue, options); + + canvas = _html2canvas.Renderer( queue, options ); if (typeof options.onrendered === "function") { options.onrendered( canvas ); @@ -64,18 +66,18 @@ html2canvas = function( elements, opts ) { // for pages without images, we still want this to be async, i.e. return methods before executing window.setTimeout( function(){ - _html2canvas.Preload( elements, options ); - }, 0 ); - + _html2canvas.Preload( options ); + }, 0 ); + return { render: function( queue, opts ) { - return _html2canvas.Renderer( queue, _html2canvas.Util.Extend(opts, options) ); + return _html2canvas.Renderer( queue, _html2canvas.Util.Extend(opts, options) ); }, - parse: function( elements, images, opts ) { - return _html2canvas.Parse( elements, images, _html2canvas.Util.Extend(opts, options) ); + parse: function( images, opts ) { + return _html2canvas.Parse( images, _html2canvas.Util.Extend(opts, options) ); }, - preload: function( elements, opts ) { - return _html2canvas.Preload( elements, _html2canvas.Util.Extend(opts, options) ); + preload: function( opts ) { + return _html2canvas.Preload( _html2canvas.Util.Extend(opts, options) ); }, log: h2clog }; diff --git a/src/plugins/jquery.plugin.html2canvas.js b/src/plugins/jquery.plugin.html2canvas.js index b6a6378..9ac1c50 100644 --- a/src/plugins/jquery.plugin.html2canvas.js +++ b/src/plugins/jquery.plugin.html2canvas.js @@ -12,7 +12,6 @@ timeoutTimer = false, timer = date.getTime(); options = options || {}; - options.elements = this; options.onrendered = function( canvas ) { var $canvas = $(canvas), @@ -45,7 +44,7 @@ } }; - html2obj = html2canvas(this[0], options); + html2obj = html2canvas(this, options); function throwMessage(msg,duration){ window.clearTimeout(timeoutTimer);