Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 130634d1cc6b78d4294f83f39dd20ee67f536481 1 parent 57dfd01
Cody Brocious daeken authored
Showing with 23 additions and 12 deletions.
  1. +23 −12 ventroulette/public/Chat.js
35 ventroulette/public/Chat.js
View
@@ -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();
Please sign in to comment.
Something went wrong with that request. Please try again.