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
|
* New function for traversing elements
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_html2canvas.Parse = function (element, images, options) {
|
_html2canvas.Parse = function ( images, options ) {
|
||||||
window.scroll(0,0);
|
window.scroll(0,0);
|
||||||
|
|
||||||
// select body by default
|
|
||||||
if (element === undefined) {
|
|
||||||
element = document.body;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var support = {
|
var support = {
|
||||||
rangeBounds: false
|
rangeBounds: false
|
||||||
|
|
||||||
},
|
},
|
||||||
|
element = (( options.elements === undefined ) ? document.body : options.elements[0]), // select body by default
|
||||||
needReorder = false,
|
needReorder = false,
|
||||||
numDraws = 0,
|
numDraws = 0,
|
||||||
fontData = {},
|
fontData = {},
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
Released under MIT License
|
Released under MIT License
|
||||||
*/
|
*/
|
||||||
|
|
||||||
_html2canvas.Preload = function(element, options){
|
_html2canvas.Preload = function( options ) {
|
||||||
|
|
||||||
var images = {
|
var images = {
|
||||||
numLoaded: 0, // also failed are counted here
|
numLoaded: 0, // also failed are counted here
|
||||||
@ -18,6 +18,7 @@ _html2canvas.Preload = function(element, options){
|
|||||||
methods,
|
methods,
|
||||||
i,
|
i,
|
||||||
count = 0,
|
count = 0,
|
||||||
|
element = options.elements[0] || document.body,
|
||||||
doc = element.ownerDocument,
|
doc = element.ownerDocument,
|
||||||
domImages = doc.images, // TODO probably should limit it to images present in the element only
|
domImages = doc.images, // TODO probably should limit it to images present in the element only
|
||||||
imgLen = domImages.length,
|
imgLen = domImages.length,
|
||||||
@ -35,8 +36,6 @@ _html2canvas.Preload = function(element, options){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
element = element || doc.body;
|
|
||||||
|
|
||||||
function isSameOrigin(url){
|
function isSameOrigin(url){
|
||||||
link.href = url;
|
link.href = url;
|
||||||
link.href = link.href; // YES, BELIEVE IT OR NOT, that is required for IE9 - http://jsfiddle.net/niklasvh/2e48b/
|
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(){
|
function start(){
|
||||||
h2clog("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
|
h2clog("html2canvas: start: images: " + images.numLoaded + " / " + images.numTotal + " (failed: " + images.numFailed + ")");
|
||||||
if (!images.firstRun && images.numLoaded >= images.numTotal){
|
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"){
|
if (typeof options.complete === "function"){
|
||||||
options.complete(images);
|
options.complete(images);
|
||||||
}
|
}
|
||||||
|
@ -174,7 +174,7 @@ _html2canvas.Renderer = function(parseQueue, options){
|
|||||||
|
|
||||||
// this.canvasRenderStorage(queue,this.ctx);
|
// this.canvasRenderStorage(queue,this.ctx);
|
||||||
queueLen = options.elements.length;
|
queueLen = options.elements.length;
|
||||||
|
|
||||||
if (queueLen === 1) {
|
if (queueLen === 1) {
|
||||||
if (typeof options.elements[ 0 ] === "object" && options.elements[ 0 ].nodeName !== "BODY" && usingFlashcanvas === false) {
|
if (typeof options.elements[ 0 ] === "object" && options.elements[ 0 ].nodeName !== "BODY" && usingFlashcanvas === false) {
|
||||||
// crop image to the bounds of selected (single) element
|
// crop image to the bounds of selected (single) element
|
||||||
|
24
src/Util.js
24
src/Util.js
@ -14,6 +14,7 @@ html2canvas = function( elements, opts ) {
|
|||||||
options = {
|
options = {
|
||||||
// general
|
// general
|
||||||
logging: false,
|
logging: false,
|
||||||
|
elements: elements,
|
||||||
|
|
||||||
// preload options
|
// preload options
|
||||||
proxy: "http://html2canvas.appspot.com/",
|
proxy: "http://html2canvas.appspot.com/",
|
||||||
@ -40,20 +41,21 @@ html2canvas = function( elements, opts ) {
|
|||||||
|
|
||||||
_html2canvas.logging = options.logging;
|
_html2canvas.logging = options.logging;
|
||||||
options.complete = function( images ) {
|
options.complete = function( images ) {
|
||||||
|
|
||||||
if (typeof options.onpreloaded === "function") {
|
if (typeof options.onpreloaded === "function") {
|
||||||
if ( options.onpreloaded( images ) === false ) {
|
if ( options.onpreloaded( images ) === false ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queue = _html2canvas.Parse( elements, images, options);
|
queue = _html2canvas.Parse( images, options );
|
||||||
|
|
||||||
if (typeof options.onparsed === "function") {
|
if (typeof options.onparsed === "function") {
|
||||||
if ( options.onparsed( queue ) === false ) {
|
if ( options.onparsed( queue ) === false ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
canvas = _html2canvas.Renderer(queue, options);
|
canvas = _html2canvas.Renderer( queue, options );
|
||||||
|
|
||||||
if (typeof options.onrendered === "function") {
|
if (typeof options.onrendered === "function") {
|
||||||
options.onrendered( canvas );
|
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
|
// for pages without images, we still want this to be async, i.e. return methods before executing
|
||||||
window.setTimeout( function(){
|
window.setTimeout( function(){
|
||||||
_html2canvas.Preload( elements, options );
|
_html2canvas.Preload( options );
|
||||||
}, 0 );
|
}, 0 );
|
||||||
|
|
||||||
return {
|
return {
|
||||||
render: function( queue, opts ) {
|
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 ) {
|
parse: function( images, opts ) {
|
||||||
return _html2canvas.Parse( elements, images, _html2canvas.Util.Extend(opts, options) );
|
return _html2canvas.Parse( images, _html2canvas.Util.Extend(opts, options) );
|
||||||
},
|
},
|
||||||
preload: function( elements, opts ) {
|
preload: function( opts ) {
|
||||||
return _html2canvas.Preload( elements, _html2canvas.Util.Extend(opts, options) );
|
return _html2canvas.Preload( _html2canvas.Util.Extend(opts, options) );
|
||||||
},
|
},
|
||||||
log: h2clog
|
log: h2clog
|
||||||
};
|
};
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
timeoutTimer = false,
|
timeoutTimer = false,
|
||||||
timer = date.getTime();
|
timer = date.getTime();
|
||||||
options = options || {};
|
options = options || {};
|
||||||
options.elements = this;
|
|
||||||
|
|
||||||
options.onrendered = function( canvas ) {
|
options.onrendered = function( canvas ) {
|
||||||
var $canvas = $(canvas),
|
var $canvas = $(canvas),
|
||||||
@ -45,7 +44,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
html2obj = html2canvas(this[0], options);
|
html2obj = html2canvas(this, options);
|
||||||
|
|
||||||
function throwMessage(msg,duration){
|
function throwMessage(msg,duration){
|
||||||
window.clearTimeout(timeoutTimer);
|
window.clearTimeout(timeoutTimer);
|
||||||
|
Loading…
Reference in New Issue
Block a user