Sometimes you are the river...

Posted by Frederic Jean Fri, 23 Feb 2007 05:46:26 GMT

After my last attempt, I decided that it was very advantageous to me and my team to be able to augment DOM elements with functions that I wish was in the DOM APIs. So I started looking around to see how it was done and looked at the Prototype sources that are shipped with every single Rails project.

Now, Prototype is much maligned for it's interference with the DOM. To work around IE, they simply redefine the Element object and replace it with their own. This does cause problems when other frameworks are sharing the global object with Prototype. The big advantage though is that it allows Prototype to provide functions that are extremely useful, even if they aren't officially part of the DOM.

At this point, I don't plan to simply highjack the Element object, but I can certainly add methods to any returned element. This works under both IE and Firefox (to my great relief). I borrowed Prototype's $ function and are now using my own version instead of document.getElementById. This gives me the chance to intercept finding the element and to add the methods that I want or need on the fly. It's not quite elegant, and it does require a lot of code to be changed in order to take advantage of the new function. It's certainly worth a try though.

Trackbacks

Use the following link to trackback from your own site:
http://blog.fredjean.net/articles/trackback/75

Comments

Leave a response

Comments


(leave url/email »)