Skip to content

Commit dfc01c5

Browse files
authored
Merge pull request #814 from ramonornela/html2canvas
[UPDATE] html2canvas 0.5.0-beta4
2 parents c01f6b5 + 0e2f2d5 commit dfc01c5

29 files changed

+2154
-1370
lines changed

libs/html2canvas/dist/html2canvas.js

Lines changed: 1211 additions & 892 deletions
Large diffs are not rendered by default.

libs/html2canvas/readme.md

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ html2canvas
33

44
[Homepage](http://html2canvas.hertzen.com) | [Downloads](https://github.com/niklasvh/html2canvas/releases) | [Questions](http://stackoverflow.com/questions/tagged/html2canvas?sort=newest) | [Donate](https://www.gittip.com/niklasvh/)
55

6-
### Current build status ###
7-
[![Build Status](https://travis-ci.org/niklasvh/html2canvas.png)](https://travis-ci.org/niklasvh/html2canvas)
6+
[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/niklasvh/html2canvas?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![Build Status](https://travis-ci.org/niklasvh/html2canvas.png)](https://travis-ci.org/niklasvh/html2canvas)
87

98
#### JavaScript HTML renderer ####
109

@@ -21,7 +20,7 @@ The script is still in a **very experimental state**, so I don't recommend using
2120

2221
###Browser compatibility###
2322

24-
The script should work fine on the following browsers:
23+
The library should work fine on the following browsers (with `Promise` polyfill):
2524

2625
* Firefox 3.5+
2726
* Google Chrome
@@ -33,6 +32,10 @@ As each CSS property needs to be manually built to be supported, there are a num
3332

3433
### Usage ###
3534

35+
The html2canvas library utilizes `Promise`s and expects them to be available in the global context. If you wish to
36+
support [older browsers](http://caniuse.com/#search=promise) that do not natively support `Promise`s, please include a polyfill such as
37+
[es6-promise](https://github.com/jakearchibald/es6-promise) before including `html2canvas`.
38+
3639
**Note!** These instructions are for using the current dev version of 0.5, for the latest release version (0.4.1), checkout the [old readme](https://github.com/niklasvh/html2canvas/blob/v0.4/readme.md).
3740

3841
To render an `element` with html2canvas, simply call:
@@ -52,6 +55,10 @@ Clone git repository with submodules:
5255

5356
$ git clone --recursive git://github.com/niklasvh/html2canvas.git
5457

58+
Install Grunt and uglifyjs:
59+
60+
$ npm install -g grunt-cli uglify-js
61+
5562
Run the full build process (including lint, qunit and webdriver tests):
5663

5764
$ grunt
@@ -81,46 +88,3 @@ For more information and examples, please visit the [homepage](http://html2canva
8188
### Contributing ###
8289

8390
If you wish to contribute to the project, please send the pull requests to the develop branch. Before submitting any changes, try and test that the changes work with all the support browsers. If some CSS property isn't supported or is incomplete, please create appropriate tests for it as well before submitting any code changes.
84-
85-
### Changelog ###
86-
87-
v0.4.1 - 7.9.2013
88-
* Added support for bower
89-
* Improved z-index ordering
90-
* Basic implementation for CSS transformations
91-
* Fixed inline text in top element
92-
* Basic implementation for text-shadow
93-
94-
v0.4.0 - 30.1.2013
95-
* Added rendering tests with <a href="https://github.com/niklasvh/webdriver.js">webdriver</a>
96-
* Switched to using grunt for building
97-
* Removed support for IE<9, including any FlashCanvas bits
98-
* Support for border-radius
99-
* Support for multiple background images, size, and clipping
100-
* Support for :before and :after pseudo elements
101-
* Support for placeholder rendering
102-
* Reformatted all tests to small units to test specific features
103-
104-
v0.3.4 - 26.6.2012
105-
106-
* Removed (last?) jQuery dependencies (<a href="https://github.com/niklasvh/html2canvas/commit/343b86705fe163766fcf735eb0217130e4bd5b17">niklasvh</a>)
107-
* SVG-powered rendering (<a href="https://github.com/niklasvh/html2canvas/commit/67d3e0d0f59a5a654caf71a2e3be6494ff146c75">niklasvh</a>)
108-
* Radial gradients (<a href="https://github.com/niklasvh/html2canvas/commit/4f22c18043a73c0c3bbf3b5e4d62714c56acd3c7">SunboX</a>)
109-
* Split renderers to their own objects (<a href="https://github.com/niklasvh/html2canvas/commit/94f2f799a457cd29a21cc56ef8c06f1697866739">niklasvh</a>)
110-
* Simplified API, cleaned up code (<a href="https://github.com/niklasvh/html2canvas/commit/c7d526c9eaa6a4abf4754d205fe1dee360c7660e">niklasvh</a>)
111-
112-
v0.3.3 - 2.3.2012
113-
114-
* SVG taint fix, and additional taint testing options for rendering (<a href="https://github.com/niklasvh/html2canvas/commit/2dc8b9385e656696cb019d615bdfa1d98b17d5d4">niklasvh</a>)
115-
* Added support for CORS images and option to create canvas as tainted (<a href="https://github.com/niklasvh/html2canvas/commit/3ad49efa0032cde25c6ed32a39e35d1505d3b2ef">niklasvh</a>)
116-
* Improved minification saved ~1K! (<a href="https://github.com/cobexer/html2canvas/commit/b82be022b2b9240bd503e078ac980bde2b953e43">cobexer</a>)
117-
* Added integrated support for Flashcanvas (<a href="https://github.com/niklasvh/html2canvas/commit/e9257191519f67d74fd5e364d8dee3c0963ba5fc">niklasvh</a>)
118-
* Fixed a variety of legacy IE bugs (<a href="https://github.com/niklasvh/html2canvas/commit/b65357c55d0701017bafcd357bc654b54d458f8f">niklasvh</a>)
119-
120-
v0.3.2 - 20.2.2012
121-
122-
* Added changelog!
123-
* Added bookmarklet (<a href="https://github.com/niklasvh/html2canvas/commit/b320dd306e1a2d32a3bc5a71b6ebf6d8c060cde5">cobexer</a>)
124-
* Option to select single element to render (<a href="https://github.com/niklasvh/html2canvas/commit/0cb252ada91c84ef411288b317c03e97da1f12ad">niklasvh</a>)
125-
* Fixed closure compiler warnings (<a href="https://github.com/niklasvh/html2canvas/commit/36ff1ec7aadcbdf66851a0b77f0b9e87e4a8e4a1">cobexer</a>)
126-
* Enable profiling in FF (<a href="https://github.com/niklasvh/html2canvas/commit/bbd75286a8406cf9e5aea01fdb7950d547edefb9">cobexer</a>)

libs/html2canvas/src/clone.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
var log = require('./log');
2+
3+
function restoreOwnerScroll(ownerDocument, x, y) {
4+
if (ownerDocument.defaultView && (x !== ownerDocument.defaultView.pageXOffset || y !== ownerDocument.defaultView.pageYOffset)) {
5+
ownerDocument.defaultView.scrollTo(x, y);
6+
}
7+
}
8+
9+
function cloneCanvasContents(canvas, clonedCanvas) {
10+
try {
11+
if (clonedCanvas) {
12+
clonedCanvas.width = canvas.width;
13+
clonedCanvas.height = canvas.height;
14+
clonedCanvas.getContext("2d").putImageData(canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height), 0, 0);
15+
}
16+
} catch(e) {
17+
log("Unable to copy canvas content from", canvas, e);
18+
}
19+
}
20+
21+
function cloneNode(node, javascriptEnabled) {
22+
var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
23+
24+
var child = node.firstChild;
25+
while(child) {
26+
if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') {
27+
clone.appendChild(cloneNode(child, javascriptEnabled));
28+
}
29+
child = child.nextSibling;
30+
}
31+
32+
if (node.nodeType === 1) {
33+
clone._scrollTop = node.scrollTop;
34+
clone._scrollLeft = node.scrollLeft;
35+
if (node.nodeName === "CANVAS") {
36+
cloneCanvasContents(node, clone);
37+
} else if (node.nodeName === "TEXTAREA" || node.nodeName === "SELECT") {
38+
clone.value = node.value;
39+
}
40+
}
41+
42+
return clone;
43+
}
44+
45+
function initNode(node) {
46+
if (node.nodeType === 1) {
47+
node.scrollTop = node._scrollTop;
48+
node.scrollLeft = node._scrollLeft;
49+
50+
var child = node.firstChild;
51+
while(child) {
52+
initNode(child);
53+
child = child.nextSibling;
54+
}
55+
}
56+
}
57+
58+
module.exports = function(ownerDocument, containerDocument, width, height, options, x ,y) {
59+
var documentElement = cloneNode(ownerDocument.documentElement, options.javascriptEnabled);
60+
var container = containerDocument.createElement("iframe");
61+
62+
container.className = "html2canvas-container";
63+
container.style.visibility = "hidden";
64+
container.style.position = "fixed";
65+
container.style.left = "-10000px";
66+
container.style.top = "0px";
67+
container.style.border = "0";
68+
container.width = width;
69+
container.height = height;
70+
container.scrolling = "no"; // ios won't scroll without it
71+
containerDocument.body.appendChild(container);
72+
73+
return new Promise(function(resolve) {
74+
var documentClone = container.contentWindow.document;
75+
76+
/* Chrome doesn't detect relative background-images assigned in inline <style> sheets when fetched through getComputedStyle
77+
if window url is about:blank, we can assign the url to current by writing onto the document
78+
*/
79+
container.contentWindow.onload = container.onload = function() {
80+
var interval = setInterval(function() {
81+
if (documentClone.body.childNodes.length > 0) {
82+
initNode(documentClone.documentElement);
83+
clearInterval(interval);
84+
if (options.type === "view") {
85+
container.contentWindow.scrollTo(x, y);
86+
if ((/(iPad|iPhone|iPod)/g).test(navigator.userAgent) && (container.contentWindow.scrollY !== y || container.contentWindow.scrollX !== x)) {
87+
documentClone.documentElement.style.top = (-y) + "px";
88+
documentClone.documentElement.style.left = (-x) + "px";
89+
documentClone.documentElement.style.position = 'absolute';
90+
}
91+
}
92+
resolve(container);
93+
}
94+
}, 50);
95+
};
96+
97+
documentClone.open();
98+
documentClone.write("<!DOCTYPE html><html></html>");
99+
// Chrome scrolls the parent document for some reason after the write to the cloned window???
100+
restoreOwnerScroll(ownerDocument, x, y);
101+
documentClone.replaceChild(documentClone.adoptNode(documentElement), documentClone.documentElement);
102+
documentClone.close();
103+
});
104+
};

0 commit comments

Comments
 (0)