Fix first installation error

This commit is contained in:
isqua 2015-01-05 23:16:40 +03:00
parent 21eb253031
commit 1057506f05
2 changed files with 28 additions and 26 deletions

View file

@ -39,6 +39,10 @@ Options.prototype.init = function() {
if (data.options_version !== this.version) { if (data.options_version !== this.version) {
console.log('Initializing options...'); console.log('Initializing options...');
$('#tabs-content input').each(function(index, input) {
this.updateOptionFromInput($(input));
}.bind(this));
chrome.storage.sync.set({ chrome.storage.sync.set({
options: this.getValues(), options: this.getValues(),
options_version: this.version options_version: this.version
@ -73,11 +77,10 @@ Options.prototype.restore = function() {
this.checkOldStyle(); this.checkOldStyle();
chrome.storage.sync.get('options', function(data) { chrome.storage.sync.get('options', function(data) {
this._options = data.options; this._options = data.options || {};
try {
// Setting options in DOM // Setting options in DOM
$.each(data.options, function(key, data) { $.each(this._options, function(key, data) {
switch (data.type) { switch (data.type) {
case 'boolean': case 'boolean':
if (data.value) { if (data.value) {
@ -94,9 +97,6 @@ Options.prototype.restore = function() {
break; break;
} }
}.bind(this)); }.bind(this));
} catch (ex) {
console.log('Error while loading extension options: %O', ex);
}
this.showCopyright(); this.showCopyright();
this.init(); this.init();
@ -113,8 +113,12 @@ Options.prototype.getValues = function() {
Options.prototype._onChange = function(event) { Options.prototype._onChange = function(event) {
var $input = $(event.target); var $input = $(event.target);
console.log(arguments); this.updateOptionFromInput($input);
this.save();
};
Options.prototype.updateOptionFromInput = function($input) {
if (this.isBoolean($input)) { if (this.isBoolean($input)) {
this._options[this.getOptionKey($input.prop('id'))] = { this._options[this.getOptionKey($input.prop('id'))] = {
type: 'boolean', type: 'boolean',
@ -126,8 +130,6 @@ Options.prototype._onChange = function(event) {
value: $input.val() value: $input.val()
}; };
} }
this.save();
}; };
/** /**

View file

@ -9,7 +9,7 @@ chrome.extension.sendMessage({
* @constructor * @constructor
*/ */
function OptionsManager(options) { function OptionsManager(options) {
this._options = options; this._options = options || {};
} }
/** /**
@ -80,7 +80,7 @@ $(document).ready(function() {
// Parse webm-links and create video instead // Parse webm-links and create video instead
if (options.is('option_videos_parse_links')) { if (options.is('option_videos_parse_links')) {
if (option.is('option_videos_parse_links_type', 'all')) { if (options.is('option_videos_parse_links_type', 'all')) {
parse_all_videos(options); parse_all_videos(options);
} else { } else {
parse_webm(options); parse_webm(options);