Permalink
Browse files

Added code to make the newPartner code get called on window close.

  • Loading branch information...
daeken committed Aug 13, 2010
1 parent 57dfd01 commit 130634d1cc6b78d4294f83f39dd20ee67f536481
Showing with 23 additions and 12 deletions.
  1. +23 −12 ventroulette/public/Chat.js
@@ -54,6 +54,18 @@ var chatId = -1;
var other;
var hasPartner = false;
+function newPartner(cb) {
+ if(hasPartner) {
+ var oldChatId = chatId;
+ chatId = -1;
+ hasPartner = false;
+ $.getJSON(
+ '/Chat/newPartner', {chatId: oldChatId},
+ cb
+ );
+ }
+}
+
$(document).ready(
function() {
info('Initializing');
@@ -67,21 +79,20 @@ $(document).ready(
$('#newPartner').click(
function() {
- if(hasPartner) {
- var oldChatId = chatId;
- chatId = -1;
- hasPartner = false;
- $.getJSON(
- '/Chat/newPartner', {chatId: oldChatId},
- function(data) {
- addMessage('System', 'Please wait while we find you a new chat partner.');
- getPartner()
- }
- );
- }
+ newPartner(
+ function(data) {
+ addMessage('System', 'Please wait while we find you a new chat partner.');
+ getPartner()
+ }
+ );
}
);
+ window.onbeforeunload =
+ function() {
+ newPartner(function() {});
+ };
+
other = ($.getUrlVar('type') == 'listener') ? 'Venter' : 'Listener';
getPartner();

0 comments on commit 130634d

Please sign in to comment.