forked from PactInteractive/image-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.js
152 lines (131 loc) · 6.48 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
window.onload = function () {
initializeControlValues();
initializeControlStyles();
initializeControlEvents();
};
function initializeControlValues(reset) {
//General
if ((reset ? localStorage.show_download_confirmation_default : localStorage.show_download_confirmation) == 'true') {
$('#show_download_confirmation_checkbox').prop('checked', true);
}
if ((reset ? localStorage.show_download_notification_default : localStorage.show_download_notification) == 'true') {
$('#show_download_notification_checkbox').prop('checked', true);
}
//Filters
if ((reset ? localStorage.show_filter_mode_default : localStorage.show_filter_mode) == 'true') {
$('#show_filter_mode_checkbox').prop('checked', true);
}
if ((reset ? localStorage.show_only_images_from_links_default : localStorage.show_only_images_from_links) == 'true') {
$('#show_only_images_from_links_checkbox').prop('checked', true);
}
if ((reset ? localStorage.show_sort_by_url_default : localStorage.show_sort_by_url) == 'true') {
$('#show_sort_by_url_checkbox').prop('checked', true);
}
//Images
if ((reset ? localStorage.show_download_image_button_default : localStorage.show_download_image_button) == 'true') {
$('#show_download_image_button_checkbox').prop('checked', true);
}
if ((reset ? localStorage.show_open_image_button_default : localStorage.show_open_image_button) == 'true') {
$('#show_open_image_button_checkbox').prop('checked', true);
}
if ((reset ? localStorage.show_image_url_default : localStorage.show_image_url) == 'true') {
$('#show_image_url_checkbox').prop('checked', true);
}
$('#image_min_width_numberbox').val(reset ? localStorage.image_min_width_default : localStorage.image_min_width);
$('#image_max_width_numberbox').val(reset ? localStorage.image_max_width_default : localStorage.image_max_width);
$('#image_border_width_numberbox').val(reset ? localStorage.image_border_width_default : localStorage.image_border_width);
$('#image_border_style_dropdown').val(reset ? localStorage.image_border_style_default : localStorage.image_border_style);
$('#image_border_color_picker').val(reset ? localStorage.image_border_color_default : localStorage.image_border_color);
}
function initializeControlStyles(reset) {
jss('body', {
width: reset ? localStorage.body_width_default : localStorage.body_width
});
jss('img', {
'min-width': (reset ? localStorage.image_min_width_default : localStorage.image_min_width) + 'px',
'max-width': (reset ? localStorage.image_max_width_default : localStorage.image_max_width) + 'px',
'border-width': (reset ? localStorage.image_border_width_default : localStorage.image_border_width) + 'px',
'border-style': reset ? localStorage.image_border_style_default : localStorage.image_border_style,
'border-color': reset ? localStorage.image_border_color_default : localStorage.image_border_color
});
}
function initializeControlEvents() {
$('#image_min_width_numberbox')
.on('change', function () {
jss('img', { 'min-width': (this.value || localStorage.image_min_width_default) + 'px' });
});
$('#image_max_width_numberbox')
.on('change', function () {
var width = parseInt(this.value || localStorage.image_max_width_default);
jss('img', {
'max-width': width + 'px'
});
var bodyWidth = width + parseInt(localStorage.body_width_default) - parseInt(localStorage.image_max_width_default);
jss('body', {
'width': bodyWidth + 'px'
});
});
$('#image_border_width_numberbox')
.on('change', function () {
jss('img', { 'border-width': (this.value || localStorage.image_border_width_default) + 'px' });
});
$('#image_border_style_dropdown')
.on('change', function () {
jss('img', { 'border-style': this.value || localStorage.image_border_style_default });
});
$('#image_border_color_picker')
.on('change', function () {
jss('img', { 'border-color': this.value || localStorage.image_border_color_default });
});
//Buttons
$('#save_button').on('click', saveOptions);
$('#reset_button').on('click', resetOptions);
$('#clear_data_button').on('click', clearData);
}
function saveOptions() {
//General
localStorage.show_download_confirmation = $('#show_download_confirmation_checkbox').prop('checked');
localStorage.show_download_notification = $('#show_download_notification_checkbox').prop('checked');
//Filters
localStorage.show_filter_mode = $('#show_filter_mode_checkbox').prop('checked');
localStorage.show_only_images_from_links = $('#show_only_images_from_links_checkbox').prop('checked');
localStorage.show_sort_by_url = $('#show_sort_by_url_checkbox').prop('checked');
//Images
localStorage.show_download_image_button = $('#show_download_image_button_checkbox').prop('checked');
localStorage.show_open_image_button = $('#show_open_image_button_checkbox').prop('checked');
localStorage.show_image_url = $('#show_image_url_checkbox').prop('checked');
localStorage.image_min_width = $('#image_min_width_numberbox').val();
localStorage.image_max_width = $('#image_max_width_numberbox').val();
localStorage.image_border_width = $('#image_border_width_numberbox').val();
localStorage.image_border_style = $('#image_border_style_dropdown').val();
localStorage.image_border_color = $('#image_border_color_picker').val();
localStorage.sort_images = $('#sort_images_checkbox').prop('checked');
localStorage.body_width = parseInt($('#image_max_width_numberbox').val()) + parseInt(localStorage.body_width_default) - parseInt(localStorage.image_max_width_default);
addNotification('Options saved.', 'success');
}
function resetOptions() {
initializeControlValues(true);
initializeControlStyles(true);
addNotification('Options have been reset to their defaults. You can now save the changes you made or discard them by reloading the page.', 'warning');
}
function clearData() {
var result = confirm('Are you sure you want to clear all data for this extension?');
if (result) {
localStorage.clear();
window.location.reload();
}
}
function addNotification(message, cssClass) {
var animation_duration = parseInt(localStorage.animation_duration);
var container =
$('<div></div>')
.prependTo('#notifications')
.toggle(false)
.html(message)
.addClass(cssClass)
.fadeIn(animation_duration, function () {
setTimeout(function () {
container.fadeOut(animation_duration, function () { container.remove() });
}, 10000);
});
}