diff options
| author | dumpfmprod <dumpfmprod@ubuntu.(none)> | 2010-01-16 23:05:09 -0500 |
|---|---|---|
| committer | dumpfmprod <dumpfmprod@ubuntu.(none)> | 2010-01-16 23:05:09 -0500 |
| commit | eae4c55ec22589a036f292fd3d9bf2c87fe5a39e (patch) | |
| tree | 60013714b1714fec365678e0445b279319c46ef3 /static/js/home.js | |
| parent | a1350f6ec6d089f1a42805b17bc6cbc11fd0e3fa (diff) | |
| parent | 0b435f081c7f9d9f5d2e351a6d7dc0fa2504c6ba (diff) | |
Merge branch 'master' of /pichat/repo/
Diffstat (limited to 'static/js/home.js')
| -rwxr-xr-x | static/js/home.js | 60 |
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 |
