/*** @jsx React.DOM */ var valid_charts = ['green', 'orange', 'red'].filter(function(val, index) { return window.difficulties[index] > 0; }); var chart_names = { 'green': 'Green (\u7FE0)', 'orange': 'Orange (\u6A59)', 'red': 'Red (\u6731)', }; var pagenav = new History(valid_charts); var top_scores = React.createClass({ sortTopScores: function(topscores) { var newscores = [[], [], [], [], []]; topscores.map(function(score) { newscores[score.chart].push(score); }.bind(this)); return newscores; }, getInitialState: function(props) { return { topscores: this.sortTopScores(window.topscores), players: window.players, chart: pagenav.getInitialState(valid_charts[0]), }; }, componentDidMount: function() { pagenav.onChange(function(chart) { this.setState({chart: chart}); }.bind(this)); this.refreshScores(); }, refreshScores: function() { AJAX.get( Link.get('refresh'), function(response) { this.setState({ topscores: this.sortTopScores(response.topscores), players: response.players, }); // Refresh every 15 seconds setTimeout(this.refreshScores, 15000); }.bind(this) ); }, convertChart: function(chart) { switch(chart) { case 'green': return 0; case 'orange': return 1; case 'red': return 2; default: return null; } }, render: function() { var chart = this.convertChart(this.state.chart); return (