mirror of
https://github.com/niklasvh/html2canvas.git
synced 2023-08-10 21:13:10 +03:00
Add ignoreElements predicate function option
This commit is contained in:
parent
e6c44afca1
commit
fad4f837c9
@ -17,6 +17,7 @@ These are all of the available configuration options.
|
|||||||
| canvas | `null` | Existing `canvas` element to use as a base for drawing on
|
| canvas | `null` | Existing `canvas` element to use as a base for drawing on
|
||||||
| foreignObjectRendering | `false` | Whether to use ForeignObject rendering if the browser supports it
|
| foreignObjectRendering | `false` | Whether to use ForeignObject rendering if the browser supports it
|
||||||
| imageTimeout | `15000` | Timeout for loading an image (in milliseconds). Set to `0` to disable timeout.
|
| imageTimeout | `15000` | Timeout for loading an image (in milliseconds). Set to `0` to disable timeout.
|
||||||
|
| ignoreElements | `(element) => false` | Predicate function which removes the matching elements from the render.
|
||||||
| logging | `true` | Enable logging for debug purposes
|
| logging | `true` | Enable logging for debug purposes
|
||||||
| proxy | `null` | Url to the [proxy](/proxy/) which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded.
|
| proxy | `null` | Url to the [proxy](/proxy/) which is to be used for loading cross-origin images. If left empty, cross-origin images won't be loaded.
|
||||||
| removeContainer | `true` | Whether to cleanup the cloned DOM elements html2canvas creates temporarily
|
| removeContainer | `true` | Whether to cleanup the cloned DOM elements html2canvas creates temporarily
|
||||||
|
@ -65,7 +65,7 @@
|
|||||||
"build": "rimraf dist/ && node scripts/create-reftest-list && npm run build:npm && npm run build:browser",
|
"build": "rimraf dist/ && node scripts/create-reftest-list && npm run build:npm && npm run build:browser",
|
||||||
"build:npm": "babel src/ -d dist/npm/ --plugins=dev-expression,transform-es2015-modules-commonjs && replace-in-file __VERSION__ '\"$npm_package_version\"' dist/npm/index.js",
|
"build:npm": "babel src/ -d dist/npm/ --plugins=dev-expression,transform-es2015-modules-commonjs && replace-in-file __VERSION__ '\"$npm_package_version\"' dist/npm/index.js",
|
||||||
"build:browser": "webpack",
|
"build:browser": "webpack",
|
||||||
"format": "prettier --single-quote --no-bracket-spacing --tab-width 4 --print-width 100 --write \"{src,www,tests,scripts}/**/*.js\"",
|
"format": "prettier --single-quote --no-bracket-spacing --tab-width 4 --print-width 100 --write \"{src,www/src,tests,scripts}/**/*.js\"",
|
||||||
"flow": "flow",
|
"flow": "flow",
|
||||||
"lint": "eslint src/**",
|
"lint": "eslint src/**",
|
||||||
"test": "npm run flow && npm run lint && npm run test:node && npm run karma",
|
"test": "npm run flow && npm run lint && npm run test:node && npm run karma",
|
||||||
|
@ -268,8 +268,12 @@ export class DocumentCloner {
|
|||||||
for (let child = node.firstChild; child; child = child.nextSibling) {
|
for (let child = node.firstChild; child; child = child.nextSibling) {
|
||||||
if (
|
if (
|
||||||
child.nodeType !== Node.ELEMENT_NODE ||
|
child.nodeType !== Node.ELEMENT_NODE ||
|
||||||
// $FlowFixMe
|
(child.nodeName !== 'SCRIPT' &&
|
||||||
(child.nodeName !== 'SCRIPT' && !child.hasAttribute(IGNORE_ATTRIBUTE))
|
// $FlowFixMe
|
||||||
|
!child.hasAttribute(IGNORE_ATTRIBUTE) &&
|
||||||
|
(typeof this.options.ignoreElements !== 'function' ||
|
||||||
|
// $FlowFixMe
|
||||||
|
!this.options.ignoreElements(child)))
|
||||||
) {
|
) {
|
||||||
if (!this.copyStyles || child.nodeName !== 'STYLE') {
|
if (!this.copyStyles || child.nodeName !== 'STYLE') {
|
||||||
clone.appendChild(this.cloneNode(child));
|
clone.appendChild(this.cloneNode(child));
|
||||||
|
@ -14,6 +14,7 @@ export type Options = {
|
|||||||
backgroundColor: string,
|
backgroundColor: string,
|
||||||
canvas: ?HTMLCanvasElement,
|
canvas: ?HTMLCanvasElement,
|
||||||
foreignObjectRendering: boolean,
|
foreignObjectRendering: boolean,
|
||||||
|
ignoreElements?: HTMLElement => boolean,
|
||||||
imageTimeout: number,
|
imageTimeout: number,
|
||||||
logging: boolean,
|
logging: boolean,
|
||||||
proxy: ?string,
|
proxy: ?string,
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
<title>element render test</title>
|
<title>element render test</title>
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||||
<script>
|
<script>
|
||||||
|
h2cOptions = {ignoreElements: function(element) {
|
||||||
|
return element.className === 'ignored';
|
||||||
|
}};
|
||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="../../test.js"></script>
|
<script type="text/javascript" src="../../test.js"></script>
|
||||||
<style>
|
<style>
|
||||||
@ -15,7 +17,7 @@
|
|||||||
background: green;
|
background: green;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ignored {
|
#ignored, .ignored {
|
||||||
background: red;
|
background: red;
|
||||||
width: 100px;
|
width: 100px;
|
||||||
height: 100px;
|
height: 100px;
|
||||||
@ -32,10 +34,11 @@
|
|||||||
<div id="ignored" data-html2canvas-ignore>
|
<div id="ignored" data-html2canvas-ignore>
|
||||||
great failure
|
great failure
|
||||||
</div>
|
</div>
|
||||||
|
<div class="ignored">
|
||||||
|
ignore predicate
|
||||||
|
</div>
|
||||||
<div id="div1">
|
<div id="div1">
|
||||||
great success
|
great success
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user