2011-12-23 02:48:20 +00:00
|
|
|
/**
|
|
|
|
* Main app for cah.
|
|
|
|
*
|
|
|
|
* @author ajanata
|
|
|
|
*/
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2011-12-25 03:37:45 +00:00
|
|
|
// see if we already exist on the server so we can resume
|
2012-01-12 22:25:04 +00:00
|
|
|
cah.Ajax.build("firstload").run();
|
2011-12-25 03:37:45 +00:00
|
|
|
|
2011-12-23 02:48:20 +00:00
|
|
|
// TODO see if we have a stored nickname somewhere
|
|
|
|
$("#nicknameconfirm").click(nicknameconfirm_click);
|
|
|
|
$("#nickbox").keyup(nickbox_keyup);
|
|
|
|
$("#nickbox").focus();
|
2011-12-25 03:37:45 +00:00
|
|
|
|
|
|
|
$("#chat").keyup(chat_keyup);
|
|
|
|
$("#chat_submit").click(chatsubmit_click);
|
2012-01-06 23:53:04 +00:00
|
|
|
|
|
|
|
// TODO: have some sort of mechanism to alert the server that we have unloaded the page, but
|
|
|
|
// have not expressed an interest in being cleared out yet.
|
|
|
|
// $(window).bind("beforeunload", window_beforeunload);
|
|
|
|
$("#logout").click(logout_click);
|
2011-12-23 02:48:20 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
function nickbox_keyup(e) {
|
|
|
|
if (e.which == 13) {
|
|
|
|
$("#nicknameconfirm").click();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function nicknameconfirm_click(e) {
|
2011-12-25 03:37:45 +00:00
|
|
|
var nickname = $.trim($("#nickname").val());
|
2012-01-12 22:25:04 +00:00
|
|
|
cah.Ajax.build("register").withNickname(nickname).run();
|
2011-12-25 03:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function chat_keyup(e) {
|
|
|
|
if (e.which == 13) {
|
|
|
|
$("#chat_submit").click();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function chatsubmit_click(e) {
|
|
|
|
var text = $.trim($("#chat").val());
|
|
|
|
// TODO when I get multiple channels working, this needs to know active and pass it
|
2012-01-12 22:25:04 +00:00
|
|
|
cah.Ajax.build("chat").withMessage(text).run();
|
2011-12-25 03:37:45 +00:00
|
|
|
cah.log.status("<" + cah.nickname + "> " + text);
|
|
|
|
$("#chat").val("");
|
|
|
|
$("#chat").focus();
|
2011-12-23 02:48:20 +00:00
|
|
|
}
|
2012-01-06 23:53:04 +00:00
|
|
|
|
|
|
|
function logout_click(e) {
|
2012-01-12 22:25:04 +00:00
|
|
|
cah.Ajax.build("logout").run();
|
2012-01-06 23:53:04 +00:00
|
|
|
}
|