A notch above a monkey

Auto-grow TEXTAREA

Update 6.8.2009: This post is old and somewhat obsolete, but has been kept alive by commentators. Hence I posted an updated version of the script in comments.

Fry recently mentioned a TEXTAREA improvement he found. As you type your text in the box, it grows in length as needed to avoid having to deal with scroll bars.

I liked the idea and went to create my own version. Making it work in Internet Explorer and Firefox was literally a matter of seconds. All you really need to do is compare elements clientHeight with its scrollHeight on key presses and increment rows attribute when former is smaller than later.

But supporting Opera and Safari has proven to be an insurmountable task for now. They simply don’t seem to update any property that could reliably be used for measuring the height of the text (but would love to be proven wrong).

You can try a demo , which also doubles as a test environment for reading interesting attributes on the fly (updates are done with mouse over input box).

Random bits of observation:

  • scrollHeight is always bigger than clientHeight in Opera. Hence the need to ignore it using its unique fingerprint.
  • I didn’t try to work out the length of the text by trying to count the number of lines (using \n ) and the length of each of them. Proportional fonts prevent any such reasonable guess.
  • I didn’t try to limit the growth of the box to the boundaries of the screen. I find page scroll bars the least annoying when scroll bars can’t be avoided. It’s a personal choice though.

Accessible DHTML and other bits

I’ve been neglecting my blog recently. There was no shortage of news, but somehow I didn’t feel like writing. My mind is preoccupied with other things and where the hell is the cold and wet summer everyone promised?

Google announced accessible web search for the visually impaired. I see it as a great step in creating an accessible web search for everyone.

Najdi.si is testing a slovenian version of Google maps, which obviously can’t be more accurate than its source data, but works very well nevertheless.

But I’ve been most pleased to discover something else. I gave a talk recently and we spent quite some time discussing AJAX and Javascript accessibility issues. I wish I knew back then about this .

Not only is there a draft of a specification for making widgets accessible, we even got a test environment with Firefox 1.5. I’ve only had the time to scan through specification, so my view should be taken with a big pinch of salt, but my first impression is definitely positive. We’ll see how it develops after I had time to digest it and make a few tests.

Remembering parts of a page

Every now and then, but especially when I build pages that combine index of images together with a preview of one of them, I wish there was a way to tell a browser to remember a part of a current page and apply it at appropriate place on the next one from the same domain which also has same ID.

The gist of a problem is that I sometimes want bookmark-ability of separate pages without throwing away a product of an expensive operation. I want my cake and eat it too.

This is impossible, since there’s no way to actually store DOM objects and I’m not even sure it’s a good idea. Nevertheless, I certainly do miss the feature.