]> git.rm.cloudns.org Git - xonotic/xonstat.git/commitdiff
Fixed sorting of leaderboard table (Bug #738) with a datatables plugin.
authorEnrique Schiel <ecschiel@gmail.com>
Mon, 17 Oct 2011 20:59:34 +0000 (17:59 -0300)
committerEnrique Schiel <ecschiel@gmail.com>
Mon, 17 Oct 2011 20:59:34 +0000 (17:59 -0300)
Also, default sorting in recent games was changed to be descending
(Newer games at the top)

xonstat/static/js/default.js
xonstat/static/js/jquery.dataTables.numHtml.js [new file with mode: 0644]
xonstat/templates/base.mako

index 7f7824f1331555121bd2f231939f9fb3aa2b83cc..18dc39ae22f678c9c9203938894fb28f97da3869 100644 (file)
@@ -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 (file)
index 0000000..8b577c8
--- /dev/null
@@ -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<sData.length ; i++ )
+  {
+    Char = sData.charAt(i);
+    if (sValidChars.indexOf(Char) == -1)
+    {
+      return null;
+    }
+
+    /* Only allowed one decimal place... */
+    if ( Char == "." )
+    {
+      if ( bDecimal )
+      {
+       return null;
+      }
+      bDecimal = true;
+    }
+  }
+
+  return 'num-html';
+} );
\ No newline at end of file
index 068e56174b497c91a294704f4471ad492e33dec1..74b5fcfbd56d92edd57c38f6c582f3e0c5df1bc2 100755 (executable)
@@ -8,9 +8,9 @@
         </%block>
     </head>
     <body>
-               <div id="container"> 
-                       <div id="home" class="window"> 
-                               <h1 id="title">Player Statistics for Xonotic</h1> 
+               <div id="container">
+                       <div id="home" class="window">
+                               <h1 id="title">Player Statistics for Xonotic</h1>
                                <ul id="menu" class="nav clearfix">
                                        <li><a href="${request.route_url('main_index')}" title="Leaderboard">leaderboard</a></li>
                                        <li><a href="${request.route_url('player_index')}" title="Player Index">players</a></li>
@@ -33,6 +33,7 @@
                <script>window.jQuery || document.write( '<script src="/static/js/scripts/jquery-1.6.1.min.js"><\/script>' )</script>-->
                <script src="/static/js/jquery-1.6.1.min.js"></script>
                <script src="/static/js/jquery.dataTables.min.js"></script>
+               <script src="/static/js/jquery.dataTables.numHtml.js"></script>
                <script src="/static/js/default.js"></script>
         </%block>
     </body>