FnordMetric.widgets.toplistWidget = function(){ var opts; var current_gauge = false; function render(_opts){ opts = _opts; var headbar = $('
').append( $('').html(opts.title) ); var __elem = $(''); if (opts.no_min_height) { __elem.css('minHeight', '0'); } opts.elem.append(headbar).css({ 'marginBottom': 20, 'overflow': 'hidden' }).append(__elem); if(!opts.ticks){ var first = true; for(k in opts.gauges){ if (opts.gauges.length > 1) headbar.append( $('') .attr('class', 'button mr') .attr('rel', k) .append( $('').html(opts.gauges[k].title) ).click(function(){ loadGauge($(this).attr('rel')); } ) ); if(first){ first = false; loadGauge(k); } } } else { loadGauge(opts.gauges[0], true); } if(opts.autoupdate){ var secs = parseInt(opts.autoupdate); if(secs > 0){ var autoupdate_interval = window.setInterval(function(){ loadGauge(false, true); }, secs*1000); $('body').bind('fm_dashboard_close', function(){ window.clearInterval(autoupdate_interval); }); } }; } function loadGauge(gkey, silent){ if(!gkey) gkey = current_gauge; current_gauge = gkey; if(!silent) $('.toplist_inner', opts.elem).addClass('loading'); FnordMetric.publish({ "type": "widget_request", "klass": "ToplistWidget", "gauge": current_gauge, "cmd": "values_for", "tick": opts.tick, "widget_key": opts.widget_key }); } function renderGauge(gkey, gdata){ var _elem = $('.toplist_inner', opts.elem).removeClass('loading').html(''); var i = 0; $(gdata.values).each(function(n, _gd){ if (opts.limit && ((i += 1) > opts.limit)) { return; } var _perc = (parseInt(gdata.values[n][1]) / parseFloat(gdata.count))*100; var _item = $('