From 6c27ee0789b47a9149e10aad631dfc398c89ae91 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Tue, 27 Aug 2013 00:59:21 -0400 Subject: [PATCH] Reduce function sizes --- js/passwd.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/js/passwd.js b/js/passwd.js index 39acb95..341f98e 100644 --- a/js/passwd.js +++ b/js/passwd.js @@ -3,18 +3,20 @@ $(document).ready(function() { }); $('#generate input').on('input', function() { - var hash = $.md5($('#root').val() + ('#master').val()); + hash = generatePassword($('#root').val(), $('#master').val()); - hash = hash.replace(/[a-f]/, function(alpha) { + $('#password').val(specialCase($('#root').val(), hash)); +}); + +function generatePassword(root, master) { + return $.md5(root + master).replace(/[a-f]/, function(alpha) { return alpha.toUpperCase(); }); +} - if($('#root').val() in special) { - $('#password').val(special[$('#root').val()](hash)); - } else { - $('#password').val(hash); - } -}); +function specialCase(root, hash) { + return (special[root] != undefined) ? special[root](hash) : hash; +} var currentFocus; var lastFocus;