summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-04-22 22:16:36 +0200
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2017-04-22 22:16:36 +0200
commitab1c07e80bd21f2cdf773be238d4dd754db4e80a (patch)
treeb1386635a4e54f29eee8cfa41151fd930610c25e /src
parent03d25548fe99c87ed74e789b894e37a7fc6caf34 (diff)
downloadsvg.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.js42
-rw-r--r--src/doc.js13
-rw-r--r--src/element.js6
-rw-r--r--src/fx.js10
-rw-r--r--src/nested.js2
-rw-r--r--src/svg.js2
6 files changed, 41 insertions, 34 deletions
diff --git a/src/css.js b/src/css.js
index b5f2702..3ecb2b9 100644
--- a/src/css.js
+++ b/src/css.js
@@ -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
diff --git a/src/doc.js b/src/doc.js
index 6a48a6a..4192516 100644
--- a/src/doc.js
+++ b/src/doc.js
@@ -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() {
diff --git a/src/fx.js b/src/fx.js
index 7894b3e..b2b5d29 100644
--- a/src/fx.js
+++ b/src/fx.js
@@ -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
diff --git a/src/svg.js b/src/svg.js
index 775b6fa..0716a0a 100644
--- a/src/svg.js
+++ b/src/svg.js
@@ -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%',