summaryrefslogtreecommitdiff
path: root/static/js/home.js
diff options
context:
space:
mode:
authorScott Ostler <sostler@deathmachine.local>2010-01-20 01:14:54 -0500
committerScott Ostler <sostler@deathmachine.local>2010-01-20 01:14:54 -0500
commitfaab952a795a1eee1ed6eaca476d56fcb77998aa (patch)
tree5b90a7e345c82583cadac9eda58a6c5d5ec9b9c2 /static/js/home.js
parenta91eb914edb95a5facd62b2eac00186b7b8c63c1 (diff)
parent9b9f1b51d63ee0a46d766d285ffac028d7c40cbb (diff)
Getting up to date
Diffstat (limited to 'static/js/home.js')
-rwxr-xr-xstatic/js/home.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/static/js/home.js b/static/js/home.js
new file mode 100755
index 0000000..b955d8a
--- /dev/null
+++ b/static/js/home.js
@@ -0,0 +1,60 @@
+function ifEnter(fn) {
+ return function(e) {
+ if (e.keyCode == 13) { fn(); }
+ };
+}
+
+function initHome() {
+
+ var defaults = {
+ '#nickInput': "username",
+ "#passwordInput": "not-a-real-password"
+ }
+
+ _.map(defaults, function(value, id){
+
+ // set default values for the login form only if empty
+ if ($(id).val() == "") $(id).val(value);
+
+ // erase the form text when clicked only if it is filler text, otherwise select it
+ $(id).focus(function(){
+ if($(id).val() == value) $(id).val("")
+ else $(id).select()
+ })
+
+ // restore filler text on blur if field is empty
+ $(id).blur(function(){
+ if($(id).val() == "") $(id).val(value);
+ })
+
+ })
+
+ $('#passwordInput').keyup(ifEnter(login));
+ $('#loginSubmit').click(login);
+}
+
+function login() {
+ $('#passwordInput, #loginSubmit').blur();
+ var nick = $('#nickInput').val();
+ var password = $('#passwordInput').val();
+ var hash = hex_sha1(nick + '$' + password + '$dumpfm');
+
+ var onSuccess = function(json) {
+ location.href = "/chat";
+ };
+
+ var onError = function(resp, textStatus, errorThrown) {
+ alert("Error logging in!");
+ };
+
+ $.ajax({
+ type: 'GET',
+ timeout: 5000,
+ url: 'login',
+ data: {'nick': nick, ts: '', 'hash': hash },
+ cache: false,
+ dataType: 'json',
+ success: onSuccess,
+ error: onError
+ });
+}; \ No newline at end of file