Monthly Archives: July 2008

Back to Firefox 2

If you’re like me, you use Firebug a lot, like, all day long. Long gone are the days of resorting to alerts. The worst I’ll fall back to is using the YUI logger for IE. I’ve recently been having a lot of issues using Firefox 3, and Firebug. Firefox 3 has been pretty [...]
Tagged , | 1 Comment

Complex Javascript Event Handling: EventMediator

A large enterprise sized project I work on uses YUI library extensively, and events are a huge part of the rich front end we’re developing. What you start to learn quickly about UI events, is that dependencies between different events start to get very complicated very fast. When A depends on B, but [...]
Tagged , | 4 Comments

Subscribing to an image loaded event

I recently was working on something where I needed to swap the src of an image, but then perform some specific javascript AFTER the new image was loaded, namely resize the dimensions a little. This may seem pretty simple, but took me a little research, along with trial and error to get a working solution, so hopefully it helps someone else. I often use jQuery on my smaller projects, so I'll show how I accomplished this with that toolkit.
  1. First, I would need to listen to the load event of the image I was replacing the src of.
  2. Next, in order to trigger the handler, we need to actually change the src of the image
$('#my-image').load(function() { 
    //Logic for w/e here, resizing, etc.
}).attr('src', myNewImageSrc);
The code itself is really simple, but it took me a few to realize that jQuery solved the problem by simply letting us listen to the load event of the image, and count on it being fired when the src changes, and finishes loading.
Tagged , | Leave a comment