aboutsummaryrefslogtreecommitdiffstats
path: root/src/element.js
diff options
context:
space:
mode:
authorwout <wout@impinc.co.uk>2012-12-21 17:28:17 +0100
committerwout <wout@impinc.co.uk>2012-12-21 17:28:17 +0100
commit5e4f748abffe48305e3d112e683d71cbec5155b3 (patch)
tree3c283536ea906a9260946168f6ad7b3891aa4f58 /src/element.js
parentb1516b2580dbdffd5ee68c75d4eb769b52faa100 (diff)
downloadsvg.js-5e4f748abffe48305e3d112e683d71cbec5155b3.tar.gz
svg.js-5e4f748abffe48305e3d112e683d71cbec5155b3.zip
Streamlined code
Diffstat (limited to 'src/element.js')
-rw-r--r--src/element.js40
1 files changed, 36 insertions, 4 deletions
diff --git a/src/element.js b/src/element.js
index 87ae198..981f9a0 100644
--- a/src/element.js
+++ b/src/element.js
@@ -2,6 +2,8 @@
SVG.Element = function Element(n) {
this.node = n;
this.attrs = {};
+
+ this._s = ('size family weight stretch variant style').split(' ');
};
// Add element-specific functions
@@ -34,18 +36,38 @@ SVG.extend(SVG.Element, {
// set svg element attribute
attr: function(a, v, n) {
-
if (arguments.length < 2) {
if (typeof a == 'object')
for (v in a) this.attr(v, a[v]);
+
+ else if (this._isStyle(a))
+ return a == 'text' ?
+ this.content :
+ a == 'leading' ?
+ this[a] :
+ this.style[a];
+
else
return this.attrs[a];
+ } else if (this._isStyle(a)) {
+ a == 'text' ?
+ this.text(v) :
+ a == 'leading' ?
+ this[a] = v :
+ this.style[a] = v;
+
+ this.text(this.content);
+
} else {
this.attrs[a] = v;
- n != null ?
- this.node.setAttributeNS(n, a, v) :
- this.node.setAttribute(a, v);
+ if (a == 'x' && this._isText())
+ for (var i = this.lines.length - 1; i >= 0; i--)
+ this.lines[i].attr(a, v);
+ else
+ n != null ?
+ this.node.setAttributeNS(n, a, v) :
+ this.node.setAttribute(a, v);
}
@@ -92,6 +114,16 @@ SVG.extend(SVG.Element, {
e = e.parent;
return e;
+ },
+
+ // private: is this text style
+ _isStyle: function(a) {
+ return typeof a == 'string' && this._isText() ? (/^font|text|leading/).test(a) : false;
+ },
+
+ // private: element type tester
+ _isText: function() {
+ return this instanceof SVG.Text;
}
});