Skip to content

Commit

Permalink
Use cookie to tie in conversations.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmhobbs committed May 15, 2012
1 parent 77a4173 commit 88af783
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions static/chat.js
Expand Up @@ -2,15 +2,26 @@ jQuery(document).ready( function ( $ ) {
var $body = $("#body"), var $body = $("#body"),
$send = $("#send"), $send = $("#send"),
$mesg = $("#messages"); $mesg = $("#messages");


var conversation = document.cookie;
if( conversation.length == 0 ) {
conversation = navigator.appVersion + Math.random() + new Date();
conversation = conversation.replace( /\W+/g, '' );
document.cookie = "conversation=" + escape( conversation ) + "; path=/";
}
else {
conversation = conversation.split( '=' );
conversation = conversation[1];
}

$send.click( function () { $send.click( function () {
var val = $body.val().replace( /^\s+|\s+$/g, '' ); var val = $body.val().replace( /^\s+|\s+$/g, '' );
if( val.length <= 0 ) { return; } if( val.length <= 0 ) { return; }
$body.val(''); $body.val('');
$mesg.append( $('<div/>').addClass('me').text(val) ); $mesg.append( $('<div/>').addClass('me').text(val) );
$.get( $.get(
'/chat.txt', '/chat.txt',
{ conversation: 'lol', body: val } { conversation: conversation, body: val }
).success( function ( data ) { ).success( function ( data ) {
$mesg.append( $('<div/>').addClass('don').text(data) ); $mesg.append( $('<div/>').addClass('don').text(data) );
} ).error( function ( xhr ) { } ).error( function ( xhr ) {
Expand Down

0 comments on commit 88af783

Please sign in to comment.