Merge pull request #1 from atomaka/cleanup

Cleanup
This commit is contained in:
Andrew Tomaka 2013-11-13 13:48:58 -08:00
commit 6286afe980
4 changed files with 45 additions and 52 deletions

View file

@ -39,55 +39,9 @@
<input type="text" id="password" readyonly="readyonly" tabindex="-1" />
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
<script src="js/jquery.corner.min.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="js/jquery.md5.min.js"></script>
<script src="js/rules.js"></script>
<script type="text/javascript">
$(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();
}
});
</script>
<script src="js/passwd.js"></script>
</body>
</html>

File diff suppressed because one or more lines are too long

40
js/passwd.js Normal file
View file

@ -0,0 +1,40 @@
$(document).ready(function() {
$('#root').focus();
});
$('#generate input').on('input', function() {
hash = generatePassword($('#root').val(), $('#master').val());
$('#password').val(specialCase($('#root').val(), hash));
});
function generatePassword(root, master) {
return $.md5(root + master).replace(/[a-f]/, function(alpha) {
return alpha.toUpperCase();
});
}
function specialCase(root, hash) {
return (special[root] != undefined) ? special[root](hash) : 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();
}
});