2 * (C) 2007 Andrew Gwozdziewycz <apgwoz@gmail.com>
3 * VERSION: 0.1, Released under an MIT License.
4 * URL: http://www.apgwoz.com/textfit/
6 function textFit(node, minfs, maxfs, width, height) {
7 var fits = function(sz) {
8 node.style.fontSize = sz + 'px';
9 return node.offsetWidth <= width && node.offsetHeight <= height;
11 var hfs = maxfs - minfs;
12 var tst = minfs + Math.ceil(hfs / 2);
13 var opsz = node.style.fontSize;
15 while ((hfs/2) >= 1) {
23 tst = minfs + Math.ceil(hfs/2);
25 opsz = fits(maxfs) ? maxfs: minfs;
26 node.style.fontSize = opsz + 'px';