[Dojo-interest] gfx Text setShape patch, and How do you change text content?

Hugh Winkler hughw at wellstorm.com
Sat Feb 17 19:32:37 MST 2007


Using the gfx Text object, I was trying to figure out how to change
the text value. The best I came up with was to do this:

myText.shape.text = newTextValue;
myText.setShape();

I don't know whether I'm abusing setShape() or not, but this seemed
the best way. However the svg implementation of Text.setShape creates
a new text node each time, and calls appendChild. So each time you
call setShape you accumulate textNodes. I think we want to replace the
text node, so here is my patch to do that. Advice appreciated on the
preferred way to change the text value!

Thanks,

Hugh



Index: C:/Documents and
Settings/hugh/workspace/witsml131/web/browser/js/dojo/src/gfx/svg.js
===================================================================
--- C:/Documents and
Settings/hugh/workspace/witsml131/web/browser/js/dojo/src/gfx/svg.js	(revision
7344)
+++ C:/Documents and
Settings/hugh/workspace/witsml131/web/browser/js/dojo/src/gfx/svg.js	(working
copy)
@@ -507,7 +507,7 @@
 		r.setAttribute("text-decoration", s.decoration);
 		r.setAttribute("rotate", s.rotated ? 90 : 0);
 		r.setAttribute("kerning", s.kerning ? "auto" : 0);
-		r.appendChild(document.createTextNode(s.text));
+		r.textContent = s.text;
 		return this;	// self
 	},
 	attach: function(rawNode){



-- 
Hugh Winkler
Wellstorm Development

http://www.wellstorm.com/
+1 512 694 4795 mobile (preferred)
+1 512 264 3998 office


More information about the Dojo-interest mailing list