Your browser is very old. You might enjoy surfing the web more if you used something newer like:

Google Chrome

Even Firefox would be OK.

If you're being forced at gunpoint to use Internet Explorer, you should at least upgrade it. Version 8 is tolerable and 9 will be OK when it comes out.

New Year’s Resolutions

2011 was an interesting year with lots of highs and lows.

But rather than rehashing last year, I’ve decided to go on record with my New Year’s Resolutions in the hopes that a permanent record will help me stay honest:

  • Starting tomorrow, no alcoholic beverages until I’m under 200lbs.
  • Write at least one blog post or poem (I reserve the right to keep the poems to myself) per week.
  • Ride a century. The ideal would be 100-miles-to-nowhere in Cherokee.
  • Play more D&D with the kids.
  • Do something cool with my Freeduino
  • Get a app published to the Android Market.
So here’s to being the people we always wanted to be next year and here’s to not beating ourselves up too much if we can’t pull it off.

How to write a very simple jQuery Plugin

One of the great things about jQuery is that it’s very easy to extend and has a great plugin ecosystem.

Today, we’re going to create a very simple jQuery plugin which will change the border color of an element.

Step 1: Protect the global scope

The first thing to do is wrap your plugin code in an anonymous function that calls itself so we don’t pollute the global scope.

(function($) {

})(jQuery);

Now any variables we declare inside that function will only exist within the local scope.

We also pass the main jQuery object to our function. This allows us to use the $ object even when jQuery is running in noConflict mode.

Step 2: Create our plugin function and make sure it’s chainable

We going to add a function called borderize to the jQuery object.

(function($) {
    $.fn.borderize = function(opts) {
        return this.each( function() {
        });
    };
})(jQuery);

The return this.each(); is important because it allows our plugin to be chainable by returning the object the function is being called on.

That means we’ll be able to do things like this:

$(‘#Foo’).borderize().css(‘width’, ’500px’);

Step 3: Setup some default options for the plugin but allow the end-user to change them.

We set our default border color to red. If borderize() is called without any arguments, the border color will still be red.

(function($) {
    $.fn.borderize = function(opts) {
        return this.each( function() {
            var settings = {
                borderColor: '#00ff00'
            };

            if(typeof opts == 'object') {
              $.extend(settings, opts);
            }
        });
    };
})(jQuery);

We use the $.extend function to update our settings object with any options the user might pass in.

$('#Foo').borderize( { borderColor: '#000' } );

In the above, we’re passing in black for the border color. $.extend will overwrite the value of borderColor in settings with the value passed in via opts

Step 4: Make the plugin actually do something

Now that the scaffold of our plugin, we add a call to $.css to actually change the border color of the passed in object.

(function($) {
    $.fn.borderize = function(opts) {
        return this.each( function() {
            var settings = {
                borderColor: '#00ff00'
            };

            if(typeof opts == 'object') {
              $.extend(settings, opts);
            }

            $(this).css('border', '1px solid ' + settings.borderColor);
        });
    };
})(jQuery);

Step 5: A final demo

Here’s a working jsfiddle demo

Must-Have Chrome Extensions

Here’s a short list of the Chrome extensions that I use all day, every day.

MeasureIt!

Web Developer

HTML Validator

Google Analytics Debugger

And let’s also not forget the Chrome Developer Tools that are built into Chrome. Once you turn on XMLHttpRequest logging, it can do everything Firebug does.