From 0b58f66bc77d2e17ddf3e76bb6f466bedbe69321 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 9 Jun 2012 18:10:43 -0400 Subject: [PATCH] Add _nextFieldInterceptor so that you can press enter between fields --- core.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/core.js b/core.js index 6b8ca1c..737d04b 100644 --- a/core.js +++ b/core.js @@ -69,6 +69,10 @@ SkeletonKey.prototype.MIN_LENGTH = 6; SkeletonKey.prototype._init = function() { this._generateButton.onclick = this._onGenerate.bind(this); + this._master.onkeyup = this._nextFieldInterceptor.bind(this); + this._sitekey.onkeyup = this._nextFieldInterceptor.bind(this); + this._username.onkeyup = this._nextFieldInterceptor.bind(this); + this._password.onclick = this._selectPassword.bind(this); this._password.labels[0].onclick = this._selectPassword.bind(this); @@ -136,6 +140,27 @@ SkeletonKey.prototype._capitalizeKey = function(key) { return newKey; }; +/** + * Checks if the given key event is from the enter key and moves onto the next + * field or generates the password. + * @param {Event} e + * @private + */ +SkeletonKey.prototype._nextFieldInterceptor = function(e) { + if (e.keyCode != 0xD) + return; + + if (this._master.value == "") { + this._master.focus(); + } else if (this._sitekey.value == "") { + this._sitekey.focus(); + } else if (this._username.value == "") { + this._username.focus(); + } else { + this._generateButton.click(); + } +}; + /** * Selects the contents of the generated password. * @private -- 2.43.5