Skip to content

Instantly share code, notes, and snippets.

@tbeseda
Forked from pjhoberman/gist:ecd4bf5f494885125399
Created December 14, 2010 23:45
Show Gist options
  • Save tbeseda/e0f3fa72828134c83f69 to your computer and use it in GitHub Desktop.
Save tbeseda/e0f3fa72828134c83f69 to your computer and use it in GitHub Desktop.
// Extend it yo!
$.extend( {
updateBlock = {
defaults: {
round: false
},
init: function(url, options, callback){
options = $.extend({}, $.updateBlock.defaults, options || {});
$.get(url, function(data, these_options){
var r = data.output; // r for record
for (var key in r) {
if (r.hasOwnProperty(key)) {
if( typeof r[key] == 'object' ) { // units and values
if( $.updateBlock.options.round )
round($( '#' + key ).text( quantity(r[key])),1);
else
$( '#' + key ).text( quantity(r[key]));
} // if
else
{
if( r[key] == '' && typeof r[key] == 'string' ) // for blank strings
r[key] = '--';
$( '#' + key ).text( r[key] );
} // else
} // if
} // for
if( typeof callback == 'function' )
callback.call(this, data);
}); // get
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment