From 973556a88de356e610a8bf26d1e22d5a92033769 Mon Sep 17 00:00:00 2001 From: nobuti Date: Fri, 26 Oct 2018 18:57:55 +0200 Subject: [PATCH] Modifiers implementation on getter --- src/element.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/element.js b/src/element.js index f0d9e8e..57a83ac 100644 --- a/src/element.js +++ b/src/element.js @@ -261,7 +261,7 @@ SVG.Element = SVG.invent({ var well, len // act as a setter if svg is given - if (svg && this instanceof SVG.Parent) { + if (typeof svg === 'string' && this instanceof SVG.Parent) { // create temporary holder well = document.createElementNS(SVG.ns, 'svg') // dump raw svg @@ -271,9 +271,20 @@ SVG.Element = SVG.invent({ for (len = well.children.length; len--;) { this.node.appendChild(well.firstElementChild) } - // otherwise act as a getter } else { + if (typeof svg === 'function') { + well = svg(this) + + if (well instanceof SVG.Element) { + return well.svg() + } + + if (typeof well === 'boolean' && !well) { + return null + } + } + // write svgjs data to the dom this.writeDataToDom() -- 2.39.5