Skip to content

Commit 373f4fe

Browse files
committed
Use deepCloneBasic for cloning
1 parent 6c1f54d commit 373f4fe

2 files changed

Lines changed: 3 additions & 33 deletions

File tree

src/utils.js

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,6 @@ export const createElement = function createElement(tagName, opt) {
2828
return el;
2929
};
3030

31-
// Deep-clone a node and preserve contents/properties.
32-
export const cloneNode = function cloneNode(node, javascriptEnabled) {
33-
// Recursively clone the node.
34-
var clone = node.nodeType === 3 ? document.createTextNode(node.nodeValue) : node.cloneNode(false);
35-
for (var child = node.firstChild; child; child = child.nextSibling) {
36-
if (javascriptEnabled === true || child.nodeType !== 1 || child.nodeName !== 'SCRIPT') {
37-
clone.appendChild(cloneNode(child, javascriptEnabled));
38-
}
39-
}
40-
41-
if (node.nodeType === 1) {
42-
// Preserve contents/properties of special nodes.
43-
if (node.nodeName === 'CANVAS') {
44-
clone.width = node.width;
45-
clone.height = node.height;
46-
clone.getContext('2d').drawImage(node, 0, 0);
47-
} else if (node.nodeName === 'TEXTAREA' || node.nodeName === 'SELECT') {
48-
clone.value = node.value;
49-
}
50-
51-
// Preserve the node's scroll position when it loads.
52-
clone.addEventListener('load', function() {
53-
clone.scrollTop = node.scrollTop;
54-
clone.scrollLeft = node.scrollLeft;
55-
}, true);
56-
}
57-
58-
// Return the cloned node.
59-
return clone;
60-
}
61-
6231
// Convert units from px using the conversion value 'k' from jsPDF.
6332
export const unitConvert = function unitConvert(obj, k) {
6433
if (objType(obj) === 'number') {

src/worker.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { jsPDF } from 'jspdf';
22
import html2canvas from 'html2canvas';
3-
import { objType, createElement, cloneNode, toPx } from './utils.js';
3+
import { deepCloneBasic } from './snapdom/clone.js';
4+
import { objType, createElement, toPx } from './utils.js';
45

56
/* ----- CONSTRUCTOR ----- */
67

@@ -116,7 +117,7 @@ Worker.prototype.toContainer = function toContainer() {
116117
overlayCSS.opacity = 0;
117118

118119
// Create and attach the elements.
119-
var source = cloneNode(this.prop.src, this.opt.html2canvas.javascriptEnabled);
120+
var source = deepCloneBasic(this.prop.src);
120121
this.prop.overlay = createElement('div', { className: 'html2pdf__overlay', style: overlayCSS });
121122
this.prop.container = createElement('div', { className: 'html2pdf__container', style: containerCSS });
122123
this.prop.container.appendChild(source);

0 commit comments

Comments
 (0)