aboutsummaryrefslogtreecommitdiffstats
path: root/src/css.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/css.js')
-rw-r--r--src/css.js42
1 files changed, 31 insertions, 11 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