diff options
author | Saivan <savian@me.com> | 2018-11-25 16:21:53 +1300 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-11-25 16:21:53 +1300 |
commit | 62de7d0a1b994b69032a759b796b486e6bc382e3 (patch) | |
tree | 112b19f2903b4dc5b4cf61ebef0d021c6ca2f14d /src/modules/optional/arrange.js | |
parent | 2b37d7ba5b4267b39c86f9aba5fb14a1b376e846 (diff) | |
download | svg.js-62de7d0a1b994b69032a759b796b486e6bc382e3.tar.gz svg.js-62de7d0a1b994b69032a759b796b486e6bc382e3.zip |
Changed the esLint rules to avoid silly ternary operators, and to let code breathe!
This commit modifies some of the eslint rules, to allow our code to be a little bit more
readable. This came about because we had a particularly pesky problem, where the code
was indenting ternary operators. This fixes that, and makes it easy to add new rules
to eslint as we please in the future.
Changes
=======
- Rebuilt the library with new eslint rules
- Changed the eslintrc file to a yaml file by default
Diffstat (limited to 'src/modules/optional/arrange.js')
-rw-r--r-- | src/modules/optional/arrange.js | 82 |
1 files changed, 57 insertions, 25 deletions
diff --git a/src/modules/optional/arrange.js b/src/modules/optional/arrange.js index 6ce2eea..51e8605 100644 --- a/src/modules/optional/arrange.js +++ b/src/modules/optional/arrange.js @@ -3,109 +3,141 @@ import { registerMethods } from '../../utils/methods.js' // Get all siblings, including myself export function siblings () { + return this.parent().children() + } // Get the curent position siblings export function position () { - return this.parent().index(this) + + return this.parent().index( this ) + } // Get the next element (will return null if there is none) export function next () { + return this.siblings()[this.position() + 1] + } // Get the next element (will return null if there is none) export function prev () { + return this.siblings()[this.position() - 1] + } // Send given element one step forward export function forward () { + var i = this.position() + 1 var p = this.parent() // move node one step forward - p.removeElement(this).add(this, i) + p.removeElement( this ).add( this, i ) // make sure defs node is always at the top - if (typeof p.isRoot === 'function' && p.isRoot()) { - p.node.appendChild(p.defs().node) + if ( typeof p.isRoot === 'function' && p.isRoot() ) { + + p.node.appendChild( p.defs().node ) + } return this + } // Send given element one step backward export function backward () { + var i = this.position() - if (i > 0) { - this.parent().removeElement(this).add(this, i - 1) + if ( i > 0 ) { + + this.parent().removeElement( this ).add( this, i - 1 ) + } return this + } // Send given element all the way to the front export function front () { + var p = this.parent() // Move node forward - p.node.appendChild(this.node) + p.node.appendChild( this.node ) // Make sure defs node is always at the top - if (typeof p.isRoot === 'function' && p.isRoot()) { - p.node.appendChild(p.defs().node) + if ( typeof p.isRoot === 'function' && p.isRoot() ) { + + p.node.appendChild( p.defs().node ) + } return this + } // Send given element all the way to the back export function back () { - if (this.position() > 0) { - this.parent().removeElement(this).add(this, 0) + + if ( this.position() > 0 ) { + + this.parent().removeElement( this ).add( this, 0 ) + } return this + } // Inserts a given element before the targeted element -export function before (element) { - element = makeInstance(element) +export function before ( element ) { + + element = makeInstance( element ) element.remove() var i = this.position() - this.parent().add(element, i) + this.parent().add( element, i ) return this + } // Inserts a given element after the targeted element -export function after (element) { - element = makeInstance(element) +export function after ( element ) { + + element = makeInstance( element ) element.remove() var i = this.position() - this.parent().add(element, i + 1) + this.parent().add( element, i + 1 ) return this + } -export function insertBefore (element) { - element = makeInstance(element) - element.before(this) +export function insertBefore ( element ) { + + element = makeInstance( element ) + element.before( this ) + } -export function insertAfter (element) { - element = makeInstance(element) - element.after(this) +export function insertAfter ( element ) { + + element = makeInstance( element ) + element.after( this ) + } -registerMethods('Dom', { +registerMethods( 'Dom', { siblings, position, next, prev, forward, backward, front, back, before, after -}) +} ) |