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.

Genealogy People to Follow on Twitter 2

Posted by Jimmy'z on January 22, 2009

This is my list of genealogy industry people I follow in Twitter:

Genealogists:

Do you know of anyone else I should be following? Please comment.

[Update 3-17-2009]

Individuals and companies listed here were discovered largely from browsing “Follow” and “Follower” lists throughout the Twitter network; and by identifying individuals that I have worked for (paulballen), associated with via the FamilySearch Developers Network, or met during various family history conferences. I also subscribe to a #genealogy hash-tag feed to find other individuals that post about genealogy.

Some Twitter profiles were discovered from TamuraJones‘ “Follow List” based on the following tip: http://twitter.com/TamuraJones/status/1124553358

How to Get Hooked on Twitter

Posted by Jimmy'z on January 16, 2009

I started using Twitter on the 25th of November, 2008. Before then, I thought Twitter was an immense waste of time. I finally saw the light, joined, and have become a huge fan.

Here are a few things I did to help me get hooked on Twitter.

1. Used the Gmail address book finder from the “Find People” link at the top. This helped me connect quickly with about 15 friends I didn’t even know used Twitter.

2. Found more friends to follow by exploring my friends’ “Following” lists.

3. Installed TweetDeck and Twitterberry. TweetDeck makes posting updates to your timeline really easy. It also has a handy URL shortener and gives you fast Desktop notification of your friends’ updates. Twitterberry allows you to easily give updates while you are on the go without needing to use SMS.

4. Began tracking my links with Tr.im. Tr.im is a link shortening service that will give you click stats on all of the links you post. These numbers will begin to show you the power of Twitter as a broadcast medium. Think nobody is listening because they don’t reply? Tr.im will show you that people actually do care about what you post.

5. Began posting regularly, although I still go through dry spells at time.

Hopefully this post will help other Twitter newbies more effectively use Twitter.

What have you done to get hooked on Twitter?

Any WordPress plug-ins I should be aware of? Other tools?

Windows XP PATH not interpreting environment variables

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.

In Case You Missed MerbCamp

Posted by Jimmy'z on November 26, 2008

I’m working on a long post about Merb, but I figured I’d post a link to MerbCamp videos from the event in October. I was unable to attend, so these videos are really, really nice to be able to watch.

It also looks like they were able to stream some of the event live, and people participated in the conversations over IRC. Way cool.

I’ve now watched almost every video posted on the site. My favorite videos include:

  • Keynote by Ezra Zygmuntowicz – Ezra reviews the core tenets of Merb and introduces Nanite. Nanite is a really cool library for scaling the backends of web apps. Basically, when you build a web app, you want to be able to respond to the browser quickly. However, some tasks take some power to process, so you can kick these tasks out to Nanite Agents. You can have as many machines running as nanite agents as you want. They can be located anywhere, and can be added as needed. Very cool.
  • MerbSlices by Daniel Neighman – This is something I’ve wanted to see in Rails and other frameworks for a long time. Basically, it provides a way to build reusable applications. So, I have frequently had clients ask if I could just add a forum, a blog, or some kind of CMS to their site. Integrating authentication and user accounts across a custom site to a forum (like vBulletin) or a blog (like WordPress) is a real pain. If a forum slice or a blog slice would be a great mixin to a custom site.
  • Using Multiple Databases with Merb by Wesley Beary – Wesley talks about an experimental site that he’s got on Github that uses CouchDB and a RDBMS together. As I mentioned in a previous post, CouchDB is one of the newer technologies that I’m following. Pretty cool. I wouldn’t recommend sharing images though like he talks about in his presentation just for the reason that the port may be blocked on some networks. I’m sure there are other security implications as well.
  • jQuery on Merb by Yehuda Katz – Yehuda shows some good examples of how to get by in life without JavaScript helpers, like the ones we often rely on in Rails. This was also a good introduction to jQuery.
  • Learning from Django by Edward O’Connor – A good presentation on similarities between Django and Merb. Fun to learn about why Django is cool.
  • Keynote by Yehuda Katz – Yehuda talks about future goals for Merb and why Rubyists don’t need to be ashamed about Ruby.

I have to admit that I was disappointed in the “From Rails to Merb” video. While the discussion was interesting, I was really hoping someone would address good strategies for migrating a site to Merb. Oh well.

Overall, there is some great content at the MerbCamp site, and this would have been a very fun event to attend.

So THIS is Twitter… 4

Posted by Jimmy'z on November 25, 2008

Although I consider myself a pretty tech savvy guy, I’m not as up to date on Internet social life. Today, I updated my status on my Facebook account for the first time ever, and then I thought, Oh, I bet that is what Twitter is really all about.

I visited Twitter and lo and behold, a new video there that explains Twitter in plain English. I never really grokked Twitter, even though I knew what the Fail Whale was. I guess I’m starting to get it now.

Now I just need to actually use it.

(video provided by a cool company named Common Craft)

self.update 1

Posted by Jimmy'z on November 14, 2008

You may have noticed that I haven’t updated my blog for a while. I’ve decided that I’m going to try to write more during my lunch breaks. So, what have I been up to?

I’m still working for FamilySearch as the Developer Support guy for all public APIs. This has been a fun and rewarding experience. I get to write documentation and code samples, present at conferences and webinars, and meet with a lot of companies in the genealogy space. I’m really excited about what is coming in the genealogy industry. Lots of advancements are being made. I’ll update more of what I see coming in a later post.

I’m still doing Ruby programming on the side for USFamilyTree.com. I get to do most of this work during my commute to and from Salt Lake City. UTA has free WiFi on their express buses, which makes it possible for me to still stay productive.

Family life has been really good. Our little boy is almost 2 years old now, and he keeps us laughing and having lots of fun. We’re excited to announce that we are in the application process again to adopt another baby. The second time has been a lot faster for us and we’re getting really close to being approved and on the waiting list.

This blog has typically been about web technology and such, and I plan to keep it on that subject. Some projects that I’ve been watching closely include: Merb, CouchDB, and Rubinius. These will likely be the topics of my next posts.

I’d like to continue with my Wordpress/Hostmonster screencasts, but I haven’t been able to find the time or place to make and record new episodes. Hopefully I can find a Saturday to crank out another one soon.