From 62de7d0a1b994b69032a759b796b486e6bc382e3 Mon Sep 17 00:00:00 2001 From: Saivan Date: Sun, 25 Nov 2018 16:21:53 +1300 Subject: 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 --- src/elements/Mask.js | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) (limited to 'src/elements/Mask.js') diff --git a/src/elements/Mask.js b/src/elements/Mask.js index 8dfffd6..523b9de 100644 --- a/src/elements/Mask.js +++ b/src/elements/Mask.js @@ -4,54 +4,72 @@ import Container from './Container.js' import baseFind from '../modules/core/selector.js' export default class Mask extends Container { + // Initialize node - constructor (node) { - super(nodeOrNew('mask', node), node) + constructor ( node ) { + + super( nodeOrNew( 'mask', node ), node ) + } // Unmask all masked elements and remove itself remove () { + // unmask all targets - this.targets().forEach(function (el) { + this.targets().forEach( function ( el ) { + el.unmask() - }) + + } ) // remove mask from parent return super.remove() + } targets () { - return baseFind('svg [mask*="' + this.id() + '"]') + + return baseFind( 'svg [mask*="' + this.id() + '"]' ) + } + } -registerMethods({ +registerMethods( { Container: { - mask: wrapWithAttrCheck(function () { - return this.defs().put(new Mask()) - }) + mask: wrapWithAttrCheck( function () { + + return this.defs().put( new Mask() ) + + } ) }, Element: { // Distribute mask to svg element - maskWith (element) { + maskWith ( element ) { + // use given mask or create a new one var masker = element instanceof Mask ? element - : this.parent().mask().add(element) + : this.parent().mask().add( element ) // apply mask - return this.attr('mask', 'url("#' + masker.id() + '")') + return this.attr( 'mask', 'url("#' + masker.id() + '")' ) + }, // Unmask element unmask () { - return this.attr('mask', null) + + return this.attr( 'mask', null ) + }, masker () { - return this.reference('mask') + + return this.reference( 'mask' ) + } } -}) +} ) -register(Mask) +register( Mask ) -- cgit v1.2.3