1 /* Copyright (c) 2012 Robert Sesek <http://robert.sesek.com>
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:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
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.
23 document
.addEventListener('DOMContentLoaded', function() {
25 if (window
.location
.pathname
.indexOf('options.html') != -1)
27 var controller
= new SkeletonKeyOptions(doc
, window
);
32 * SkeletonKeyOptions is a controller for both retrieving settings and for
33 * displaying the view.
35 * @param {HTMLDocument} doc The document on wich to operate.
36 * @param {Window} win The window to use for localStorage.
38 var SkeletonKeyOptions
= SkeletonKeyOptions
|| function(doc
, win
) {
40 this._maxLength
= doc
.getElementById('maxlength');
41 this._saveButton
= doc
.getElementById('save');
42 this._saveButton
.onclick
= this.onSave
.bind(this);
45 this._storage
= win
.localStorage
;
47 if (this._maxLength
) {
48 this._maxLength
.value
= this.getMaximumPasswordLength();
53 * Local storage key constants.
56 SkeletonKeyOptions
.prototype._MIN_LENGTH_KEY
= 'minlength';
57 SkeletonKeyOptions
.prototype._MAX_LENGTH_KEY
= 'maxlength';
60 * Gets the minimum password length.
63 SkeletonKeyOptions
.prototype.getMinimumPasswordLength
= function() {
65 var setting
= this._storage
.getItem(this._MIN_LENGTH_KEY
);
73 * Gets the maximum password length.
76 SkeletonKeyOptions
.prototype.getMaximumPasswordLength
= function() {
78 var setting
= this._storage
.getItem(this._MAX_LENGTH_KEY
);
86 * Saves the options. Requires a document.
88 SkeletonKeyOptions
.prototype.onSave
= function() {
92 this._storage
.setItem(this._MAX_LENGTH_KEY
, this._maxLength
.value
);