Minor optimization.

This commit is contained in:
Paulo Gustavo Veiga 2012-05-12 15:28:04 -03:00
parent 873e635b9a
commit 8f05606449

View File

@ -40,27 +40,23 @@ web2d.peer.svg.TextPeer = new Class({
}, },
setText : function(text) { setText : function(text) {
var i = 0; // Remove all previous nodes ...
var childs = this._native.childNodes; while (this._native.firstChild) {
for (i = 0; i < childs.length; i++) { this._native.removeChild(this._native.firstChild);
Element.dispose(childs[i]);
} }
this._text = text; this._text = text;
var lines = text.split('\n'); if (text) {
var lines = text.split('\n');
lines.forEach(function(line) {
var tspan = window.document.createElementNS(this.svgNamespace, 'tspan');
tspan.setAttribute('dy', '1em');
tspan.setAttribute('x', this.getPosition().x);
var tspans = []; tspan.textContent = line.length == 0 ? " " : line;
lines.forEach(function(line) { this._native.appendChild(tspan);
}.bind(this));
var tspan = window.document.createElementNS(this.svgNamespace, 'tspan'); }
tspan.setAttribute('dy', '1em');
tspan.setAttribute('x', this.getPosition().x);
var tspanContent = window.document.createTextNode(line.length == 0 ? " " : line);
tspan.appendChild(tspanContent);
tspans.push(tspan);
this._native.appendChild(tspan);
}.bind(this));
}, },
getText : function() { getText : function() {
@ -73,10 +69,10 @@ web2d.peer.svg.TextPeer = new Class({
this._native.setAttribute('x', x); this._native.setAttribute('x', x);
// tspan must be positioned manually. // tspan must be positioned manually.
var tspans = this._native.childNodes; this._native.getElements('tspan').forEach(function(span) {
for (var i = 0; i < tspans.length; i++) { span.setAttribute('x', x);
tspans[i].setAttribute('x', x); });
}
}, },
getPosition : function() { getPosition : function() {