Merge pull request #107 from clutterskull/master

Adds a simple regex based filter to the game list.
This commit is contained in:
Andy Janata 2014-05-03 19:40:20 -07:00
commit 1f06fb0fac
2 changed files with 67 additions and 16 deletions

View File

@ -125,6 +125,8 @@ HttpSession hSession = request.getSession(true);
<div id="menubar_left">
<input type="button" id="refresh_games" class="hide" value="Refresh Games" />
<input type="button" id="create_game" class="hide" value="Create Game" />
<input type="text" id="filter_games" class="hide" placeholder="Filter games by keyword" />
<input type="button" id="leave_game" class="hide" value="Leave Game" />
<input type="button" id="start_game" class="hide" value="Start Game" />
<input type="button" id="stop_game" class="hide" value="Stop Game" />

View File

@ -45,8 +45,17 @@ cah.GameList = function() {
*/
this.games_ = {};
/**
* Regular Expression for simple filtering of game list.
*
* @type {RegExp}
* @private
*/
this.filter_ = null;
$("#create_game").click(cah.bind(this, this.createGameClick_));
$("#refresh_games").click(cah.bind(this, this.refreshGamesClick_));
$("#filter_games").keyup(cah.bind(this, this.filterGamesChange_));
};
$(document).ready(function() {
@ -65,6 +74,7 @@ cah.GameList.prototype.show = function() {
$(this.element_).show();
$("#create_game").show();
$("#refresh_games").show();
$("#filter_games").show();
};
/**
@ -74,6 +84,7 @@ cah.GameList.prototype.hide = function() {
$(this.element_).hide();
$("#create_game").hide();
$("#refresh_games").hide();
$("#filter_games").hide();
};
/**
@ -150,6 +161,8 @@ cah.GameList.prototype.processUpdate = function(gameData) {
} else {
$("#create_game").attr("disabled", "disabled");
}
this.applyFilter();
};
/**
@ -167,6 +180,33 @@ cah.GameList.prototype.joinGame = function(id) {
}
};
/**
* Sets the current game filter regular expression
*/
cah.GameList.prototype.setFilter = function (filterRegExp) {
try {
this.filter_ = new RegExp(filterRegExp || '.', 'i');
} catch (err) {
//console.log('Invalid filter: ' + String(filterRegExp))
}
};
/**
* Filters the visibility of the current game list by regular expression
*/
cah.GameList.prototype.applyFilter = function (filterRegExp) {
if (filterRegExp || filterRegExp === '') this.setFilter(filterRegExp);
var filter = this.filter_
, gamelist = $('.gamelist_lobby').show();
if (filter && filter.test) {
gamelist.filter(function (i) {
return !filter.test($(this).text());
}).hide();
}
};
/**
* Event handler for the clicking the Create Game button.
*
@ -185,6 +225,15 @@ cah.GameList.prototype.refreshGamesClick_ = function() {
this.update();
};
/**
* Event handler for typing in the filter games input.
*
* @private
*/
cah.GameList.prototype.filterGamesChange_ = function() {
this.applyFilter($('#filter_games').val());
};
// ///////////////////////////////////////////////
/**