/
options.js
56 lines (45 loc) · 1.21 KB
/
options.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
(function($) {
'use strict';
function ImageExt(value) {
if (typeof value === 'undefined') {
return $('#rdbOther').is(':checked')
? $('#txtOther').val()
: $('input:radio[name="ImageExt"]:checked').val()
;
}
var $rdb = $('input:radio[name="ImageExt"][value="' + value + '"]');
$rdb.prop('checked', true);
$('#txtOther').prop('disabled', !$rdb.is('#rdbOther'));
}
function UpdateExamples() {
$('.sample-url').text($('#txtRootUrl').val());
$('.sample-ext').text(ImageExt());
}
function LoadModel(options) {
$('#txtRootUrl').val(options.RootUrl);
ImageExt(options.ImageExt);
$('#txtOther').val(options.Other);
UpdateExamples();
}
function GetModel(options) {
return {
RootUrl: $('#txtRootUrl').val(),
ImageExt : $('input:radio[name="ImageExt"]:checked').val(),
Other : $('#txtOther').val()
};
}
function LoadOptions() {
var options = chrome.storage.local.get('options', function(root) {
LoadModel(root.options);
});
}
function SaveOptions() {
var options = GetModel();
chrome.storage.local.set({options: options});
}
$(function() {
$('input:radio, input:text').change(UpdateExamples);
$('#btnSave').click(SaveOptions);
LoadOptions();
});
})(jQuery);