Unobtrusive JavaScript on Dynamic Content

Posted by Jimmy'z on August 22, 2009

I’m working on a web application outside of my FamilySearch work that requires a lot of AJAX behavior. I have been using Prototype with Rails’ Prototype Helpers, but this is beginning to become a unwieldy.

The content I load can get very large with TONS of inline JavaScript, so in an effort to trim down the html and improve performance, I’m beginning to use Unobtrusive JavaScript methods. While I do this, I’m also doing a migration to jQuery.

I had seen a lot of code examples that looked like this:

jQuery(function($) {
  $('a.sidenote').click(function() {
    var href = $(this).attr('href');
    window.open(href, 'popup',
      'height=500,width=400,toolbar=no');
    return false;
  });
});

This seemed to work for event listening on elements that were loaded as the page loads, but I have lots of content that is loaded via AJAX methods after the document loads. I needed something that would bind the listeners not only at the time the document loaded, but would continue to bind event listeners to new content that matched the given selectors.

I later discovered the “live” method. This does exactly what I want it to do. Instead of just registering a click, I call live, so the above example would change to:

jQuery(function($) {
  $('a.sidenote').live('click',function() {
    var href = $(this).attr('href');
    window.open(href, 'popup',
      'height=500,width=400,toolbar=no');
    return false;
  });
});

This doesn’t require a big change in code, but the approach is much more powerful and truly allows you to make your JavaScript unobtrusive.

Windows XP PATH not interpreting environment variables 1

Posted by Jimmy'z on December 23, 2008

This one took me a while to figure out. I have my PATH environment variable set up to include other paths that are also defined by an environment variable. For example, I have Maven set up in the following way:


M2_HOME = C:\Program Files\Apache Software Foundation\apache-maven-2.0.9
M2 = %M2_HOME%\bin
PATH = %M2%;[a whole lot of other dirs]

Today, I tried to run a Maven build, and it wasn’t recognizing the maven\bin in my path. When I did an echo on my path, the path had the following:

%M2%;C:\Program Files...

instead of

C:\Program Files\Apache Software Foundation\apache-maven-2.0.9\bin

which would be the value of %M2%

When I did:

echo %M2%

I got the full path C:\Program Files\Apache Software Foundation\apache-maven-2.0.9\bin

What was going on?

Well, apparently, Windows has a limit on the size of your path and when it hits that limit, it just stops interpreting your %VARIABLES% set in the path.

So, the solution is to either reorganize all of your files into more succinctly named directories, or remove some of the dirs from your path.

Thanks M$. Hope this helps someone else.

my new blackberry pearl 3

Posted by Jimmy'z on April 30, 2008

I just got a new blackberry pearl for work. So far I really like it. It is amazing that you can type with such a small keyboard.

I’m writing this with my phone to practice typing with this little keyboard.

Maybe I’ll start to use twitter for more practice. Does anyone know of a good way to tweet from a blackberry?

[Gmail Tip] is:unread in:inbox 3

Posted by Jimmy'z on April 12, 2008

If you find yourself falling behind in getting all of your emails read, like I have in the past week, you may find it useful to put the following in your Gmail search:

is:unread in:inbox

This will filter your messages to just those that are unread and in your inbox. Pretty cool. This help a lot for me because I have a lot of filters on my mail that mark some mailing list emails as ‘read’ and put others under different labels without marking them as read.

Amazing Wii Remote Projects 1

Posted by Jimmy'z on December 24, 2007

Wii RemoteI just had to post this. Johnny Lee is doing amazing things with a Wii Remote. One of my favorites is the video on head tracking for desktop vr displays. It’s incredible! When you have a minute, it’s worth checking out.

[Wii Remote photo taken by Dave Minnich]

Just got Grand Central! 17

Posted by Jimmy'z on August 03, 2007

I finally made it into the Beta of Grand Central! So far it seems really cool. I have 5 invites that I can give away to the first people who comment on this post.

If you haven’t heard about Grand Central, it’s a service that gives you a new phone number that you can use to route calls to any of your other phones. It offers Spam call filtering, a cool online voice mailbox, and click2call features.

One of the coolest features that I’ve seen is being able to seamlessly transfer a call from one phone line to another. So, say that someone calls you while you’re on the road, and you’re just getting home. You answer the call, begin your conversation, walk through your front door, press your * key on your phone and your home phone then rings. You pick up your home phone and continue your conversation on your land-line without using up more of your cell phone minutes!

It appears that most of the features will remain free after the Beta period, except for the click2call features, which will end up charging a per-minute fee.

Who else wants a Grand Central account?

Hacked! 1

Posted by Jimmy'z on August 03, 2007

I came to my blog today and saw that my first post showing was May 25, and I though, “Oh snap! I’ve been hacked!” Which is what Phil Burns thought he had experienced earlier this week when his blog’s database rolled back to April.

Then I realized I just hadn’t written anything since then and time has blown by too fast. I guess that means that I’ve been really busy.