don't refresh game list if the browser tab/window isn't active, and refresh immediately when it becomes active if an update was missed

This commit is contained in:
Andy Janata 2013-04-28 10:11:28 -07:00
parent ef4a558137
commit 014258fcf2
3 changed files with 30 additions and 1 deletions

View File

@ -65,6 +65,17 @@ $(document).ready(function() {
app_resize();
});
$(window).focus(function() {
cah.windowActive = true;
if (cah.missedGameListRefresh) {
cah.GameList.instance.update();
}
});
$(window).blur(function() {
cah.windowActive = false;
});
/**
* Handle a key up event in the nick box. If the key was enter, try to register with the server.
*

View File

@ -80,9 +80,12 @@ cah.GameList.prototype.hide = function() {
* Query the server to update the game list.
*/
cah.GameList.prototype.update = function() {
if ($(this.element_).is(":visible")) {
if ($(this.element_).is(":visible") && cah.windowActive) {
// TODO display a loading indicator of some sort
cah.Ajax.build(cah.$.AjaxOperation.GAME_LIST).run();
cah.missedGameListRefresh = false;
} else {
cah.missedGameListRefresh = true;
}
};

View File

@ -57,6 +57,21 @@ cah.ignoreList = {};
*/
cah.hideConnectQuit = false;
/**
* Whether the game's browser window has focus, so we don't update the game list when we're not
* active.
*
* @type {Boolean}
*/
cah.windowActive = true;
/**
* Whether we've missed a game list refresh due to not being the active window.
*
* @type {Boolean}
*/
cah.missedGameListRefresh = false;
/**
* Binds a function to a "this object". Result is a new function that will do the right thing across
* contexts.