diff options
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/core/attr.js | 11 | ||||
-rw-r--r-- | src/modules/core/event.js | 26 | ||||
-rw-r--r-- | src/modules/core/poly.js | 8 | ||||
-rw-r--r-- | src/modules/optional/arrange.js | 16 | ||||
-rw-r--r-- | src/modules/optional/class.js | 4 | ||||
-rw-r--r-- | src/modules/optional/data.js | 8 | ||||
-rw-r--r-- | src/modules/optional/memory.js | 4 | ||||
-rw-r--r-- | src/modules/optional/sugar.js | 8 | ||||
-rw-r--r-- | src/modules/optional/transform.js | 14 |
9 files changed, 53 insertions, 46 deletions
diff --git a/src/modules/core/attr.js b/src/modules/core/attr.js index 52c10a0..d54b235 100644 --- a/src/modules/core/attr.js +++ b/src/modules/core/attr.js @@ -39,9 +39,11 @@ export default function attr (attr, val, ns) { } else if (val == null) { // act as a getter if the first and only argument is not an object val = this.node.getAttribute(attr) - return val == null ? defaults[attr] - : isNumber.test(val) ? parseFloat(val) - : val + return val == null + ? defaults[attr] + : isNumber.test(val) + ? parseFloat(val) + : val } else { // Loop through hooks and execute them to convert value val = hooks.reduce((_val, hook) => { @@ -67,7 +69,8 @@ export default function attr (attr, val, ns) { } } else { // set given attribute on node - typeof ns === 'string' ? this.node.setAttributeNS(ns, attr, val.toString()) + typeof ns === 'string' + ? this.node.setAttributeNS(ns, attr, val.toString()) : this.node.setAttribute(attr, val.toString()) } diff --git a/src/modules/core/event.js b/src/modules/core/event.js index 976e13d..3594fc4 100644 --- a/src/modules/core/event.js +++ b/src/modules/core/event.js @@ -26,10 +26,10 @@ export function clearEvents (instance) { // Add event binder in the SVG namespace export function on (node, events, listener, binding, options) { - var l = listener.bind(binding || node) - var instance = makeInstance(node) - var bag = getEvents(instance) - var n = getEventTarget(instance) + const l = listener.bind(binding || node) + const instance = makeInstance(node) + const bag = getEvents(instance) + const n = getEventTarget(instance) // events can be an array of events or a string of events events = Array.isArray(events) ? events : events.split(delimiter) @@ -40,8 +40,8 @@ export function on (node, events, listener, binding, options) { } events.forEach(function (event) { - var ev = event.split('.')[0] - var ns = event.split('.')[1] || '*' + const ev = event.split('.')[0] + const ns = event.split('.')[1] || '*' // ensure valid object bag[ev] = bag[ev] || {} @@ -57,9 +57,9 @@ export function on (node, events, listener, binding, options) { // Add event unbinder in the SVG namespace export function off (node, events, listener, options) { - var instance = makeInstance(node) - var bag = getEvents(instance) - var n = getEventTarget(instance) + const instance = makeInstance(node) + const bag = getEvents(instance) + const n = getEventTarget(instance) // listener can be a function or a number if (typeof listener === 'function') { @@ -71,9 +71,9 @@ export function off (node, events, listener, options) { events = Array.isArray(events) ? events : (events || '').split(delimiter) events.forEach(function (event) { - var ev = event && event.split('.')[0] - var ns = event && event.split('.')[1] - var namespace, l + const ev = event && event.split('.')[0] + const ns = event && event.split('.')[1] + let namespace, l if (listener) { // remove listener reference @@ -122,7 +122,7 @@ export function off (node, events, listener, options) { } export function dispatch (node, event, data, options) { - var n = getEventTarget(node) + const n = getEventTarget(node) // Dispatch event if (event instanceof globals.window.Event) { diff --git a/src/modules/core/poly.js b/src/modules/core/poly.js index d96d1bc..d422028 100644 --- a/src/modules/core/poly.js +++ b/src/modules/core/poly.js @@ -19,9 +19,11 @@ export function move (x, y) { // Plot new path export function plot (p) { - return (p == null) ? this.array() - : this.clear().attr('points', typeof p === 'string' ? p - : (this._array = new PointArray(p))) + return (p == null) + ? this.array() + : this.clear().attr('points', typeof p === 'string' + ? p + : (this._array = new PointArray(p))) } // Set element size to given width and height diff --git a/src/modules/optional/arrange.js b/src/modules/optional/arrange.js index 30151c1..9aaeef1 100644 --- a/src/modules/optional/arrange.js +++ b/src/modules/optional/arrange.js @@ -23,8 +23,8 @@ export function prev () { // Send given element one step forward export function forward () { - var i = this.position() - var p = this.parent() + const i = this.position() + const p = this.parent() // move node one step forward p.add(this.remove(), i + 1) @@ -34,8 +34,8 @@ export function forward () { // Send given element one step backward export function backward () { - var i = this.position() - var p = this.parent() + const i = this.position() + const p = this.parent() p.add(this.remove(), i ? i - 1 : 0) @@ -44,7 +44,7 @@ export function backward () { // Send given element all the way to the front export function front () { - var p = this.parent() + const p = this.parent() // Move node forward p.add(this.remove()) @@ -54,7 +54,7 @@ export function front () { // Send given element all the way to the back export function back () { - var p = this.parent() + const p = this.parent() // Move node back p.add(this.remove(), 0) @@ -67,7 +67,7 @@ export function before (element) { element = makeInstance(element) element.remove() - var i = this.position() + const i = this.position() this.parent().add(element, i) @@ -79,7 +79,7 @@ export function after (element) { element = makeInstance(element) element.remove() - var i = this.position() + const i = this.position() this.parent().add(element, i + 1) diff --git a/src/modules/optional/class.js b/src/modules/optional/class.js index b08c82b..4e544be 100644 --- a/src/modules/optional/class.js +++ b/src/modules/optional/class.js @@ -3,7 +3,7 @@ import { registerMethods } from '../../utils/methods.js' // Return array of classes on the node export function classes () { - var attr = this.attr('class') + const attr = this.attr('class') return attr == null ? [] : attr.trim().split(delimiter) } @@ -15,7 +15,7 @@ export function hasClass (name) { // Add class to the node export function addClass (name) { if (!this.hasClass(name)) { - var array = this.classes() + const array = this.classes() array.push(name) this.attr('class', array.join(' ')) } diff --git a/src/modules/optional/data.js b/src/modules/optional/data.js index 9986c3d..00bb8ea 100644 --- a/src/modules/optional/data.js +++ b/src/modules/optional/data.js @@ -24,9 +24,11 @@ export function data (a, v, r) { } } else { this.attr('data-' + a, - v === null ? null - : r === true || typeof v === 'string' || typeof v === 'number' ? v - : JSON.stringify(v) + v === null + ? null + : r === true || typeof v === 'string' || typeof v === 'number' + ? v + : JSON.stringify(v) ) } diff --git a/src/modules/optional/memory.js b/src/modules/optional/memory.js index 6478367..459dcf1 100644 --- a/src/modules/optional/memory.js +++ b/src/modules/optional/memory.js @@ -4,7 +4,7 @@ import { registerMethods } from '../../utils/methods.js' export function remember (k, v) { // remember every item in an object individually if (typeof arguments[0] === 'object') { - for (var key in k) { + for (const key in k) { this.remember(key, k[key]) } } else if (arguments.length === 1) { @@ -23,7 +23,7 @@ export function forget () { if (arguments.length === 0) { this._memory = {} } else { - for (var i = arguments.length - 1; i >= 0; i--) { + for (let i = arguments.length - 1; i >= 0; i--) { delete this.memory()[arguments[i]] } } diff --git a/src/modules/optional/sugar.js b/src/modules/optional/sugar.js index 13806f1..d4c3da5 100644 --- a/src/modules/optional/sugar.js +++ b/src/modules/optional/sugar.js @@ -6,7 +6,7 @@ import Point from '../../types/Point.js' import SVGNumber from '../../types/SVGNumber.js' // Define list of available attributes for stroke and fill -var sugar = { +const sugar = { stroke: [ 'color', 'width', 'opacity', 'linecap', 'linejoin', 'miterlimit', 'dasharray', 'dashoffset' ], fill: [ 'color', 'opacity', 'rule' ], prefix: function (t, a) { @@ -16,8 +16,8 @@ var sugar = { // Add sugar for fill and stroke ;[ 'fill', 'stroke' ].forEach(function (m) { - var extension = {} - var i + const extension = {} + let i extension[m] = function (o) { if (typeof o === 'undefined') { @@ -104,7 +104,7 @@ registerMethods([ 'Element', 'Runner' ], { registerMethods('radius', { // Add x and y radius radius: function (x, y = x) { - var type = (this._element || this).type + const type = (this._element || this).type return type === 'radialGradient' ? this.attr('r', new SVGNumber(x)) : this.rx(x).ry(y) diff --git a/src/modules/optional/transform.js b/src/modules/optional/transform.js index 68455ed..d8e7381 100644 --- a/src/modules/optional/transform.js +++ b/src/modules/optional/transform.js @@ -10,11 +10,11 @@ export function untransform () { // merge the whole transformation chain into one matrix and returns it export function matrixify () { - var matrix = (this.attr('transform') || '') + const matrix = (this.attr('transform') || '') // split transformations .split(transforms).slice(0, -1).map(function (str) { // generate key => value pairs - var kv = str.trim().split('(') + const kv = str.trim().split('(') return [ kv[0], kv[1].split(delimiter) .map(function (str) { @@ -37,8 +37,8 @@ export function matrixify () { // add an element to another parent without changing the visual representation on the screen export function toParent (parent, i) { if (this === parent) return this - var ctm = this.screenCTM() - var pCtm = parent.screenCTM().inverse() + const ctm = this.screenCTM() + const pCtm = parent.screenCTM().inverse() this.addTo(parent, i).untransform().transform(pCtm.multiply(ctm)) @@ -54,7 +54,7 @@ export function toRoot (i) { export function transform (o, relative) { // Act as a getter if no object was passed if (o == null || typeof o === 'string') { - var decomposed = new Matrix(this).decompose() + const decomposed = new Matrix(this).decompose() return o == null ? decomposed : decomposed[o] } @@ -64,8 +64,8 @@ export function transform (o, relative) { } // The user can pass a boolean, an Element or an Matrix or nothing - var cleanRelative = relative === true ? this : (relative || false) - var result = new Matrix(cleanRelative).transform(o) + const cleanRelative = relative === true ? this : (relative || false) + const result = new Matrix(cleanRelative).transform(o) return this.attr('transform', result) } |