Thursday, August 18, 2005

454 Lines

454 Lines of code in the new final final version of the Javascript Calendar.

That's a lot.

But it's cross-browser, bug free, fast, sweet.

I have a new appreciation for how truly crappy IE is btw. The latest is that under certain times of year and cycles of the moon, you can't use .innerHTML, even on DIVs. So I had to create my year, month, and day containers with the DOM, and then, BEFORE I appended them to the document, I could fill in their content with .innerHTML. If I appended them first I'd get a runtime error. If I tried the += operator on an existing element, I'd get a runtime error.

Another special specialness that IE has brought us: You can't assign strings to events when creating DOM elements. In other words:

myelement.onmouseover = "alert('boo!');";

Doesn't work. No, you have to define functions:

myelement.onmouseover = function() { alert("boo!"); };

This isn't always bad of course. It can make longer strings a bit more readable. Say you wanted to pass in a value though, aka:

myelement.onmouseover = "MyArray[TWENTY_EIGHT].doSomething();";

Now what? TWENTY_EIGHT is out of scope when the function is fired, so you can't just blindly replace that with a function like the following:

myelement.onmouseover = function() { MyArray[TWENTY_EIGHT].doSomething(); };

So what do you do? Well... I got around it with attributes:

myelement.setAttribute("myIndex", 28);
myelement.onmouseover = function() {
MyArray[this.getAttribute("myIndex")].doSomething();
};

Yes, it's true. IE sucks.
Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?