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