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.

Bending the DOM to your will

Posted by Frederic Jean Thu, 15 Feb 2007 22:04:33 GMT

Update: I thought I was very clever and posted this before testing fully on IE... Problem is that IE doesn't implement the DOM objects as native JavaScript objects. As a result, you can't simply add methods to their prototypes. I'll keep looking for a solution though.

One of the biggest frustration around JavaScript development is the incompatibilities between different browsers. Internet Explorer is certainly one of the biggest culprit in that area with their not quite complete DOM implementation.

A good example is the Option constructor that is available on Firefox and other well behaved browser. It's an extremely convenient alternative to using the core DOM to build drop down boxes. It just didn't seem to be available on Internet Explorer. I therefore had 2 options:

  1. Do without. Use the raw DOM API or an innerHTML hack to build the options and add them to the drop down box.
  2. Implement it in my library so it would be available.

I chose option 2. I now check for the existence of the Option constructor and define it if it's not available.

Another example are areas where the DOM API haven't specified a method to remove all children of a node. It's easy enough to do with some looping, but it does get annoying to have to continually rewrite the code. One of the advantages of JavaScript is that the objects are never closed. This includes their prototype. As a result, I added a removeAllChildren function to the Node's prototype. I can now clean up portions of the DOM tree very effectively now.

JavaScript is a very powerful language, and you do not have to submit yourself to the limitations imposed on you by incomplete API implementations. You can always add what you need and bend the DOM to your will.

Still waiting

Posted by Frederic Jean Sat, 10 Feb 2007 12:16:18 GMT

Almost 8 months ago Mollie and I were notified that the CCAA had received our paperwork. We were LID (which stands for Logged In Date). We had our place in line, and all we could do now was wait and attend a few mandatory classes. We weren't too sure how long it would take to get our referral. We sure hopped that it would be well within a year.

But the wait times keeps dragging on. Mollie has been following different boards and discussion forums. I started looking at them too. And it dawned on us that it would take longer than we thought. And it keeps getting longer. Right now, we both believe that it is unlikely that we will get our referral and go to China this year. It's hard to deal with this for both of us. It breaks Mollie's heart to have to wait so long. It's hard on me to see the dates continually slipping. In many ways, getting Sophia is going to be the start for many, many good things for our little family.

One thing that really bugs me is that I always have the same question each time that I talk to one of my family members. "Did you get news about your little girl?" And I always have the same answer. "No. We will not hear anything until early 2008. Probably later." I know that they mean well. This adoption is a big part of our life. It is just a reminder that we do not have any control over the process at this point and that the wait just keeps going on. And I certainly wish that somehow they would remember that we will probably not get anything for a while.

Someday, we'll have a different answer to give. Actually, we'll be calling on both our land line and our cell phones, trying to reach as many people as we can in our great excitement. We'll be posting pictures and getting ready for what will be the biggest adventure of our life. In the mean time, all we can do is wait. So we wait.

Learning more about Javascript

Posted by Frederic Jean Wed, 07 Feb 2007 01:44:17 GMT

Yahoo! is making a few classes on Javascript available through their YUI Theater blog. The classes are given by Douglas Crockford, who is Yahoo!'s Javascript Architect. I took sometime this evening to go through the "Javascript Programming Language" presentation and learned a great deal about the language, which is going to be directly applicable to the work that I am currently doing at TransZap. I would recommend this presentation to anyone who is going to do extensive work using Javascript, which is essentially anyone doing Ajax or Web 2.0 work.