]>
git.wh0rd.org - chrome-ext/clearhistory-advance-fork.git/blob - javascript/options.js
1 // Copyright 2011 Google Inc. All Rights Reserved.
4 * @fileoverview Script for the options page.
5 * @author arunjit@google.com (Arunjit Singh)
8 window
.addEventListener('load', init
, false);
11 * Initializes the i18n strings.
12 * Loads values from localStorage and applies them to the elements
16 CONSTANTS
.TIMES
.forEach(function(time
) {
17 var selector
= 'input[name=time][value="{t}"], .opt-label#opt-{t}'
19 var elements
= $(selector
);
20 time
= getUnitsForTime(time
);
21 var message
= (time
.time
=== -1) ?
22 chrome
.i18n
.getMessage('optionsTimeAll') :
23 chrome
.i18n
.getMessage('optionsTime',
24 [time
.time
, time
.units
]);
25 elements
[0].title
= message
;
26 elements
[1].innerText
= message
;
29 $('#optionsTitle')[0].innerText
= chrome
.i18n
.getMessage('optionsTitle');
30 $('#optionsHeader')[0].innerText
= chrome
.i18n
.getMessage('optionsHeader');
31 $('#optionsPrompt')[0].innerText
= chrome
.i18n
.getMessage('optionsPrompt');
32 $('#optionsTimeFor')[0].innerText
= chrome
.i18n
.getMessage('optionsTimeFor');
33 $('#optionsTimeStart')[0].innerText
= chrome
.i18n
.getMessage('optionsTimeStart');
34 $('#optionsCookies')[0].innerText
= chrome
.i18n
.getMessage('optionsCookies');
35 $('#optionsAutoclear')[0].innerText
= chrome
.i18n
.getMessage('optionsAutoclear');
36 $('#optionsSaved > b')[0].innerText
= chrome
.i18n
.getMessage('optionsSaved');
38 // Bind all the callbacks
39 $('#opt-time input.opt-chk[type=radio]').forEach(function(e
) {
42 $('input.opt-chk[type=checkbox]').forEach(function(e
) {
45 $('#opt-prompt input.opt-chk[type=checkbox]').forEach(function(e
) {
46 e
.onclick
= setPrompt
;
49 // Load or set localStorage data
50 var timeStart
= localStorage
['timeStart'] || CONSTANTS
.YES
;
51 var time
= ~~(localStorage
['time']) ||
52 (localStorage
['time'] = CONSTANTS
.DEFAULT_TIME
);
53 var showPrompt
= localStorage
['prompt'] ||
54 (localStorage
['prompt'] = CONSTANTS
.YES
);
55 var clearCookies
= localStorage
['cookies'] || CONSTANTS
.NO
;
56 var autoClear
= localStorage
['autoclear'] || CONSTANTS
.NO
;
58 $('input[name=timeStart]')[0].checked
= (timeStart
=== CONSTANTS
.YES
);
59 $('input[name=time][value="' + time
+ '"]')[0].checked
= true;
60 $('input[name=prompt]')[0].checked
= (showPrompt
=== CONSTANTS
.YES
);
61 $('input[name=cookies]')[0].checked
= (clearCookies
=== CONSTANTS
.YES
);
62 $('input[name=autoclear]')[0].checked
= (autoClear
=== CONSTANTS
.YES
);
66 * Toggles the value in localStorage for the element selected
67 * @this {HTMLInputElement} The element (radio button) that was clicked.
70 localStorage
['time'] = this.value
;
75 * Sets the {@code localStorage.prompt} property when selected
76 * @this {HTMLInputElement} The element (checkbox) that was clicked.
78 function setPrompt() {
79 localStorage
['prompt'] = this.checked
? CONSTANTS
.YES
: CONSTANTS
.NO
;
84 localStorage
[this.name
] = this.checked
? CONSTANTS
.YES
: CONSTANTS
.NO
;
88 // For rapid changes/saves
91 * Updates the UI to indicate save completed
93 function optionSaved() {
94 var element
= $('#optionsSaved')[0];
95 element
.classList
.add('show');
96 clearTimeout(isSaving
);
97 isSaving
= setTimeout(function() {
98 element
.classList
.remove('show');