All Topics:
apps
css
dashboard
games
javascript
php
tehcl
textmate
tools
video

Topic: javascript

Patch jQuery fadeTo() to Bring Back the Dead

published:
2009.05.14
topics:
javascript

Well, maybe not bringing back the dead exactly, but I did patch the jQuery function fadeTo() to bring back elements after hide() or fadeOut() were called on them.

Just paste this in your JavaScript after you load jQuery:

/**
 * Fix jQuery fadeTo() so it can bring back something after hide() or fadeOut()
 */
(function ($) {
    var proxied = $.fn.fadeTo;
    $.fn.fadeTo = function() {
        if ($(this).is(':hidden')) {
            $(this).css('opacity', 0).show();
        }
        
        return proxied.apply(this, arguments);
    }
})(jQuery);

I'd like to just see them fix this in the library itself, so I submitted a ticket.


Pattern for JavaScript Options with Defaults

published:
2009.05.14
topics:
javascript

Maybe this is obvious, but here's a really handy pattern for passing an object of options into your JavaScript functions when you also want there to be a set of default options for that function. I'm using jQuery's $.extend function to handle the objects, but most JavaScript libraries provide this functionality.

function myFunction(arg1, options) {
	defaultOptions = {
		foo: 'foo-default',
		bar: 'bar-default'
	}
	
	if (typeof options == 'object') {
		options = $.extend(defaultOptions, options);
	} else {
		options = defaultOptions;
	}
	
	// rest of your code here...
	
	// for demonstration purposes
	alert(options.foo + ' and ' + options.bar);
}

Try running some demonstration code by clicking these buttons:

I hope somebody found that interesting/helpful.


Best 1st Day Back Ever: Video Game Award!

published:
2009.05.08
topics:
games
javascript

If you follow me on Twitter then you've probably learned by now that I've been out of the office at my day job because I had an emergency appendectomy. Today was my first day back, and I have to say I had a pretty good morning because I found out that a video game I made with my web team last spring — Handy Andy 2: The Ampersand Trail — won an award! (So now I can say I am an award winning video game developer. Heh.)

Me holding the award.
The Handy Andy 2 title screen graphic.

Hey, it is a Friday afternoon, you know that you totally want to spend it "researching" this game rather than working. And when you've finished playing Handy Andy 2, you definitely will want to check out the first game, Handy Andy's Key Quest, and play some Handy Andy Bowling.

Congratulations to the Handy Andy 2 team! Kamran Ayub did the graphics and Jesse Mullan did the sound, and both contributed to the overall insanity and level design. The games are written in JavaScript with a Flash bridge for the audio if you were wondering.


JS "Game" - Viking Jesse

published:
2009.03.22
topics:
games
javascript

When my friend Jesse moved out to California, I made him a little venturing-west game (in the loose sense of the word "game") as a safe journey gift. He was just in town visiting for the last week, which reminded me of the game so I thought I'd post it. The game is built with JavaScript, and I did the graphics except for the flying manatee, which was done by Kamran.

To play, use your right and left arrow keys to move the Viking Jesse and blow up as many flying Manatees as you can. Click the image below to start.


jQuery Plugin: rotate3Di - Flip HTML content in 3D

updated:
2009.06.23
published:
2009.03.11
topics:
css
javascript
tools
Question Mark Box

Rotate3Di is a jQuery Effect Plugin that makes it possible to do an isometric 3D flip or 3D rotation of any HTML content. It also enables custom 3D rotation animations. CSS Transforms are used to create this visual "3D" isometric effect. Supported browsers are WebKit, Safari, Chrome, and Firefox 3.5. The plugin's functionality includes: setting or animating HTML content to an arbitrary isometric rotation angle, as well as flipping, unflipping, or toggling the flip state of an object.