From d927f2d225d74fd3b3f41b298a19f6ba075702cf Mon Sep 17 00:00:00 2001 From: Ulrich-Matthias Schäfer Date: Wed, 8 Apr 2020 07:32:38 +1000 Subject: added Fragment, completed Dom Tests, fixed `matches()` for document fragments --- src/elements/Fragment.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/elements/Fragment.js (limited to 'src/elements/Fragment.js') 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 -- cgit v1.2.3