Add _nextFieldInterceptor so that you can press enter between fields
authorRobert Sesek <rsesek@google.com>
Sat, 9 Jun 2012 22:10:43 +0000 (18:10 -0400)
committerRobert Sesek <rsesek@google.com>
Sat, 9 Jun 2012 22:10:43 +0000 (18:10 -0400)
core.js

diff --git a/core.js b/core.js
index 6b8ca1c8685a0a4fc3a6108b44605453164c6e53..737d04b8e5acf2070b40dba86d9b3cc97dd1a704 100644 (file)
--- 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