diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-05 19:02:35 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-05 19:02:35 +0100 |
commit | 2f8d32a1f4fbe51c4e6ac381d5d663d8f11fc1f9 (patch) | |
tree | 4abb508477aa4b6b811f89731011661783a2225c /src/elemnts-svg.js | |
parent | 4049e2e6361d5ed9120f1edd02ef96ecc138fa6d (diff) | |
download | svg.js-2f8d32a1f4fbe51c4e6ac381d5d663d8f11fc1f9.tar.gz svg.js-2f8d32a1f4fbe51c4e6ac381d5d663d8f11fc1f9.zip |
Linted all files, upgraded all dependencies
Diffstat (limited to 'src/elemnts-svg.js')
-rw-r--r-- | src/elemnts-svg.js | 107 |
1 files changed, 56 insertions, 51 deletions
diff --git a/src/elemnts-svg.js b/src/elemnts-svg.js index 5ee97b7..b5b2542 100644 --- a/src/elemnts-svg.js +++ b/src/elemnts-svg.js @@ -1,63 +1,68 @@ - // Import raw svg - svg: function (svg, fn = false) { - var well, len - - // act as getter if no svg string is given - if(svg == null || svg === true || typeof svg == 'function') { - // write svgjs data to the dom - this.writeDataToDom() - let current = this - - // An export modifier was passed - if (typeof svg == 'function') { - // Juggle arguments - [fn, svg] = [svg, fn] - - // If the user wants outerHTML we need to process this node, too - if (!svg) { - current = fn(current) - - // The user does not want this node? Well, then he gets nothing - if (current === false) return '' - } +import { ns } from './namespaces.js' - // Deep loop through all children and apply modifier - current.each(function () { - let result = fn(this) +/* eslint no-unused-vars: "off" */ +var a = { + // Import raw svg + svg (svg, fn = false) { + var well, len, fragment - // If modifier returns false, discard node - if (result === false) { - this.remove() + // act as getter if no svg string is given + if (svg == null || svg === true || typeof svg === 'function') { + // write svgjs data to the dom + this.writeDataToDom() + let current = this - // If modifier returns new node, use it - } else if (result !== this) { - this.replace(result) - } - }, true) + // An export modifier was passed + if (typeof svg === 'function') { + // Juggle arguments + [fn, svg] = [svg, fn] + + // If the user wants outerHTML we need to process this node, too + if (!svg) { + current = fn(current) + + // The user does not want this node? Well, then he gets nothing + if (current === false) return '' } - // Return outer or inner content - return svg - ? current.node.innerHTML - : current.node.outerHTML + // Deep loop through all children and apply modifier + current.each(function () { + let result = fn(this) + + // If modifier returns false, discard node + if (result === false) { + this.remove() + + // If modifier returns new node, use it + } else if (result !== this) { + this.replace(result) + } + }, true) } - // Act as setter if we got a string + // Return outer or inner content + return svg + ? current.node.innerHTML + : current.node.outerHTML + } - // Create temporary holder - well = document.createElementNS(SVG.ns, 'svg') - fragment = document.createDocumentFragment() + // Act as setter if we got a string - // Dump raw svg - well.innerHTML = svg + // Create temporary holder + well = document.createElementNS(ns, 'svg') + fragment = document.createDocumentFragment() - // Transplant nodes into the fragment - for (len = well.children.length; len--;) { - fragment.appendChild(well.firstElementChild) - } + // Dump raw svg + well.innerHTML = svg + + // Transplant nodes into the fragment + for (len = well.children.length; len--;) { + fragment.appendChild(well.firstElementChild) + } - // Add the whole fragment at once - this.node.appendChild(fragment) + // Add the whole fragment at once + this.node.appendChild(fragment) - return this - }, + return this + } +} |