diff options
author | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-04-22 22:16:36 +0200 |
---|---|---|
committer | Ulrich-Matthias Schäfer <ulima.ums@googlemail.com> | 2017-04-22 22:16:36 +0200 |
commit | ab1c07e80bd21f2cdf773be238d4dd754db4e80a (patch) | |
tree | b1386635a4e54f29eee8cfa41151fd930610c25e /src | |
parent | 03d25548fe99c87ed74e789b894e37a7fc6caf34 (diff) | |
download | svg.js-ab1c07e80bd21f2cdf773be238d4dd754db4e80a.tar.gz svg.js-ab1c07e80bd21f2cdf773be238d4dd754db4e80a.zip |
changed `style()` to `css()`
it now accepts array as input and returns object when no argument given (#517)
also removed sub-pixel offset fix
Diffstat (limited to 'src')
-rw-r--r-- | src/css.js | 42 | ||||
-rw-r--r-- | src/doc.js | 13 | ||||
-rw-r--r-- | src/element.js | 6 | ||||
-rw-r--r-- | src/fx.js | 10 | ||||
-rw-r--r-- | src/nested.js | 2 | ||||
-rw-r--r-- | src/svg.js | 2 |
6 files changed, 41 insertions, 34 deletions
@@ -1,22 +1,42 @@ SVG.extend(SVG.Element, { // Dynamic style generator - style: function(s, v) { + css: function(s, v) { + var t, i, ret = {} if (arguments.length == 0) { - // get full style - return this.node.style.cssText || '' + // get full style as object + this.node.style.cssText.split(/\s*;\s*/).filter(function(el) { return !!el.length }).forEach(function(el) { + t = el.split(/\s*:\s*/) + ret[t[0]] = t[1] + }) + return ret + } - } else if (arguments.length < 2) { - // apply every style individually if an object is passed - if (typeof s == 'object') { - for (v in s) this.style(v, s[v]) + if (arguments.length < 2) { + // get style properties in the array + if(Array.isArray(s)) { + for(i = s.length; i--;) { + ret[camelCase(s[i])] = this.node.style[camelCase(s[i])] + } + return ret + } - } else { - // act as a getter if the first and only argument is not an object + // get style for property + if(typeof s == 'string') { return this.node.style[camelCase(s)] } - } else { - this.node.style[camelCase(s)] = v === null || SVG.regex.isBlank.test(v) ? '' : v + // set styles in object + if(typeof s == 'object') { + for(i in s) { + // set empty string if null/undefined/'' was given + this.node.style[camelCase(i)] = (s[i] == null || SVG.regex.isBlank.test(s[i])) ? '' : s[i] + } + } + } + + // set style for property + if (arguments.length == 2) { + this.node.style[camelCase(s)] = (v == null || SVG.regex.isBlank.test(v)) ? '' : v } return this @@ -55,19 +55,6 @@ SVG.Doc = SVG.invent({ , parent: function() { return this.node.parentNode.nodeName == '#document' ? null : this.node.parentNode } - // Fix for possible sub-pixel offset. See: - // https://bugzilla.mozilla.org/show_bug.cgi?id=608812 - , spof: function(spof) { - var pos = this.node.getScreenCTM() - - if (pos) - this - .style('left', (-pos.e % 1) + 'px') - .style('top', (-pos.f % 1) + 'px') - - return this - } - // Removes the doc from the DOM , remove: function() { if(this.parent()) { diff --git a/src/element.js b/src/element.js index 24770b1..1e3dcb0 100644 --- a/src/element.js +++ b/src/element.js @@ -107,15 +107,15 @@ SVG.Element = SVG.invent({ } // Show element , show: function() { - return this.style('display', '') + return this.css('display', '') } // Hide element , hide: function() { - return this.style('display', 'none') + return this.css('display', 'none') } // Is element visible? , visible: function() { - return this.style('display') != 'none' + return this.css('display') != 'none' } // Return id on string conversion , toString: function() { @@ -235,7 +235,7 @@ SVG.FX = SVG.invent({ } for(i in s.styles){ - s.styles[i] = new SVG.MorphObj(this.target().style(i), s.styles[i]) + s.styles[i] = new SVG.MorphObj(this.target().css(i), s.styles[i]) } s.initialTransformation = this.target().matrixify() @@ -608,14 +608,14 @@ SVG.FX = SVG.invent({ } - // apply animation which has to be applied with style() + // apply animation which has to be applied with css() for(i in s.styles){ at = [i].concat(s.styles[i]).map(function(el){ return typeof el !== 'string' && el.at ? el.at(s.ease(self.pos), self.pos) : el }) - target.style.apply(target, at) + target.css.apply(target, at) } @@ -767,10 +767,10 @@ SVG.extend(SVG.FX, { return this } // Add animatable styles -, style: function(s, v) { +, css: function(s, v) { if (typeof s == 'object') for (var key in s) - this.style(key, s[key]) + this.css(key, s[key]) else this.add(s, v, 'styles') diff --git a/src/nested.js b/src/nested.js index f856e52..fff03d1 100644 --- a/src/nested.js +++ b/src/nested.js @@ -3,7 +3,7 @@ SVG.Nested = SVG.invent({ create: function() { this.constructor.call(this, SVG.create('svg')) - this.style('overflow', 'visible') + this.css('overflow', 'visible') } // Inherit from @@ -131,7 +131,7 @@ SVG.prepare = function() { // Create parser object SVG.parser = { body: body || document.documentElement - , draw: draw.style({ + , draw: draw.css({ opacity:0, position:'absolute', left:'-100%', |