From a63c1e61277b3b4cd8298a9798fb52b4818f8987 Mon Sep 17 00:00:00 2001 From: Thomas Brierley Date: Wed, 1 Feb 2017 00:04:04 +0000 Subject: [PATCH] Fix clipPath coercion when used multiple times (#498) Check parent nodes before coercing elements into clipPaths to prevent the same element being coerced multiple times. Fixes adobe-webplatform/Snap.svg#471 --- src/attr.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/attr.js b/src/attr.js index 9943141..cf6c81e 100644 --- a/src/attr.js +++ b/src/attr.js @@ -64,9 +64,20 @@ Snap.plugin(function (Snap, Element, Paper, glob, Fragment) { }(function (value) { if (value instanceof Element || value instanceof Fragment) { eve.stop(); - if (value.type == "clipPath") { - var clip = value; - } else { + var clip, + node = value.node; + while (node) { + if (node.nodeName === "clipPath") { + clip = new Element(node); + break; + } + if (node.nodeName === "svg") { + clip = undefined; + break; + } + node = node.parentNode; + } + if (!clip) { clip = make("clipPath", getSomeDefs(this)); clip.node.appendChild(value.node); !clip.node.id && $(clip.node, {