Short thoughts by David LeMieux
Lorem ipsum is a popular bit of filler text used in design and development. When a paragraph or space will be needed but the contents is not yet known, filler text is used in its place. "Lorem ipsum" is popular due to the fact that it doesn't mean anything while still looking like real text.
Recently, friend and fellow developer, Ben Rasmusen, was in search of a way to automatically place "lorem ipsum" text in to a form text field. He asked followers on Twitter to help him solve the problem. Curious, I decided to help. (More after the image)
A quick search revealed that many have tried to solve this problem and that it seems to be a difficult thing to acheive. Notwithstanding the hurdles, I decided to give it the old college try. Really, I was just curious and determined to find the answer. I had to know!
Eventually I found the activeElement javascript property. This property gives you the currently active/in-focus element, but it only works on some browsers and it is not officially part of ECMAScript. I also found that you can control focus of elements with the focus() and blur() methods. Like activeElement, these methods are different in each browser.
With this information I made some basic assumptions (not always a wise thing to do). If activeElement is available, the basic problem is solved; changing the value of the active element after some basic type checking is trivial. If not, you can assume that an element has been selected and therefore has focus. Assinging an "onblur" listener to that element and then forcing all elements to blur would cause that element to react. Since none of the other elements where in focus, causing them to blur would not actually change their state and (this is one of those dangerous assumptions) would not receive a dispatched event.
One major roadblock in all of this is that the element may already have an onblur event listener. In that case, it is neccessary to store the old data and then reapply it after execution.
What I ended up with, in expanded format, was this: lipsum-bookmarklet-expanded.js [JavaScript] (I appologize for not putting the code in the post, but I haven't gotten arround to adding that functionality. Its on my list).
Here is the bookmarklet: Lorem Ipsum - after adding the link to your bookmarks toolbar go to a registration form (or the contact page on this site), click on a text field, then hit the newly created bookmark. It should add text to the text box.
I was, at first, pretty happy with my results. That is until I tried it in a browser other than FireFox 3 beta 5. And that is where I am stuck. I, too, now make an appeal to those smarter than me to help solve this problem. Perhaps it isn't something that can be done, but I like to remain optimistic and engaged in solution finding.
In the mean time, here are some more Lorem Ipsum resources:
Lipsum.com - history, facts, and lorem ipsum generation.
Dummy Lipsum 2.3.0 - a lorem ipsum FireFox extension.
If you would like to help in this quest for knowlege, contact me on this site or send a twitter message my way. http://twitter.com/lemieuxster