From db47e94e0bfd1d6caf386d6dddb1cf0db6562b96 Mon Sep 17 00:00:00 2001 From: Enrique Schiel Date: Mon, 17 Oct 2011 17:59:34 -0300 Subject: [PATCH] Fixed sorting of leaderboard table (Bug #738) with a datatables plugin. Also, default sorting in recent games was changed to be descending (Newer games at the top) --- xonstat/static/js/default.js | 15 ++--- .../static/js/jquery.dataTables.numHtml.js | 56 +++++++++++++++++++ xonstat/templates/base.mako | 7 ++- 3 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 xonstat/static/js/jquery.dataTables.numHtml.js diff --git a/xonstat/static/js/default.js b/xonstat/static/js/default.js index 7f7824f..18dc39a 100644 --- a/xonstat/static/js/default.js +++ b/xonstat/static/js/default.js @@ -1,15 +1,15 @@ $(function(){ - + init_menus(); init_checkboxes(); init_radiobuttons(); init_datatables(); }); - + $.fn.hoverClass = function(c) { return this.each(function(){ - $(this).hover( + $(this).hover( function() { $(this).addClass(c); }, function() { $(this).removeClass(c); } ); @@ -18,8 +18,8 @@ $.fn.hoverClass = function(c) { function init_menus() { $("#menu li").hover( - function(){ $("ul", this).fadeIn("fast"); }, - function() { } + function(){ $("ul", this).fadeIn("fast"); }, + function() { } ); if (document.all) { $("#menu li").hoverClass("sfHover"); @@ -40,7 +40,7 @@ function init_radiobuttons() { $(".radio-selected:not(:checked)").removeClass("radio-selected"); $(this).next("label").addClass("radio-selected"); } - }); + }); } function init_datatables() { /* lazy test to see if exists, @@ -65,7 +65,8 @@ function init_datatables() { "bAutoWidth": false, "oLanguage": { "sSearch": "_INPUT_" - } + }, + "aaSorting": [[ 0, "desc" ]] }); } if ($("table.scoreboard").length) { diff --git a/xonstat/static/js/jquery.dataTables.numHtml.js b/xonstat/static/js/jquery.dataTables.numHtml.js new file mode 100644 index 0000000..8b577c8 --- /dev/null +++ b/xonstat/static/js/jquery.dataTables.numHtml.js @@ -0,0 +1,56 @@ +jQuery.fn.dataTableExt.oSort['num-html-asc'] = function(a,b) { + var x = a.replace( /<.*?>/g, "" ); + var y = b.replace( /<.*?>/g, "" ); + x = parseFloat( x ); + y = parseFloat( y ); + return ((x < y) ? -1 : ((x > y) ? 1 : 0)); +}; + +jQuery.fn.dataTableExt.oSort['num-html-desc'] = function(a,b) { + var x = a.replace( /<.*?>/g, "" ); + var y = b.replace( /<.*?>/g, "" ); + x = parseFloat( x ); + y = parseFloat( y ); + return ((x < y) ? 1 : ((x > y) ? -1 : 0)); +}; + +jQuery.fn.dataTableExt.aTypes.unshift( function ( sData ) +{ + sData = typeof sData.replace == 'function' ? + sData.replace( /<.*?>/g, "" ) : sData; + sData = $.trim(sData); + + var sValidFirstChars = "0123456789-"; + var sValidChars = "0123456789."; + var Char; + var bDecimal = false; + + /* Check for a valid first char (no period and allow negatives) */ + Char = sData.charAt(0); + if (sValidFirstChars.indexOf(Char) == -1) + { + return null; + } + + /* Check all the other characters are valid */ + for ( var i=1 ; i -
-
-

Player Statistics for Xonotic

+
+
+

Player Statistics for Xonotic