aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobuti <buti@nobuti.com>2018-10-26 18:57:55 +0200
committernobuti <buti@nobuti.com>2018-10-26 18:57:55 +0200
commit973556a88de356e610a8bf26d1e22d5a92033769 (patch)
tree97e6de792e02a0f561581b3c47229c00e1c913ad
parentf46aedf58fbc93483cb21017ffed10e439830108 (diff)
downloadsvg.js-973556a88de356e610a8bf26d1e22d5a92033769.tar.gz
svg.js-973556a88de356e610a8bf26d1e22d5a92033769.zip
Modifiers implementation on getter
-rw-r--r--src/element.js15
1 files 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()