bug fixes, and further simplification of API

This commit is contained in:
Niklas von Hertzen 2012-03-02 19:07:15 +02:00
parent c7d526c9ea
commit cad3be2c66
5 changed files with 20 additions and 32 deletions

View File

@ -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 File

@ -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/
@ -48,11 +47,6 @@ _html2canvas.Preload = function(element, options){
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 File

@ -14,6 +14,7 @@ html2canvas = function( elements, opts ) {
options = {
// general
logging: false,
elements: elements,
// preload options
proxy: "http://html2canvas.appspot.com/",
@ -40,12 +41,13 @@ 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 ) {
@ -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 );
_html2canvas.Preload( options );
}, 0 );
return {
render: function( queue, opts ) {
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
};

View File

@ -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);