diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-12 09:35:37 +0100 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2018-11-12 09:35:37 +0100 |
commit | d3f8d83551799db061a558537bc89dcbfd522c21 (patch) | |
tree | f6456de7ac3599c35b217c9f769cb1adca03997f /src/elements | |
parent | bf7703f5915c6154937f3febf812aad6483bff45 (diff) | |
download | svg.js-d3f8d83551799db061a558537bc89dcbfd522c21.tar.gz svg.js-d3f8d83551799db061a558537bc89dcbfd522c21.zip |
evaluate window and document on access and not on import
Diffstat (limited to 'src/elements')
-rw-r--r-- | src/elements/Bare.js | 6 | ||||
-rw-r--r-- | src/elements/Doc.js | 6 | ||||
-rw-r--r-- | src/elements/Dom.js | 10 | ||||
-rw-r--r-- | src/elements/Image.js | 6 | ||||
-rw-r--r-- | src/elements/Text.js | 6 |
5 files changed, 12 insertions, 22 deletions
diff --git a/src/elements/Bare.js b/src/elements/Bare.js index 7162f3a..a057634 100644 --- a/src/elements/Bare.js +++ b/src/elements/Bare.js @@ -1,9 +1,7 @@ import { nodeOrNew, register, wrapWithAttrCheck } from '../utils/adopter.js' import { registerMethods } from '../utils/methods.js' import Container from './Container.js' -import globals from '../utils/window.js' - -const { document } = globals +import { globals } from '../utils/window.js' export default class Bare extends Container { constructor (node, attrs) { @@ -17,7 +15,7 @@ export default class Bare extends Container { } // create text node - this.node.appendChild(document.createTextNode(text)) + this.node.appendChild(globals.document.createTextNode(text)) return this } diff --git a/src/elements/Doc.js b/src/elements/Doc.js index 952f1d3..d56fae3 100644 --- a/src/elements/Doc.js +++ b/src/elements/Doc.js @@ -8,9 +8,7 @@ import { ns, svgjs, xlink, xmlns } from '../modules/core/namespaces.js' import { registerMethods } from '../utils/methods.js' import Container from './Container.js' import Defs from './Defs.js' -import globals from '../utils/window.js' - -const { window } = globals +import { globals } from '../utils/window.js' export default class Doc extends Container { constructor (node) { @@ -20,7 +18,7 @@ export default class Doc extends Container { isRoot () { return !this.node.parentNode || - !(this.node.parentNode instanceof window.SVGElement) || + !(this.node.parentNode instanceof globals.window.SVGElement) || this.node.parentNode.nodeName === '#document' } diff --git a/src/elements/Dom.js b/src/elements/Dom.js index 8fa053c..192b9bd 100644 --- a/src/elements/Dom.js +++ b/src/elements/Dom.js @@ -8,12 +8,10 @@ import { } from '../utils/adopter.js' import { map } from '../utils/utils.js' import { ns } from '../modules/core/namespaces.js' -import globals from '../utils/window.js' +import { globals } from '../utils/window.js' import EventTarget from '../types/EventTarget.js' import attr from '../modules/core/attr.js' -const { window, document } = globals - export default class Dom extends EventTarget { constructor (node, attrs) { super(node) @@ -156,7 +154,7 @@ export default class Dom extends EventTarget { if (!type) return parent // loop trough ancestors if type is given - while (parent && parent.node instanceof window.SVGElement) { // FIXME: That shouldnt be neccessary + while (parent && parent.node instanceof globals.window.SVGElement) { // FIXME: That shouldnt be neccessary if (typeof type === 'string' ? parent.matches(type) : parent instanceof type) return parent parent = adopt(parent.node.parentNode) } @@ -279,8 +277,8 @@ export default class Dom extends EventTarget { outerHTML = outerHTML == null ? false : outerHTML // Create temporary holder - well = document.createElementNS(ns, 'svg') - fragment = document.createDocumentFragment() + well = globals.document.createElementNS(ns, 'svg') + fragment = globals.document.createDocumentFragment() // Dump raw svg well.innerHTML = svgOrFn diff --git a/src/elements/Image.js b/src/elements/Image.js index 6a01b8f..7f00980 100644 --- a/src/elements/Image.js +++ b/src/elements/Image.js @@ -6,9 +6,7 @@ import { registerMethods } from '../utils/methods.js' import { xlink } from '../modules/core/namespaces.js' import Pattern from './Pattern.js' import Shape from './Shape.js' -import globals from '../utils/window.js' - -const { window } = globals +import { globals } from '../utils/window.js' export default class Image extends Shape { constructor (node) { @@ -19,7 +17,7 @@ export default class Image extends Shape { load (url, callback) { if (!url) return this - var img = new window.Image() + var img = new globals.window.Image() on(img, 'load', function (e) { var p = this.parent(Pattern) diff --git a/src/elements/Text.js b/src/elements/Text.js index 41be916..db9c2ee 100644 --- a/src/elements/Text.js +++ b/src/elements/Text.js @@ -9,11 +9,9 @@ import { attrs } from '../modules/core/defaults.js' import { registerMethods } from '../utils/methods.js' import SVGNumber from '../types/SVGNumber.js' import Shape from './Shape.js' -import globals from '../utils/window.js' +import { globals } from '../utils/window.js' import * as textable from '../modules/core/textable.js' -const { window } = globals - export default class Text extends Shape { // Initialize node constructor (node) { @@ -134,7 +132,7 @@ export default class Text extends Shape { var leading = this.dom.leading this.each(function () { - var fontSize = window.getComputedStyle(this.node) + var fontSize = globals.window.getComputedStyle(this.node) .getPropertyValue('font-size') var dy = leading * new SVGNumber(fontSize) |