Sunday 2014-11-30

Jquery snippets that seem worthwhile:

$( "body" ).on( "click", "button", function( event ) {
    alert( "Hello." );
});

$( "#loading_indicator" ).ajaxStart(function() {
    $( this ).show();
}).ajaxStop(function() {
    $( this ).hide();
});

$.createCache = function( requestFunction ) {
    var cache = {};
    return function( key, callback ) {
        if ( !cache[ key ] ) {
            cache[ key ] = $.Deferred(function( defer ) {
                requestFunction( defer, key );
            }).promise();
        }
        return cache[ key ].done( callback );
    };
}