1) CODE TITLE: TextFormatter
2) AUTHOR NAME/NOTES: Thomas Eding
3) DESCRIPTION: A simple class to help format strings within an element
4) URL TO CODE: http://trinithis.awardspace.com/Text...xtFormatter.js
Tested in IE6 and Fx2
Demo: http://trinithis.awardspace.com/Text...Formatter.html
How to use:
There are more methods than shown. Just look at the source code and look at the method names. Should be fairly obvious.Code:var tf = new TextFormatter(document.getElementById("theElement")); tf.print("This"); tf.println(" is"); tf.setFontFamily("monospace"); tf.println("a test!"); tf.setWidth(15); tf.setWidthAlign("left"); tf.print("x").print("y").println("f(x,y)"); //you can chain any of TextFormatter's methods like this tf.print(3.6).print(4.9).println(4.51); tf.setWidth(); //sets the width to normal if argument is <1 or absent
NOTE: The methods format(), formatNumber(), and newWrapper() are intended to be used indirectly through other methods.



Reply With Quote
I would suggest some way of avoiding doing newWrapper() after every modification, though -- it really only needs to be done if text has been output since the last newWrapper().

Bookmarks