Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created February 9, 2012 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ralphbean/1779989 to your computer and use it in GitHub Desktop.
Save ralphbean/1779989 to your computer and use it in GitHub Desktop.
tg2app/public/js/waiting.js
(function() {
var globals, poll;
globals = typeof exports !== "undefined" && exports !== null ? exports : this;
globals.polling_interval = 3000;
poll = function() {
var last, name, toks;
toks = window.location.href.split('/');
last = toks[4];
name = last.split('#')[0];
return $.ajax({
url: '/waiting/' + name + '.json',
error: function(err) {
console.log("Got an error");
return console.log(err);
},
success: function(json) {
$("#users li").remove();
$(json['users']).each(function(i, user) {
return $("#users ul").append("<li>" + user.name + "</li>");
});
$("#messages li").remove();
$(json['messages']).each(function(i, msg) {
return $("#messages ul").append("<li>" + msg.msg + "</li>");
});
return setTimeout(poll, globals.polling_interval);
}
});
};
$(document).ready(setTimeout(poll, globals.polling_interval));
$(document).bind('before-unload', function() {
var last, name, toks;
toks = window.location.href.split('/');
last = toks[4];
name = last.split('#')[0];
return $.ajax({
url: '/do_logout/' + name
});
});
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment