]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
compact prefs tables
[tt-rss.git] / tt-rss.js
1 var xmlhttp = false;
2
3 var total_unread = 0;
4 var first_run = true;
5
6 var display_tags = false;
7
8 var global_unread = 0;
9
10 var active_title_text = "";
11
12 var current_subtitle = "";
13
14 /*@cc_on @*/
15 /*@if (@_jscript_version >= 5)
16 // JScript gives us Conditional compilation, we can cope with old IE versions.
17 // and security blocked creation of the objects.
18 try {
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
20 } catch (e) {
21 try {
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
23 } catch (E) {
24 xmlhttp = false;
25 }
26 }
27 @end @*/
28
29 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
30 xmlhttp = new XMLHttpRequest();
31 }
32
33 function toggleTags() {
34 display_tags = !display_tags;
35
36 var p = document.getElementById("dispSwitchPrompt");
37
38 if (display_tags) {
39 p.innerHTML = "display feeds";
40 } else {
41 p.innerHTML = "display tags";
42 }
43
44 updateFeedList();
45 }
46
47 function dlg_frefresh_callback() {
48 if (xmlhttp.readyState == 4) {
49 updateFeedList(false, false);
50 closeDlg();
51 }
52 }
53
54 function dialog_refresh_callback() {
55 if (xmlhttp.readyState == 4) {
56 var dlg = document.getElementById("userDlg");
57 var dlg_s = document.getElementById("userDlgShadow");
58
59 dlg.innerHTML = xmlhttp.responseText;
60 dlg_s.style.display = "block";
61 }
62 }
63
64 function refetch_callback() {
65 if (xmlhttp.readyState == 4) {
66 try {
67
68 if (!xmlhttp.responseXML) {
69 notify("refetch_callback: backend did not return valid XML");
70 return;
71 }
72
73 var reply = xmlhttp.responseXML.firstChild;
74
75 if (!reply) {
76 notify("refetch_callback: backend did not return expected XML object");
77 return;
78 }
79
80 var error_code = reply.getAttribute("error-code");
81
82 if (error_code && error_code != 0) {
83 return fatalError(error_code);
84 }
85
86 var f_document = window.frames["feeds-frame"].document;
87
88 for (var l = 0; l < reply.childNodes.length; l++) {
89 var id = reply.childNodes[l].getAttribute("id");
90 var ctr = reply.childNodes[l].getAttribute("counter");
91
92 var feedctr = f_document.getElementById("FEEDCTR-" + id);
93 var feedu = f_document.getElementById("FEEDU-" + id);
94 var feedr = f_document.getElementById("FEEDR-" + id);
95
96 /* TODO figure out how to update this from viewfeed.js->view()
97 disabled for now...
98
99 if (id == "global-unread") {
100 global_unread = ctr;
101 } */
102
103 if (feedctr && feedu && feedr) {
104
105 feedu.innerHTML = ctr;
106
107 if (ctr > 0) {
108 feedctr.className = "odd";
109 if (!feedr.className.match("Unread")) {
110 feedr.className = feedr.className + "Unread";
111 }
112 } else {
113 feedctr.className = "invisible";
114 feedr.className = feedr.className.replace("Unread", "");
115 }
116 }
117 }
118
119 updateTitle("");
120 notify("All feeds updated.");
121 } catch (e) {
122 exception_error("refetch_callback", e);
123 }
124 }
125 }
126
127 function backend_sanity_check_callback() {
128
129 if (xmlhttp.readyState == 4) {
130
131 try {
132
133 if (!xmlhttp.responseXML) {
134 fatalError(3);
135 return;
136 }
137
138 var reply = xmlhttp.responseXML.firstChild;
139
140 if (!reply) {
141 fatalError(3);
142 return;
143 }
144
145 var error_code = reply.getAttribute("error-code");
146
147 if (error_code && error_code != 0) {
148 return fatalError(error_code);
149 }
150
151 init_second_stage();
152
153 } catch (e) {
154 exception_error("backend_sanity_check_callback", e);
155 }
156 }
157 }
158
159 function scheduleFeedUpdate(force) {
160
161 notify("Updating feeds in background...");
162
163 // document.title = "Tiny Tiny RSS - Updating...";
164
165 updateTitle("Updating");
166
167 var query_str = "backend.php?op=rpc&subop=";
168
169 if (force) {
170 query_str = query_str + "forceUpdateAllFeeds";
171 } else {
172 query_str = query_str + "updateAllFeeds";
173 }
174
175 var omode;
176
177 if (display_tags) {
178 omode = "t";
179 } else {
180 omode = "fl";
181 }
182
183 query_str = query_str + "&omode=" + omode;
184
185 if (xmlhttp_ready(xmlhttp)) {
186 xmlhttp.open("GET", query_str, true);
187 xmlhttp.onreadystatechange=refetch_callback;
188 xmlhttp.send(null);
189 } else {
190 printLockingError();
191 }
192 }
193
194 function updateFeedList(silent, fetch) {
195
196 // if (silent != true) {
197 // notify("Loading feed list...");
198 // }
199
200 var query_str = "backend.php?op=feeds";
201
202 if (display_tags) {
203 query_str = query_str + "&tags=1";
204 }
205
206 if (getActiveFeedId()) {
207 query_str = query_str + "&actid=" + getActiveFeedId();
208 }
209
210 if (fetch) query_str = query_str + "&fetch=yes";
211
212 var feeds_frame = document.getElementById("feeds-frame");
213
214 feeds_frame.src = query_str;
215 }
216
217 function catchupAllFeeds() {
218
219 var query_str = "backend.php?op=feeds&subop=catchupAll";
220
221 notify("Marking all feeds as read...");
222
223 var feeds_frame = document.getElementById("feeds-frame");
224
225 feeds_frame.src = query_str;
226
227 global_unread = 0;
228 updateTitle("");
229
230 }
231
232 function viewCurrentFeed(skip, subop) {
233
234 if (getActiveFeedId()) {
235 viewfeed(getActiveFeedId(), skip, subop);
236 } else {
237 disableContainerChildren("headlinesToolbar", false, document);
238 viewfeed(-1, skip, subop); // FIXME
239 }
240 }
241
242 function viewfeed(feed, skip, subop) {
243 var f = window.frames["feeds-frame"];
244 f.viewfeed(feed, skip, subop);
245 }
246
247 function timeout() {
248 scheduleFeedUpdate(false);
249 setTimeout("timeout()", 1800*1000);
250 }
251
252 function resetSearch() {
253 var searchbox = document.getElementById("searchbox")
254
255 if (searchbox.value != "" && getActiveFeedId()) {
256 searchbox.value = "";
257 viewfeed(getActiveFeedId(), 0, "");
258 }
259 }
260
261 function search() {
262 viewCurrentFeed(0, "");
263 }
264
265 function localPiggieFunction(enable) {
266 if (enable) {
267 var query_str = "backend.php?op=feeds&subop=piggie";
268
269 if (xmlhttp_ready(xmlhttp)) {
270
271 xmlhttp.open("GET", query_str, true);
272 xmlhttp.onreadystatechange=feedlist_callback;
273 xmlhttp.send(null);
274 }
275 }
276 }
277
278 function localHotkeyHandler(keycode) {
279
280 /* if (keycode == 78) {
281 return moveToPost('next');
282 }
283
284 if (keycode == 80) {
285 return moveToPost('prev');
286 } */
287
288 if (keycode == 82) { // r
289 return scheduleFeedUpdate(true);
290 }
291
292 if (keycode == 85) { // u
293 if (getActiveFeedId()) {
294 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
295 }
296 }
297
298 if (keycode == 65) { // a
299 return toggleDispRead();
300 }
301
302 // notify("KC: " + keycode);
303
304 }
305
306 function updateTitle(s) {
307 var tmp = "Tiny Tiny RSS";
308
309 if (s && s.length > 0) {
310 current_subtitle = s;
311 }
312
313 if (global_unread > 0) {
314 tmp = tmp + " (" + global_unread + ")";
315 }
316
317 if (s) {
318 tmp = tmp + " - " + current_subtitle;
319 }
320
321 if (active_title_text.length > 0) {
322 tmp = tmp + " > " + active_title_text;
323 }
324
325 document.title = tmp;
326 }
327
328 function genericSanityCheck() {
329
330 if (!xmlhttp) fatalError(1);
331
332 setCookie("ttrss_vf_test", "TEST");
333
334 if (getCookie("ttrss_vf_test") != "TEST") {
335 fatalError(2);
336 }
337
338 return true;
339 }
340
341 function init() {
342
343 try {
344
345 disableContainerChildren("headlinesToolbar", true);
346
347 if (!genericSanityCheck())
348 return;
349
350 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
351 xmlhttp.onreadystatechange=backend_sanity_check_callback;
352 xmlhttp.send(null);
353
354 } catch (e) {
355 exception_error("init", e);
356 }
357 }
358
359 function init_second_stage() {
360
361 try {
362
363 setCookie("ttrss_vf_actfeed", "");
364
365 updateFeedList(false, false);
366 document.onkeydown = hotkey_handler;
367
368 var content = document.getElementById("content");
369
370 if (getCookie("ttrss_vf_vmode")) {
371 var viewbox = document.getElementById("viewbox");
372 viewbox.value = getCookie("ttrss_vf_vmode");
373 }
374
375 if (getCookie("ttrss_vf_limit")) {
376 var limitbox = document.getElementById("limitbox");
377 limitbox.value = getCookie("ttrss_vf_limit");
378 }
379
380 // if (getCookie("ttrss_vf_actfeed")) {
381 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
382 // }
383
384 // setTimeout("timeout()", 2*1000);
385 // scheduleFeedUpdate(true);
386
387 } catch (e) {
388 exception_error("init_second_stage", e);
389 }
390 }
391
392 function quickMenuGo() {
393
394 var chooser = document.getElementById("quickMenuChooser");
395 var opid = chooser[chooser.selectedIndex].id;
396
397 if (opid == "qmcPrefs") {
398 gotoPreferences();
399 }
400
401 if (opid == "qmcAdvSearch") {
402 displayDlg("search");
403 return;
404 }
405
406 if (opid == "qmcAddFeed") {
407 displayDlg("quickAddFeed");
408 return;
409 }
410
411 if (opid == "qmcRemoveFeed") {
412 var actid = getActiveFeedId();
413
414 if (!actid) {
415 notify("Please select some feed first.");
416 return;
417 }
418
419 displayDlg("quickDelFeed", actid);
420 return;
421 }
422
423 if (opid == "qmcUpdateFeeds") {
424 scheduleFeedUpdate(true);
425 return;
426 }
427
428 if (opid == "qmcCatchupAll") {
429 catchupAllFeeds();
430 return;
431 }
432
433 if (opid == "qmcShowOnlyUnread") {
434 toggleDispRead();
435 return;
436 }
437
438 }
439
440 function qafAdd() {
441
442 if (!xmlhttp_ready(xmlhttp)) {
443 printLockingError();
444 return
445 }
446
447 var link = document.getElementById("qafInput");
448
449 if (link.value.length == 0) {
450 notify("Missing feed URL.");
451 } else {
452 notify("Adding feed...");
453
454 var feeds_doc = window.frames["feeds-frame"].document;
455
456 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
457
458 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
459 param_escape(link.value), true);
460 xmlhttp.onreadystatechange=dlg_frefresh_callback;
461 xmlhttp.send(null);
462
463 link.value = "";
464
465 }
466 }
467
468 function displayDlg(id, param) {
469
470 notify("");
471
472 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
473 param_escape(id) + "&param=" + param_escape(param), true);
474 xmlhttp.onreadystatechange=dialog_refresh_callback;
475 xmlhttp.send(null);
476
477 }
478
479 function closeDlg() {
480 var dlg = document.getElementById("userDlgShadow");
481 dlg.style.display = "none";
482 }
483
484 function qfdDelete(feed_id) {
485
486 notify("Removing feed...");
487
488 var feeds_doc = window.frames["feeds-frame"].document;
489 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
490
491 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
492 xmlhttp.onreadystatechange=dlg_frefresh_callback;
493 xmlhttp.send(null);
494 }
495
496
497 function allFeedsMenuGo() {
498 var chooser = document.getElementById("allFeedsChooser");
499
500 var opname = chooser[chooser.selectedIndex].text;
501
502 if (opname == "Update") {
503 scheduleFeedUpdate(true);
504 return;
505 }
506
507 if (opname == "Mark as read") {
508 catchupAllFeeds();
509 return;
510 }
511
512 if (opname == "Show only unread") {
513 toggleDispRead();
514 return;
515 }
516
517 }
518
519 function updateFeedTitle(t) {
520 active_title_text = t;
521 updateTitle();
522 }
523
524 function toggleDispRead() {
525 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
526
527 hide_read_feeds = !hide_read_feeds;
528
529 var feeds_doc = window.frames["feeds-frame"].document;
530
531 hideOrShowFeeds(feeds_doc, hide_read_feeds);
532
533 if (hide_read_feeds) {
534 setCookie("ttrss_vf_hreadf", 1);
535 } else {
536 setCookie("ttrss_vf_hreadf", 0);
537 }
538
539 }
540
541