diff options
Diffstat (limited to 'src/elements/Fragment.js')
-rw-r--r-- | src/elements/Fragment.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/elements/Fragment.js b/src/elements/Fragment.js new file mode 100644 index 0000000..228e93f --- /dev/null +++ b/src/elements/Fragment.js @@ -0,0 +1,34 @@ +import Dom from './Dom.js' +import { globals } from '../utils/window.js' +import { register } from '../utils/adopter.js' +import Svg from './Svg.js' + +class Fragment extends Dom { + constructor (node = globals.document.createDocumentFragment()) { + super(node) + } + + // Import / Export raw svg + svg (svgOrFn, outerHTML) { + if (svgOrFn === false) { + outerHTML = false + svgOrFn = null + } + + // act as getter if no svg string is given + if (svgOrFn == null || typeof svgOrFn === 'function') { + const wrapper = new Svg() + wrapper.add(this.node.cloneNode(true)) + + return wrapper.svg(svgOrFn, false) + } + + // Act as setter if we got a string + return super.svg(svgOrFn, false) + } + +} + +register(Fragment, 'Fragment') + +export default Fragment |