-
Notifications
You must be signed in to change notification settings - Fork 0
/
comicsPrefs.js
268 lines (225 loc) · 5.31 KB
/
comicsPrefs.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/*********************************
PrefencesDisplayLogic
**********************************/
var tempPrefs;
var isPrefsShowing = false;
function resetPreferences()
{
$('prefsDiv').innerHTML = '';
tempPrefs = null;
}
function showPreferences()
{
if(isPrefsShowing)
return;
isPrefsShowing = true;
tempPrefs = copy(selection);
buildPreferences();
$('content').style.display = 'none';
$('header').style.display = 'none';
$("welcome").style.display = 'none';
$('prefsDiv').style.display = 'block';
}
function hidePreferences()
{
isPrefsShowing = false;
$('content').style.display = 'block';
$('header').style.display = 'block';
$('prefsDiv').style.display = 'none';
resetPreferences();
}
function savePreferences()
{
saveComics();
hidePreferences();
resetComics();
initDisplay();
}
/*********************************
Prefences Display
**********************************/
function buildPreferences()
{
addLinks();
addPreferenceButtons();
// Go Comics
addBreak("GoComics");
for(var k = 0; k < gocomics.length; ++k)
{
var comicProps = gocomics[k];
addPreference(comicProps.index, comicProps.name);
}
// Yahoo Comics
addBreak("Yahoo");
for(var k = 0;k < yahoo.length; ++k)
{
var comicProps = yahoo[k];
addPreference(comicProps.index, comicProps.name);
}
// PhD
addBreak("Other");
addPreference(phd.index, phd.name);
addPreference(XKCD.index, XKCD.name);
// ArcaMax Comics
addBreak("ArcaMax");
for(var k = 0;k < arcamax.length; ++k)
{
var comicProps = arcamax[k];
addPreference(comicProps.index, comicProps.name);
}
// Other
// Add buttons
addBreak("");
addPreferenceButtons();
if (getViewName() == "canvas" || autoheight)
{
/* Do canvas specific stuff here */
gadgets.window.adjustHeight
}
}
function addLinks()
{
// Create variables
var content = $("prefsDiv");
var container = document.createElement("div");
container.className = "hd";
container.appendChild(makeActionLink(selectAll,"Select All"));
container.appendChild(makeLinkSeparator());
container.appendChild(makeActionLink(selectNone,"Deselect All"));
content.appendChild(container);
}
function makeLinkSeparator()
{
var span = document.createElement("span");
var text = document.createTextNode("|");
span.appendChild(text);
span.className = "linkSep";
return span;
}
function makeActionLink(fun, txt)
{
var link = document.createElement("a");
var text = document.createTextNode(txt);
link.onclick = function() {fun();};
link.href = "#";
link.appendChild(text);
return link;
}
function addBreak(name)
{
// Create variables
var content = $("prefsDiv");
var container = document.createElement("div");
var span = document.createElement("span");
var text = document.createTextNode(name);
var hr = document.createElement("hr");
// Set attributes
container.className = "comicType";
// Add to DOM
span.appendChild(text);
container.appendChild(span);
container.appendChild(hr);
content.appendChild(container);
}
function addPreferenceButtons()
{
// Create variables
var content = $("prefsDiv");
var container = document.createElement("div");
var cancel = document.createElement("input");
var save = document.createElement("input");
var stext = document.createTextNode('Save');
var ctext = document.createTextNode('Cancel');
// Set attributes
cancel.type = 'button';
cancel.value = "Cancel";
cancel.className = "prefBut";
cancel.onclick = function(e){hidePreferences();};
save.value = "Save";
save.type = 'button';
save.className = "prefBut";
save.onclick = function(e){savePreferences();};
// Add to DOM
container.appendChild(save);
container.appendChild(cancel);
content.appendChild(container);
}
function addPreference(index, name)
{
checkPrefSize(index);
// Create variables
var content = $("prefsDiv");
var container = document.createElement("div");
var choice = document.createElement("input");
var label = document.createElement("span");
var text = document.createTextNode(name);
// Set attributes
choice.type = 'checkbox';
if( hasComic(index) )
choice.defaultChecked = true;
choice.onclick = function(e) {saveComic(index);}
// Add to DOM
label.appendChild(text);
container.appendChild(choice);
container.appendChild(label);
content.appendChild(container);
}
/*********************************
Prefences Utilities
**********************************/
function selectAll()
{
defaultChoices(true);
}
function selectNone()
{
defaultChoices(false);
}
function defaultChoices(choice)
{
var content = $("prefsDiv");
var selections = content.getElementsByTagName("input");
for(var i = 0; i < selections.length; ++i)
{
if(selections[i].type != "checkbox")
continue;
selections[i].defaultChecked = choice;
selections[i].checked = choice;
}
for(var i = 0; i < tempPrefs.length; ++i)
{
if(choice)
tempPrefs[i] = '1';
else
tempPrefs[i] = '0';
}
}
function checkPrefSize(index)
{
var rlen = index + 1;
if(tempPrefs.length < rlen)
{
for(var i = tempPrefs.length; i < rlen; ++i)
{
tempPrefs.push("0");
}
}
}
function hasComic(index)
{
if(selection[index] == '1')
return true;
return false;
}
function saveComic(index)
{
if(tempPrefs[index] == '0')
tempPrefs[index] = '1';
else
tempPrefs[index] = '0';
}
function saveComics()
{
selection = tempPrefs;
prefs.set('comics', selection.join(''));
}