html2canvas/build/jquery.plugin.html2canvas.js

119 lines
3.9 KiB
JavaScript
Raw Normal View History

2011-07-16 20:59:15 +04:00
/*
* html2canvas v0.25 <http://html2canvas.hertzen.com>
2011-07-16 20:59:15 +04:00
* Copyright (c) 2011 Niklas von Hertzen. All rights reserved.
* http://www.twitter.com/niklasvh
*
* Released under MIT License
*/
/*
* The MIT License
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
* jQuery helper plugin for examples and tests
*/
(function( $ ){
$.fn.html2canvas = function(options) {
2011-07-16 20:59:15 +04:00
var date = new Date();
var message,
timeoutTimer,
timer = date.getTime();
var object = $.extend({},{
logging: false,
proxyUrl: "http://html2canvas.appspot.com/", // running html2canvas-python proxy
2011-07-17 03:42:45 +04:00
ready: function(renderer) {
2011-07-16 20:59:15 +04:00
var finishTime = new Date();
// console.log((finishTime.getTime()-timer)/1000);
2011-07-17 03:42:45 +04:00
document.body.appendChild(renderer.canvas);
2011-07-16 20:59:15 +04:00
2011-07-17 03:42:45 +04:00
var canvas = $(renderer.canvas);
2011-07-16 20:59:15 +04:00
canvas.css('position','absolute')
.css('left',0).css('top',0);
2011-07-17 03:42:45 +04:00
2011-07-16 20:59:15 +04:00
// $('body').append(canvas);
$(canvas).siblings().toggle();
2011-07-17 03:42:45 +04:00
throwMessage('Screenshot created in '+ ((finishTime.getTime()-timer)/1000) + " seconds<br />Total of "+renderer.numDraws+" draws performed",4000);
2011-07-16 20:59:15 +04:00
$(window).click(function(){
if (!canvas.is(':visible')){
$(canvas).toggle().siblings().toggle();
throwMessage("Canvas Render visible");
} else{
$(canvas).siblings().toggle();
$(canvas).toggle();
throwMessage("Canvas Render hidden");
}
});
}
},options)
new html2canvas(this.get(0), object);
2011-07-16 20:59:15 +04:00
2011-07-17 03:42:45 +04:00
function throwMessage(msg,duration){
2011-07-16 20:59:15 +04:00
window.clearTimeout(timeoutTimer);
timeoutTimer = window.setTimeout(function(){
message.fadeOut(function(){
message.remove();
});
2011-07-17 03:42:45 +04:00
},duration || 2000);
2011-07-16 20:59:15 +04:00
$(message).remove();
2011-07-17 03:42:45 +04:00
message = $('<div />').html(msg).css({
2011-07-16 20:59:15 +04:00
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',
2011-07-16 23:35:21 +04:00
height:'auto',
2011-07-17 03:42:45 +04:00
textAlign:'center',
2011-07-16 23:35:21 +04:00
textDecoration:'none'
2011-07-16 20:59:15 +04:00
}).hide().fadeIn().appendTo('body');
}
};
})( jQuery );