From 37599d7a4fc14a58ab2e5be03f4b0720e033dea7 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 26 Aug 2013 23:57:28 -0400 Subject: [PATCH] Move javascript to separate file. --- index.html | 47 +---------------------------------------------- js/passwd.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 46 deletions(-) create mode 100644 js/passwd.js diff --git a/index.html b/index.html index 17b6b8c..6b5e19a 100755 --- a/index.html +++ b/index.html @@ -43,51 +43,6 @@ - + diff --git a/js/passwd.js b/js/passwd.js new file mode 100644 index 0000000..cf61b5d --- /dev/null +++ b/js/passwd.js @@ -0,0 +1,44 @@ +$(document).ready(function() { + $('input').corner('round 4px'); + $('button').corner('round 4px'); + $('#box').corner('round bottom'); + + $('#root').focus(); +}); + +$('#generate input').on('input', function() { + var root = $('#root').val(); + var master = $('#master').val() + var hash = $.md5(root + master); + + hash = hash.replace(/[a-f]/, function(alpha) { + return alpha.toUpperCase(); + }); + + if(root in special) { + $('#password').val(special[root](hash)); + } else { + $('#password').val(hash); + } +}); + +var currentFocus; +var lastFocus; +$(':input').focus(function() { + currentFocus = this; +}); + +$(document).keydown(function(e) { + var keycode = e.keycode || e.which; + if(keycode == 17 || keycode == 91) { + lastFocus = currentFocus; + $('#password').focus().select(); + } +}); + +$(document).keyup(function(e) { + var keycode = e.keycode || e.which; + if(keycode == 17 || keycode == 91) { + lastFocus.focus(); + } +});