Intital work on options
authorRobert Sesek <rsesek@google.com>
Mon, 11 Jun 2012 19:24:29 +0000 (15:24 -0400)
committerRobert Sesek <rsesek@google.com>
Mon, 11 Jun 2012 19:24:29 +0000 (15:24 -0400)
core.css
hosted.html
options.html [new file with mode: 0644]
options.js [new file with mode: 0644]

index 6b8f01840222ba97b2ddceeccee145a05ff7fb61..ab1b302e3564c3e8df6dfad475a72ce813e29adb 100644 (file)
--- a/core.css
+++ b/core.css
@@ -23,7 +23,7 @@ body {
   width: 36em;
 }
 
-ol {
+ol, ul {
   list-style-type: none;
 }
 
index f5eea2e6c018f1c53d23c0f831c04b5e5deea118..e928b957120bddf6b59ad2a25d503d6a0b607ef4 100644 (file)
@@ -18,6 +18,8 @@
       id est laborum.
     </p>
 
-    <iframe id="core" src="core.html" />
+    <iframe id="core" src="core.html"></iframe>
+
+    <iframe id="options" src="options.html"></iframe>
   </body>
 </html>
diff --git a/options.html b/options.html
new file mode 100644 (file)
index 0000000..15f0725
--- /dev/null
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Skeleton Key - Options</title>
+    <script type="text/javascript" src="options.js"></script>
+    <link rel="stylesheet" href="common.css" />
+    <link rel="stylesheet" href="core.css" />
+  </head>
+  <body>
+    <form>
+      <ul>
+        <li>
+          <label for="maxlength">Max. Password Length</label>
+          <input type="number" id="maxlength" />
+        </li>
+
+        <li>
+          <button type="button" id="save">Save</button>
+        </li>
+      </ul>
+    </form>
+  </body>
+</html>
diff --git a/options.js b/options.js
new file mode 100644 (file)
index 0000000..506b2f8
--- /dev/null
@@ -0,0 +1,84 @@
+/* Copyright (c) 2012 Robert Sesek <http://robert.sesek.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+(function main() {
+  document.addEventListener('DOMContentLoaded', function() {
+    var controller = new SkeletonKeyOptions(window);
+  });
+})();
+
+/**
+ * SkeletonKeyOptions is a controller for both retrieving settings and for
+ * displaying the view.
+ *
+ * @param {Window} win The window and document on wich to operate.
+ */
+var SkeletonKeyOptions = SkeletonKeyOptions || function(win) {
+  if (win) {
+    this._storage = win.localStorage;
+    this._maxLength = win.document.getElementById('maxlength');
+    this._saveButton = win.document.getElementById('save');
+    this._saveButton.onclick = this.onSave.bind(this);
+  }
+};
+
+/**
+ * Local storage key constants.
+ * @priate
+ */
+SkeletonKeyOptions.prototype._MIN_LENGTH_KEY = 'minlength';
+SkeletonKeyOptions.prototype._MAX_LENGTH_KEY = 'maxlength';
+
+/**
+ * Gets the minimum password length.
+ * @returns {int}
+ */
+SkeletonKeyOptions.prototype.getMinimumPasswordLength = function() {
+  if (this._storage) {
+    var setting = this._storage.getItem(this._MIN_LENGTH_KEY);
+    if (setting)
+      return setting;
+  }
+  return 6;
+};
+
+/**
+ * Gets the maximum password length.
+ * @returns {int}
+ */
+SkeletonKeyOptions.prototype.getMaximumPasswordLength = function() {
+  if (this._storage) {
+    var setting = this._storage.getItem(this._MAX_LENGTH_KEY);
+    if (setting)
+      return setting;
+  }
+  return 18;
+};
+
+/**
+ * Saves the options. Requires a document.
+ */
+SkeletonKeyOptions.prototype.onSave = function() {
+  if (!this._storage)
+    return;
+
+  this._storage.setItem(this._MAX_LENGTH_KEY, this._maxLength.value);
+};