yaz/commit
fix sorting
author | Michiel Hildebrand |
---|---|
Sat Feb 5 17:05:18 2011 +0100 | |
committer | Michiel Hildebrand |
Sat Feb 5 17:05:18 2011 +0100 | |
commit | 53cd38974fd2d351f469467ed3686053187401d6 |
tree | 95027e9a0b20134e1c74cb58f8dc83b3da6b9a4e |
parent | 58b28df627faa79bd31eb095e17a0801907851a2 |
Diff style: patch stat
diff --git a/web/js/game/players.js b/web/js/game/players.js index ba3476c..1269226 100644 --- a/web/js/game/players.js +++ b/web/js/game/players.js @@ -39,20 +39,27 @@ YUI.add('game-players', function(Y) { initializer: function() { if(Y.one(this.get("container"))) { this.list = null; - this.el = []; this._renderContent(); - this._renderPlayers(); this.after("playersChange", this.syncUI); } }, + + syncUI: function() { + var players = this.get("players"), + nodes = this.list.all("li"); - destructor : function() { + players.sort(function(p1,p2) {return p2.score - p1.score}); + + for(var i=0; i < players.length; i++) { + var node = nodes.item(i); + if(node) { + node.setContent(this.formatPlayer(players[i], i)); + node.removeClass("hidden"); + } + } }, - - // TBD animate updates - updatePlayers : function(players) { - this.set("players", players); - this._renderPlayers(); + + destructor : function() { }, _renderContent : function() { @@ -74,28 +81,13 @@ YUI.add('game-players', function(Y) { var count=i+1; node.append('<div class="count">'+count+'.</div>'); } - this.el[i] = node; } this.list = list; }, - - _renderPlayers : function() { - var players = this.get("players"), - el = this.el; - if(players) { - players.sort(this.playerSort); - for(var i=0; i < players.length; i++) { - if(el[i]) { - el[i].setContent(this.formatPlayer(players[i], i)); - el[i].removeClass("hidden"); - } - } - } - }, formatPlayer : function(player, index) { var html = "", - name = (player.name == this.get("user")) ? "You" : player.name; + name = (player.player == this.get("user")) ? "You" : player.name; if(this.get("countShow")) { var count = index+1; @@ -106,10 +98,6 @@ YUI.add('game-players', function(Y) { html += '<div class="score">'+player.score+'</div>'; } return html; - }, - - playerSort : function(p1, p2) { - return p1.score < p2.score; } });