fixed image search for iframes + added default content for iframes and flash content

This commit is contained in:
Niklas von Hertzen 2011-07-17 02:19:26 +03:00
parent 4e19e99756
commit ead984a1f1
6 changed files with 89 additions and 34 deletions

View File

@ -43,6 +43,7 @@ function html2canvas(el, userOptions) {
ready: function (canvas) { ready: function (canvas) {
document.body.appendChild(canvas); document.body.appendChild(canvas);
}, },
iframeDefault: "default",
flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js", flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",
renderViewport: false renderViewport: false
}); });
@ -60,7 +61,7 @@ function html2canvas(el, userOptions) {
this.fontData = []; this.fontData = [];
this.ignoreElements = "IFRAME|OBJECT|PARAM"; this.ignoreElements = "IFRAME|OBJECT|PARAM";
this.ignoreRe = new RegExp("("+this.ignoreElements+")");
// test how to measure text bounding boxes // test how to measure text bounding boxes
this.useRangeBounds = false; this.useRangeBounds = false;
@ -475,6 +476,17 @@ html2canvas.prototype.newElement = function(el){
if (this.ignoreRe.test(el.nodeName) && this.opts.iframeDefault != "transparent"){
if (this.opts.iframeDefault=="default"){
bgcolor = "#efefef";
/*
* TODO write X over frame
*/
}else{
bgcolor = this.opts.iframeDefault;
}
}
// draw base element bgcolor // draw base element bgcolor
this.newRect( this.newRect(
x+borders[3].width, x+borders[3].width,
@ -546,6 +558,7 @@ html2canvas.prototype.getImages = function(el) {
var self = this; var self = this;
if (!this.ignoreRe.test(el.nodeName)){
// TODO remove jQuery dependancy // TODO remove jQuery dependancy
this.each($(el).contents(),function(i,element){ this.each($(el).contents(),function(i,element){
var ignRe = new RegExp("("+this.ignoreElements+")"); var ignRe = new RegExp("("+this.ignoreElements+")");
@ -553,6 +566,7 @@ html2canvas.prototype.getImages = function(el) {
self.getImages(element); self.getImages(element);
} }
}) })
}
if (el.nodeType==1 || typeof el.nodeType == "undefined"){ if (el.nodeType==1 || typeof el.nodeType == "undefined"){
var background_image = this.getCSS(el,'background-image'); var background_image = this.getCSS(el,'background-image');
@ -839,12 +853,14 @@ html2canvas.prototype.parseElement = function(element){
html2canvas.prototype.parsing = function(el){ html2canvas.prototype.parsing = function(el){
var ignRe = new RegExp("("+this.ignoreElements+")");
var _ = this; var _ = this;
if (!ignRe.test(el.nodeName)){
this.newElement(el); this.newElement(el);
if (!this.ignoreRe.test(el.nodeName)){
// TODO remove jQuery dependancy // TODO remove jQuery dependancy
var contents = $(el).contents(); var contents = $(el).contents();

View File

@ -13,6 +13,7 @@ function html2canvas(el, userOptions) {
ready: function (canvas) { ready: function (canvas) {
document.body.appendChild(canvas); document.body.appendChild(canvas);
}, },
iframeDefault: "default",
flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js", flashCanvasPath: "http://html2canvas.hertzen.com/external/flashcanvas/flashcanvas.js",
renderViewport: false renderViewport: false
}); });
@ -30,7 +31,7 @@ function html2canvas(el, userOptions) {
this.fontData = []; this.fontData = [];
this.ignoreElements = "IFRAME|OBJECT|PARAM"; this.ignoreElements = "IFRAME|OBJECT|PARAM";
this.ignoreRe = new RegExp("("+this.ignoreElements+")");
// test how to measure text bounding boxes // test how to measure text bounding boxes
this.useRangeBounds = false; this.useRangeBounds = false;

View File

@ -59,6 +59,17 @@ html2canvas.prototype.newElement = function(el){
if (this.ignoreRe.test(el.nodeName) && this.opts.iframeDefault != "transparent"){
if (this.opts.iframeDefault=="default"){
bgcolor = "#efefef";
/*
* TODO write X over frame
*/
}else{
bgcolor = this.opts.iframeDefault;
}
}
// draw base element bgcolor // draw base element bgcolor
this.newRect( this.newRect(
x+borders[3].width, x+borders[3].width,

View File

@ -5,6 +5,7 @@ html2canvas.prototype.getImages = function(el) {
var self = this; var self = this;
if (!this.ignoreRe.test(el.nodeName)){
// TODO remove jQuery dependancy // TODO remove jQuery dependancy
this.each($(el).contents(),function(i,element){ this.each($(el).contents(),function(i,element){
var ignRe = new RegExp("("+this.ignoreElements+")"); var ignRe = new RegExp("("+this.ignoreElements+")");
@ -12,6 +13,7 @@ html2canvas.prototype.getImages = function(el) {
self.getImages(element); self.getImages(element);
} }
}) })
}
if (el.nodeType==1 || typeof el.nodeType == "undefined"){ if (el.nodeType==1 || typeof el.nodeType == "undefined"){
var background_image = this.getCSS(el,'background-image'); var background_image = this.getCSS(el,'background-image');

View File

@ -14,12 +14,14 @@ html2canvas.prototype.parseElement = function(element){
html2canvas.prototype.parsing = function(el){ html2canvas.prototype.parsing = function(el){
var ignRe = new RegExp("("+this.ignoreElements+")");
var _ = this; var _ = this;
if (!ignRe.test(el.nodeName)){
this.newElement(el); this.newElement(el);
if (!this.ignoreRe.test(el.nodeName)){
// TODO remove jQuery dependancy // TODO remove jQuery dependancy
var contents = $(el).contents(); var contents = $(el).contents();

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<title>External content tests</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="#" type="text/css" rel="stylesheet">
<script type="text/javascript" src="../external/jquery-1.6.2.js"></script>
<script type="text/javascript" src="../build/html2canvas.js"></script>
<script type="text/javascript" src="../build/jquery.plugin.html2canvas.js"></script>
<script type="text/javascript">
$(window).ready(function() {
$('body').html2canvas();
});
</script>
</head>
<body>
<h1>Iframe</h1>
<iframe src="http://www.google.com" style="width:400px;height:300px;border:5px solid black;"></iframe>
</body>
</html>