2011-12-11 21:06:57 +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
|
|
|
|
*/
|
2012-03-03 21:18:39 +04:00
|
|
|
var h2cSelector, h2cOptions;
|
2011-12-11 21:06:57 +04:00
|
|
|
(function(document, window) {
|
2014-09-04 19:46:17 +04:00
|
|
|
function appendScript(src) {
|
|
|
|
document.write('<script type="text/javascript" src="' + src + '.js?' + Math.random() + '"></script>');
|
2011-12-11 21:06:57 +04:00
|
|
|
}
|
2014-05-18 22:17:59 +04:00
|
|
|
|
2014-10-06 23:46:43 +04:00
|
|
|
var sources = ['log', 'punycode/punycode', 'core', 'nodecontainer', 'pseudoelementcontainer', 'stackingcontext', 'textcontainer', 'support', 'imagecontainer', 'dummyimagecontainer', 'proxyimagecontainer', 'gradientcontainer',
|
2014-12-13 19:10:41 +03:00
|
|
|
'lineargradientcontainer', 'webkitgradientcontainer', 'svgcontainer', 'svgnodecontainer', 'imageloader', 'nodeparser', 'font', 'fontmetrics', 'renderer', 'promise', 'xhr', 'framecontainer', 'proxy', 'color', 'renderers/canvas'];
|
2014-09-04 19:46:17 +04:00
|
|
|
|
|
|
|
['/tests/assets/jquery-1.6.2'].concat(window.location.search === "?selenium" ? ['/dist/html2canvas'] : sources.map(function(src) { return '/src/' + src; })).forEach(appendScript);
|
|
|
|
|
2014-09-20 21:21:25 +04:00
|
|
|
if (typeof(noFabric) === "undefined") {
|
|
|
|
appendScript('/dist/html2canvas.svg');
|
|
|
|
}
|
2014-09-04 21:50:31 +04:00
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
window.onload = function() {
|
2014-09-04 19:46:17 +04:00
|
|
|
(function( $ ){
|
|
|
|
$.fn.html2canvas = function(options) {
|
|
|
|
if (options && options.profile && window.console && window.console.profile && window.location.search !== "?selenium2") {
|
|
|
|
window.console.profile();
|
|
|
|
}
|
|
|
|
var date = new Date(),
|
|
|
|
$message = null,
|
|
|
|
timeoutTimer = false,
|
|
|
|
timer = date.getTime();
|
|
|
|
options = options || {};
|
|
|
|
|
|
|
|
var promise = html2canvas(this, options);
|
|
|
|
promise['catch'](function(err) {
|
|
|
|
console.log("html2canvas threw an error", err);
|
|
|
|
});
|
|
|
|
|
|
|
|
promise.then(function(canvas) {
|
|
|
|
var $canvas = $(canvas),
|
|
|
|
finishTime = new Date();
|
|
|
|
|
|
|
|
if (options && options.profile && window.console && window.console.profileEnd) {
|
|
|
|
window.console.profileEnd();
|
|
|
|
}
|
|
|
|
$canvas.addClass("html2canvas")
|
|
|
|
.css({
|
|
|
|
position: 'absolute',
|
|
|
|
left: 0,
|
|
|
|
top: 0
|
|
|
|
}).appendTo(document.body);
|
|
|
|
|
|
|
|
if (window.location.search !== "?selenium") {
|
|
|
|
$canvas.siblings().toggle();
|
|
|
|
$(window).click(function(){
|
|
|
|
$canvas.toggle().siblings().toggle();
|
2014-09-21 12:24:20 +04:00
|
|
|
$(document.documentElement).css('background', $canvas.is(':visible') ? "none" : "");
|
|
|
|
$(document.body).css('background', $canvas.is(':visible') ? "none" : "");
|
2014-09-04 19:46:17 +04:00
|
|
|
throwMessage("Canvas Render " + ($canvas.is(':visible') ? "visible" : "hidden"));
|
|
|
|
});
|
2014-09-21 12:24:20 +04:00
|
|
|
$(document.documentElement).css('background', $canvas.is(':visible') ? "none" : "");
|
|
|
|
$(document.body).css('background', $canvas.is(':visible') ? "none" : "");
|
2014-09-04 19:46:17 +04:00
|
|
|
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)) + " ms<br />",4000);
|
|
|
|
} else {
|
|
|
|
$canvas.css('display', 'none');
|
|
|
|
}
|
|
|
|
// test if canvas is read-able
|
|
|
|
try {
|
|
|
|
$canvas[0].toDataURL();
|
|
|
|
} catch(e) {
|
|
|
|
if ($canvas[0].nodeName.toLowerCase() === "canvas") {
|
|
|
|
// TODO, maybe add a bit less offensive way to present this, but still something that can easily be noticed
|
|
|
|
window.alert("Canvas is tainted, unable to read data");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
function throwMessage(msg,duration){
|
|
|
|
window.clearTimeout(timeoutTimer);
|
|
|
|
timeoutTimer = window.setTimeout(function(){
|
|
|
|
$message.fadeOut(function(){
|
|
|
|
$message.remove();
|
|
|
|
$message = null;
|
|
|
|
});
|
|
|
|
},duration || 2000);
|
|
|
|
if ($message)
|
|
|
|
$message.remove();
|
|
|
|
$message = $('<div />').html(msg).css({
|
|
|
|
margin:0,
|
|
|
|
padding:10,
|
|
|
|
background: "#000",
|
|
|
|
opacity:0.7,
|
|
|
|
position:"fixed",
|
|
|
|
top:10,
|
|
|
|
right:10,
|
|
|
|
fontFamily: 'Tahoma',
|
|
|
|
color:'#fff',
|
|
|
|
fontSize:12,
|
|
|
|
borderRadius:12,
|
|
|
|
width:'auto',
|
|
|
|
height:'auto',
|
|
|
|
textAlign:'center',
|
|
|
|
textDecoration:'none',
|
|
|
|
display:'none'
|
|
|
|
}).appendTo(document.body).fadeIn();
|
|
|
|
log(msg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})(jQuery);
|
|
|
|
|
2014-02-23 19:02:49 +04:00
|
|
|
h2cSelector = [document.documentElement];
|
2012-05-29 05:26:26 +04:00
|
|
|
|
2012-03-02 20:05:03 +04:00
|
|
|
if (window.setUp) {
|
|
|
|
window.setUp();
|
|
|
|
}
|
2012-05-29 05:26:26 +04:00
|
|
|
|
2014-09-27 21:20:08 +04:00
|
|
|
window.run = function() {
|
2012-03-02 21:22:23 +04:00
|
|
|
$(h2cSelector).html2canvas($.extend({
|
2012-03-02 20:05:03 +04:00
|
|
|
logging: true,
|
|
|
|
profile: true,
|
2014-09-20 21:25:48 +04:00
|
|
|
proxy: "http://localhost:8082",
|
2014-10-12 21:32:10 +04:00
|
|
|
useCORS: false,
|
|
|
|
removeContainer: false
|
2012-03-02 21:22:23 +04:00
|
|
|
}, h2cOptions));
|
2014-09-27 21:20:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
if (typeof(dontRun) === "undefined") {
|
|
|
|
setTimeout(window.run, 100);
|
|
|
|
}
|
2012-03-02 20:05:03 +04:00
|
|
|
};
|
2012-02-04 18:32:09 +04:00
|
|
|
}(document, window));
|