2011-11-16 03:25:02 +04:00
|
|
|
/*
|
|
|
|
html2canvas @VERSION@ <http://html2canvas.hertzen.com>
|
|
|
|
Copyright (c) 2011 Niklas von Hertzen. All rights reserved.
|
|
|
|
http://www.twitter.com/niklasvh
|
|
|
|
|
|
|
|
Released under MIT License
|
|
|
|
*/
|
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
var html2canvas = {};
|
2011-07-16 20:59:15 +04:00
|
|
|
|
2011-12-17 23:05:20 +04:00
|
|
|
html2canvas.logging = false;
|
2011-07-16 20:59:15 +04:00
|
|
|
|
2012-02-25 22:58:04 +04:00
|
|
|
function h2clog(a) {
|
2011-11-18 14:53:26 +04:00
|
|
|
if (html2canvas.logging && window.console && window.console.log) {
|
2011-09-12 22:35:37 +04:00
|
|
|
window.console.log(a);
|
|
|
|
}
|
2012-02-25 22:58:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
html2canvas.log = h2clog; // for compatibility with the jquery plugin
|
2011-07-18 14:19:34 +04:00
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
html2canvas.Util = {};
|
2011-07-18 14:19:34 +04:00
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
html2canvas.Util.backgroundImage = function (src) {
|
2011-07-17 00:56:49 +04:00
|
|
|
|
2011-09-13 00:50:43 +04:00
|
|
|
if (/data:image\/.*;base64,/i.test( src ) || /^(-webkit|-moz|linear-gradient|-o-)/.test( src )) {
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (src.toLowerCase().substr( 0, 5 ) === 'url("') {
|
2011-09-12 22:35:37 +04:00
|
|
|
src = src.substr( 5 );
|
|
|
|
src = src.substr( 0, src.length - 2 );
|
|
|
|
} else {
|
|
|
|
src = src.substr( 4 );
|
|
|
|
src = src.substr( 0, src.length - 1 );
|
2011-07-16 20:59:15 +04:00
|
|
|
}
|
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
return src;
|
|
|
|
};
|
2011-07-18 14:19:34 +04:00
|
|
|
|
2011-09-13 00:50:43 +04:00
|
|
|
html2canvas.Util.Bounds = function getBounds (el) {
|
|
|
|
var clientRect,
|
|
|
|
bounds = {};
|
|
|
|
|
|
|
|
if (el.getBoundingClientRect){
|
|
|
|
clientRect = el.getBoundingClientRect();
|
|
|
|
|
|
|
|
|
|
|
|
// TODO add scroll position to bounds, so no scrolling of window necessary
|
|
|
|
bounds.top = clientRect.top;
|
|
|
|
bounds.bottom = clientRect.bottom || (clientRect.top + clientRect.height);
|
|
|
|
bounds.left = clientRect.left;
|
2012-02-26 02:19:16 +04:00
|
|
|
|
|
|
|
// older IE doesn't have width/height, but top/bottom instead
|
|
|
|
bounds.width = clientRect.width || (clientRect.right - clientRect.left);
|
|
|
|
bounds.height = clientRect.height || (clientRect.bottom - clientRect.top);
|
2011-09-13 00:50:43 +04:00
|
|
|
|
|
|
|
return bounds;
|
|
|
|
|
2012-02-26 02:19:16 +04:00
|
|
|
} /*else{
|
2011-09-13 00:50:43 +04:00
|
|
|
|
|
|
|
|
|
|
|
p = $(el).offset();
|
|
|
|
|
|
|
|
return {
|
|
|
|
left: p.left + getCSS(el,"borderLeftWidth", true),
|
|
|
|
top: p.top + getCSS(el,"borderTopWidth", true),
|
|
|
|
width:$(el).innerWidth(),
|
|
|
|
height:$(el).innerHeight()
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} */
|
|
|
|
}
|
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
html2canvas.Util.getCSS = function (el, attribute) {
|
|
|
|
// return jQuery(el).css(attribute);
|
2011-07-18 00:27:45 +04:00
|
|
|
/*
|
2011-09-12 22:35:37 +04:00
|
|
|
var val,
|
|
|
|
left,
|
|
|
|
rsLeft = el.runtimeStyle && el.runtimeStyle[ attribute ],
|
|
|
|
style = el.style;
|
|
|
|
|
|
|
|
if ( el.currentStyle ) {
|
|
|
|
val = el.currentStyle[ attribute ];
|
|
|
|
} else if (window.getComputedStyle) {
|
|
|
|
val = document.defaultView.getComputedStyle(el, null)[ attribute ];
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
// Check if we are not dealing with pixels, (Opera has issues with this)
|
|
|
|
// Ported from jQuery css.js
|
|
|
|
// From the awesome hack by Dean Edwards
|
|
|
|
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
|
|
|
|
|
|
|
|
// If we're not dealing with a regular pixel number
|
|
|
|
// but a number that has a weird ending, we need to convert it to pixels
|
|
|
|
|
2011-09-13 00:50:43 +04:00
|
|
|
// if ( !/^-?\d+(?:px)?$/i.test( val ) && /^-?\d/.test( val ) ) {
|
|
|
|
/*
|
2011-09-12 22:35:37 +04:00
|
|
|
// Remember the original values
|
|
|
|
left = style.left;
|
|
|
|
|
|
|
|
// Put in the new values to get a computed value out
|
|
|
|
if ( rsLeft ) {
|
|
|
|
el.runtimeStyle.left = el.currentStyle.left;
|
|
|
|
}
|
|
|
|
style.left = attribute === "fontSize" ? "1em" : (val || 0);
|
|
|
|
val = style.pixelLeft + "px";
|
|
|
|
|
|
|
|
// Revert the changed values
|
|
|
|
style.left = left;
|
|
|
|
if ( rsLeft ) {
|
|
|
|
el.runtimeStyle.left = rsLeft;
|
|
|
|
}*/
|
2011-11-23 16:57:37 +04:00
|
|
|
// val = $(el).css(attribute);
|
2011-09-13 00:50:43 +04:00
|
|
|
// }
|
2012-02-26 02:19:16 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
var val = $(el).css(attribute);
|
|
|
|
|
|
|
|
if (val === "medium") {
|
|
|
|
val = 3;
|
|
|
|
}*/
|
|
|
|
|
2011-11-23 16:57:37 +04:00
|
|
|
return $(el).css(attribute);
|
2011-07-18 00:27:45 +04:00
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
|
|
|
|
};
|
2011-07-16 20:59:15 +04:00
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
html2canvas.Util.Extend = function (options, defaults) {
|
|
|
|
var key;
|
|
|
|
for (key in options) {
|
|
|
|
if (options.hasOwnProperty(key)) {
|
|
|
|
defaults[key] = options[key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return defaults;
|
|
|
|
};
|
2011-07-16 20:59:15 +04:00
|
|
|
|
2011-09-12 22:35:37 +04:00
|
|
|
html2canvas.Util.Children = function(el) {
|
|
|
|
// $(el).contents() !== el.childNodes, Opera / IE have issues with that
|
2011-11-23 16:59:33 +04:00
|
|
|
var children;
|
|
|
|
try {
|
|
|
|
children = $(el).contents();
|
|
|
|
} catch (ex) {
|
2012-02-25 22:58:04 +04:00
|
|
|
h2clog("html2canvas.Util.Children failed with exception: " + ex.message);
|
2011-11-23 16:59:33 +04:00
|
|
|
children = [];
|
|
|
|
}
|
|
|
|
return children;
|
2012-02-25 22:58:04 +04:00
|
|
|
};
|