Skip to content

Commit cc29cab

Browse files
committed
Fix issue with importing SVG document nodes.
Closes paperjs#276.
1 parent 19c7788 commit cc29cab

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/dom/DomElement.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ var DomElement = new function() {
9595
},
9696

9797
getStyles: function(el) {
98-
var view = el && el.ownerDocument.defaultView;
98+
// If el is a document (nodeType == 9), use it directly
99+
var doc = el && el.nodeType !== 9 ? el.ownerDocument : el,
100+
view = doc && doc.defaultView;
99101
return view && view.getComputedStyle(el, '');
100102
},
101103

src/svg/SVGImport.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ new function() {
9494
for (var i = 0, l = nodes.length; i < l; i++) {
9595
var childNode = nodes[i],
9696
child;
97-
if (childNode.nodeType == 1 && (child = importSVG(childNode))) {
97+
if (childNode.nodeType === 1 && (child = importSVG(childNode))) {
9898
// When adding CompoundPaths to other CompoundPaths,
9999
// we need to "unbox" them first:
100100
if (clip && child instanceof CompoundPath) {
@@ -148,7 +148,7 @@ new function() {
148148
stops = [];
149149
for (var i = 0, l = nodes.length; i < l; i++) {
150150
var child = nodes[i];
151-
if (child.nodeType == 1)
151+
if (child.nodeType === 1)
152152
stops.push(applyAttributes(new GradientStop(), child));
153153
}
154154
var isRadial = type === 'radialgradient',
@@ -172,6 +172,10 @@ new function() {
172172
// NOTE: All importers are lowercase, since jsdom is using uppercase
173173
// nodeNames still.
174174
var importers = {
175+
'#document': function(node) {
176+
return importSVG(node.childNodes[0]);
177+
},
178+
175179
// http://www.w3.org/TR/SVG/struct.html#Groups
176180
g: importGroup,
177181
// http://www.w3.org/TR/SVG/struct.html#NewDocument
@@ -486,7 +490,7 @@ new function() {
486490
var type = node.nodeName.toLowerCase(),
487491
importer = importers[type],
488492
item = importer && importer(node, type),
489-
data = node.getAttribute('data-paper-data');
493+
data = type !== '#document' && node.getAttribute('data-paper-data');
490494
// See importGroup() for an explanation of this filtering:
491495
if (item && !(item instanceof Group))
492496
item = applyAttributes(item, node);

0 commit comments

Comments
 (0)