diff options
| author | timb <timb@mb.home> | 2010-01-15 18:57:43 -0800 |
|---|---|---|
| committer | timb <timb@mb.home> | 2010-01-15 18:57:43 -0800 |
| commit | 188f1e79227fabfd46bf0feff460516414395364 (patch) | |
| tree | d2ae085f127637bab4faa3912bd7c3fb5b8d68ad /static/js/home.js | |
| parent | cdcc81c23c6bcc3e455345a0fc8d5ed346f17089 (diff) | |
fixed up the default value for the login form fields and moved most of the javascript into static/js
Diffstat (limited to 'static/js/home.js')
| -rwxr-xr-x | static/js/home.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/static/js/home.js b/static/js/home.js new file mode 100755 index 0000000..910de02 --- /dev/null +++ b/static/js/home.js @@ -0,0 +1,58 @@ +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); + + $(id).focus(function(){ + if($(id).val() == value) $(id).val("") + else $(id).select() + }) + + $(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 |
