diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-06-13 01:43:37 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2023-06-13 01:43:37 +0200 |
commit | 03322672782a6318b019eff33fe44ec800d6f12c (patch) | |
tree | 9d807e1585cf28a1ea98e87b855932dba00f1880 /src/elements/Image.js | |
parent | 8e18b4698edd00f83af0be05bb3374f92fecaeb9 (diff) | |
download | svg.js-03322672782a6318b019eff33fe44ec800d6f12c.tar.gz svg.js-03322672782a6318b019eff33fe44ec800d6f12c.zip |
dependency updates, easier formatting
Diffstat (limited to 'src/elements/Image.js')
-rw-r--r-- | src/elements/Image.js | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/src/elements/Image.js b/src/elements/Image.js index c51bc9a..080da16 100644 --- a/src/elements/Image.js +++ b/src/elements/Image.js @@ -9,35 +9,40 @@ import Shape from './Shape.js' import { globals } from '../utils/window.js' export default class Image extends Shape { - constructor (node, attrs = node) { + constructor(node, attrs = node) { super(nodeOrNew('image', node), attrs) } // (re)load image - load (url, callback) { + load(url, callback) { if (!url) return this const img = new globals.window.Image() - on(img, 'load', function (e) { - const p = this.parent(Pattern) + on( + img, + 'load', + function (e) { + const p = this.parent(Pattern) - // ensure image size - if (this.width() === 0 && this.height() === 0) { - this.size(img.width, img.height) - } + // ensure image size + if (this.width() === 0 && this.height() === 0) { + this.size(img.width, img.height) + } - if (p instanceof Pattern) { - // ensure pattern size if not set - if (p.width() === 0 && p.height() === 0) { - p.size(this.width(), this.height()) + if (p instanceof Pattern) { + // ensure pattern size if not set + if (p.width() === 0 && p.height() === 0) { + p.size(this.width(), this.height()) + } } - } - if (typeof callback === 'function') { - callback.call(this, e) - } - }, this) + if (typeof callback === 'function') { + callback.call(this, e) + } + }, + this + ) on(img, 'load error', function () { // dont forget to unbind memory leaking events @@ -57,9 +62,12 @@ registerAttrHook(function (attr, val, _this) { } if (val instanceof Image) { - val = _this.root().defs().pattern(0, 0, (pattern) => { - pattern.add(val) - }) + val = _this + .root() + .defs() + .pattern(0, 0, (pattern) => { + pattern.add(val) + }) } return val |