html2canvas/src/Util.js

80 lines
2.1 KiB
JavaScript
Raw Normal View History

2012-12-29 19:43:15 +04:00
window.html2canvas = function(elements, opts) {
2012-11-25 22:59:31 +04:00
var queue,
canvas,
options = {
// general
logging: false,
elements: elements,
2013-01-04 01:15:06 +04:00
background: "#fff",
2012-11-25 22:59:31 +04:00
// preload options
2012-12-29 19:43:15 +04:00
proxy: "",
2012-11-25 22:59:31 +04:00
timeout: 0, // no timeout
useCORS: false, // try to load images as CORS (where available), before falling back to proxy
allowTaint: false, // whether to allow images to taint the canvas, won't need proxy if set to true
// parse options
svgRendering: false, // use svg powered rendering where available (FF11+)
ignoreElements: "IFRAME|OBJECT|PARAM",
useOverflow: true,
letterRendering: false,
2013-01-05 01:47:59 +04:00
chinese: false,
2012-11-25 22:59:31 +04:00
// render options
width: null,
height: null,
taintTest: true, // do a taint test with all images before applying to canvas
renderer: "Canvas"
2012-12-29 19:43:15 +04:00
};
2012-11-25 22:59:31 +04:00
options = _html2canvas.Util.Extend(opts, options);
_html2canvas.logging = options.logging;
options.complete = function( images ) {
if (typeof options.onpreloaded === "function") {
if ( options.onpreloaded( images ) === false ) {
return;
}
}
queue = _html2canvas.Parse( images, options );
if (typeof options.onparsed === "function") {
if ( options.onparsed( queue ) === false ) {
return;
}
}
canvas = _html2canvas.Renderer( queue, options );
if (typeof options.onrendered === "function") {
options.onrendered( canvas );
}
};
// for pages without images, we still want this to be async, i.e. return methods before executing
window.setTimeout( function(){
_html2canvas.Preload( options );
}, 0 );
return {
render: function( queue, opts ) {
return _html2canvas.Renderer( queue, _html2canvas.Util.Extend(opts, options) );
},
parse: function( images, opts ) {
return _html2canvas.Parse( images, _html2canvas.Util.Extend(opts, options) );
},
preload: function( opts ) {
return _html2canvas.Preload( _html2canvas.Util.Extend(opts, options) );
},
log: h2clog
};
2012-03-02 20:05:03 +04:00
};
2012-03-02 22:35:48 +04:00
2012-12-29 19:43:15 +04:00
window.html2canvas.log = h2clog; // for renderers
window.html2canvas.Renderer = {
2012-11-25 22:59:31 +04:00
Canvas: undefined // We are assuming this will be used
};