summaryrefslogtreecommitdiffstats
path: root/src/image.js
diff options
context:
space:
mode:
authorSaivan <savian@me.com>2018-02-27 00:48:11 +1100
committerSaivan <savian@me.com>2018-02-27 00:48:11 +1100
commitbec7881979149425a9c1b894f4741413b28c8141 (patch)
tree3a496f834520925686af3a8059766b61b65be390 /src/image.js
parentec0a8aee0e21a93b22c255dae6768a9ff7b09e73 (diff)
downloadsvg.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.js38
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)
}
}
})