this._password = doc.getElementById('password');
this._generateButton = doc.getElementById('generate');
- this._options = new SkeletonKeyOptions();
+ // If this is an extension, use defaults until the Chrome settings are loaded.
+ var win = null;
+ if (!this._isChromeExtension())
+ win = window;
+ this._options = new SkeletonKeyOptions(null, win);
+
this._init();
};
*/
SkeletonKey.prototype._initChromeExtension = function() {
return;
- if (typeof chrome == 'undefined' || typeof chrome.extension == 'undefined')
- return;
// getCurrent is undefined for backround pages. Need content script.
chrome.tabs.getCurrent(function (tab) {
console.log(siteKey);
});
};
+
+/**
+ * Checks if SkeletonKey is running as a Chrome extension.
+ * @returns {bool}
+ * @private
+ */
+SkeletonKey.prototype._isChromeExtension = function() {
+ return typeof chrome != 'undefined' && typeof chrome.extension != 'undefined';
+};
(function main() {
document.addEventListener('DOMContentLoaded', function() {
- var win = null;
+ var doc = null;
if (window.location.pathname.indexOf('options.html') != -1)
- win = window;
- var controller = new SkeletonKeyOptions(win);
+ doc = document;
+ var controller = new SkeletonKeyOptions(doc, 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.
+ * @param {HTMLDocument} doc The document on wich to operate.
+ * @param {Window} win The window to use for localStorage.
*/
-var SkeletonKeyOptions = SkeletonKeyOptions || function(win) {
+var SkeletonKeyOptions = SkeletonKeyOptions || function(doc, win) {
+ if (doc) {
+ this._maxLength = doc.getElementById('maxlength');
+ this._saveButton = doc.getElementById('save');
+ this._saveButton.onclick = this.onSave.bind(this);
+ }
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);
}
};