nanovivid

WordPress Tip: Force All Feeds to Use Atom Atomatically

June 5th, 2008Code / SiteComments?

While migrating my site to WordPress, I got annoyed that WordPress uses RSS feeds by default with no way to change to Atom. Not that there’s a big difference or anything, but if you’re anal-retentive like me and want WordPress to use Atom but still have pretty feed URLs (http://nanovivid.com/feed/ instead of http://nanovivid.com/feed/?feed=atom), you can do it with one .htaccess RewriteRule:

RewriteRule (.*)/feed/?$ $1?feed=atom [L]

This simply takes any URL ending in /feed and invisibly appends ?feed=atom to it. Instant Atom feeds for everything!Î

Gotye - Heart's A Mess (Lull's Radio Edit)

jQuery Is Sorcery

June 1st, 2008Code / Geeking Out2 Comments

Geeky content warning: Feel free to skip this post if “JavaScript” makes you think of writing a play at a coffeehouse. Otherwise you may be confused and/or bored to tears.

Lately I’ve been using the jQuery JavaScript framework quite a bit, and I consistently find myself surprised by how close to magic it seems. Being able to simply write $("#id").hide(); and have the element disappear is a bit shocking if you’re used to writing “traditional” JavaScript. jQuery encourages a massive reduction in the amount of code required to do just about anything.

For example, the collapsable yearly archive in the footer of the site is based on the Flexo Archives Widget. The original JavaScript is about 220 lines of code, including comments and whitespace. Here’s the code ported to jQuery:

jQuery(function(){
    jQuery(".flexo-link").each(function() {
        // Add a hint to each expandable link
        jQuery(this).attr("title", jQuery(this).attr("title") + " (Click to expand)");

        // Hide each list of months
        jQuery(this).parents("li:first").children("ul").hide();

    }).bind("click", function() {
        // Show or hide a list when the user clicks
        jQuery(this).parents("li:first").children("ul").slideToggle("fast");
        return false;
    });
});

That took the code from ~220 lines to ~15, which I’d say is pretty magical. Now, to be fair, jQuery is a 14 kb framework (when compressed), while the original Flexo code is only 4 kb compressed. In my case, I was already using jQuery for other functionality, so it made sense to go ahead and shrink the JavaScript for the archives. I also added scrolling to make sure the content stays on screen as it’s expanded and a few other tweaks. Even with those new features, my code only reached about 35 lines.

This is only a small taste of what jQuery can do. In addition to the core functionality, there’s the very impressive jQuery UI and all kinds of plugins. If you’re writing JavaScript, I’d highly recommend taking a look at jQuery. Then you can feel like a wizard too.

Sigur Rós - Gobbledigook