diff options
author | Saivan <savian@me.com> | 2018-02-27 00:48:11 +1100 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-02-27 00:48:11 +1100 |
commit | bec7881979149425a9c1b894f4741413b28c8141 (patch) | |
tree | 3a496f834520925686af3a8059766b61b65be390 /src/image.js | |
parent | ec0a8aee0e21a93b22c255dae6768a9ff7b09e73 (diff) | |
download | svg.js-bec7881979149425a9c1b894f4741413b28c8141.tar.gz svg.js-bec7881979149425a9c1b894f4741413b28c8141.zip |
The first half of the library complies with Standard linting
This commit reformats the code so that it complies with the
standard linting style. Its currently a work in progress, but
it is meant to pave the way for linting in the build process
Diffstat (limited to 'src/image.js')
-rw-r--r-- | src/image.js | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/src/image.js b/src/image.js index 6f8ba5b..f9395eb 100644 --- a/src/image.js +++ b/src/image.js @@ -1,55 +1,57 @@ SVG.Image = SVG.invent({ // Initialize node - create: 'image' + create: 'image', // Inherit from -, inherit: SVG.Shape + inherit: SVG.Shape, // Add class methods -, extend: { + extend: { // (re)load image - load: function(url, callback) { + load: function (url, callback) { if (!url) return this var img = new window.Image() - SVG.on(img, 'load', function(e) { + SVG.on(img, 'load', function (e) { var p = this.parent(SVG.Pattern) // ensure image size - if (this.width() == 0 && this.height() == 0) + if (this.width() === 0 && this.height() === 0) { this.size(img.width, img.height) + } - if(p instanceof SVG.Pattern) { + if (p instanceof SVG.Pattern) { // ensure pattern size if not set - if (p.width() == 0 && p.height() == 0) + if (p.width() === 0 && p.height() === 0) { p.size(this.width(), this.height()) + } } - if(typeof callback == 'function') { + if (typeof callback === 'function') { callback.call(this, { - width: img.width - , height: img.height - , ratio: img.width / img.height - , url: url + width: img.width, + height: img.height, + ratio: img.width / img.height, + url: url }) } }, this) - SVG.on(img, 'load error', function() { + SVG.on(img, 'load error', function () { // dont forget to unbind memory leaking events SVG.off(img) }) return this.attr('href', (img.src = url), SVG.xlink) } - } + }, // Add parent method -, construct: { + construct: { // create image element, load image and set its size - image: function(source, callback) { - return this.put(new SVG.Image).size(0, 0).load(source, callback) + image: function (source, callback) { + return this.put(new SVG.Image()).size(0, 0).load(source, callback) } } }) |