Database Reference
In-Depth Information
$chg.toggleClass("percentage"); });
}
This code wraps up all the information needed to update the counter as
well as the directional indicator. The code also binds a click event to the
directional indicator to allow for toggling between an absolute display and a
percentage display.
To see these metrics in action, the following is a small driver that triggers
each of the counter events with a random value. The triggers themselves are
set to randomly fire between 1 and 5 seconds and can be found in public/
javascripts/counter.js :
$(document).ready(function() {
$('*[data-counter]').each(function(i,elt) {
var name = $(elt).attr("data-counter");
setInterval(function() {
$(document).trigger("data:"+name,
Math.round(10000*Math.random()));
},1000+Math.round(4000*Math.random()));
});
});
The counters, shown in Figure 7.2 , are now ready to accept data streamed in
from the server itself.
Figure 7.2
 
 
Search WWH ::




Custom Search