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/elements/Svg.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/elements/Svg.js')
-rw-r--r-- | src/elements/Svg.js | 72 |
1 files changed, 47 insertions, 25 deletions
diff --git a/src/elements/Svg.js b/src/elements/Svg.js index 6172454..1326900 100644 --- a/src/elements/Svg.js +++ b/src/elements/Svg.js @@ -11,68 +11,90 @@ import Defs from './Defs.js' import { globals } from '../utils/window.js' export default class Svg extends Container { - constructor (node) { - super(nodeOrNew('svg', node), node) + + constructor ( node ) { + + super( nodeOrNew( 'svg', node ), node ) this.namespace() + } isRoot () { - return !this.node.parentNode || - !(this.node.parentNode instanceof globals.window.SVGElement) || - this.node.parentNode.nodeName === '#document' + + return !this.node.parentNode + || !( this.node.parentNode instanceof globals.window.SVGElement ) + || this.node.parentNode.nodeName === '#document' + } // Check if this is a root svg // If not, call docs from this element root () { - if (this.isRoot()) return this + + if ( this.isRoot() ) return this return super.root() + } // Add namespaces namespace () { - if (!this.isRoot()) return this.root().namespace() + + if ( !this.isRoot() ) return this.root().namespace() return this - .attr({ xmlns: ns, version: '1.1' }) - .attr('xmlns:xlink', xlink, xmlns) - .attr('xmlns:svgjs', svgjs, xmlns) + .attr( { xmlns: ns, version: '1.1' } ) + .attr( 'xmlns:xlink', xlink, xmlns ) + .attr( 'xmlns:svgjs', svgjs, xmlns ) + } // Creates and returns defs element defs () { - if (!this.isRoot()) return this.root().defs() - return adopt(this.node.getElementsByTagName('defs')[0]) || - this.put(new Defs()) + if ( !this.isRoot() ) return this.root().defs() + + return adopt( this.node.getElementsByTagName( 'defs' )[0] ) + || this.put( new Defs() ) + } // custom parent method - parent (type) { - if (this.isRoot()) { + parent ( type ) { + + if ( this.isRoot() ) { + return this.node.parentNode.nodeName === '#document' ? null - : adopt(this.node.parentNode) + : adopt( this.node.parentNode ) + } - return super.parent(type) + return super.parent( type ) + } clear () { + // remove children - while (this.node.hasChildNodes()) { - this.node.removeChild(this.node.lastChild) + while ( this.node.hasChildNodes() ) { + + this.node.removeChild( this.node.lastChild ) + } return this + } + } -registerMethods({ +registerMethods( { Container: { // Create nested svg document - nested: wrapWithAttrCheck(function () { - return this.put(new Svg()) - }) + nested: wrapWithAttrCheck( function () { + + return this.put( new Svg() ) + + } ) } -}) +} ) -register(Svg, 'Svg', true) +register( Svg, 'Svg', true ) |