Permalink
Browse files

bug fixes, and further simplification of API

  • Loading branch information...
1 parent c7d526c commit cad3be2c6637534f46b59a5193ffd71cad1bdfcb @niklasvh committed Mar 2, 2012
Showing with 20 additions and 32 deletions.
  1. +2 −9 src/Parse.js
  2. +3 −9 src/Preload.js
  3. +1 −1 src/Renderer.js
  4. +13 −11 src/Util.js
  5. +1 −2 src/plugins/jquery.plugin.html2canvas.js
View
@@ -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 = {},
View
@@ -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);
}
View
@@ -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
View
@@ -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
};
@@ -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);

0 comments on commit cad3be2

Please sign in to comment.