Intital work on options
[skeletonkey.git] / options.js
1 /* Copyright (c) 2012 Robert Sesek <http://robert.sesek.com>
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a copy
4 * of this software and associated documentation files (the "Software"), to
5 * deal in the Software without restriction, including without limitation the
6 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 * sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
9 *
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 * DEALINGS IN THE SOFTWARE.
20 */
21
22 (function main() {
23 document.addEventListener('DOMContentLoaded', function() {
24 var controller = new SkeletonKeyOptions(window);
25 });
26 })();
27
28 /**
29 * SkeletonKeyOptions is a controller for both retrieving settings and for
30 * displaying the view.
31 *
32 * @param {Window} win The window and document on wich to operate.
33 */
34 var SkeletonKeyOptions = SkeletonKeyOptions || function(win) {
35 if (win) {
36 this._storage = win.localStorage;
37 this._maxLength = win.document.getElementById('maxlength');
38 this._saveButton = win.document.getElementById('save');
39 this._saveButton.onclick = this.onSave.bind(this);
40 }
41 };
42
43 /**
44 * Local storage key constants.
45 * @priate
46 */
47 SkeletonKeyOptions.prototype._MIN_LENGTH_KEY = 'minlength';
48 SkeletonKeyOptions.prototype._MAX_LENGTH_KEY = 'maxlength';
49
50 /**
51 * Gets the minimum password length.
52 * @returns {int}
53 */
54 SkeletonKeyOptions.prototype.getMinimumPasswordLength = function() {
55 if (this._storage) {
56 var setting = this._storage.getItem(this._MIN_LENGTH_KEY);
57 if (setting)
58 return setting;
59 }
60 return 6;
61 };
62
63 /**
64 * Gets the maximum password length.
65 * @returns {int}
66 */
67 SkeletonKeyOptions.prototype.getMaximumPasswordLength = function() {
68 if (this._storage) {
69 var setting = this._storage.getItem(this._MAX_LENGTH_KEY);
70 if (setting)
71 return setting;
72 }
73 return 18;
74 };
75
76 /**
77 * Saves the options. Requires a document.
78 */
79 SkeletonKeyOptions.prototype.onSave = function() {
80 if (!this._storage)
81 return;
82
83 this._storage.setItem(this._MAX_LENGTH_KEY, this._maxLength.value);
84 };