mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
bug fixes, and further simplification of API
This commit is contained in:
parent
c7d526c9ea
commit
cad3be2c66
11
src/Parse.js
11
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 = {},
|
||||
|
@ -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);
|
||||
}
|
||||
|
16
src/Util.js
16
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,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 ) {
|
||||
@ -53,7 +55,7 @@ html2canvas = function( elements, opts ) {
|
||||
}
|
||||
}
|
||||
|
||||
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 );
|
||||
_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
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user