]> git.wh0rd.org - tt-rss.git/blame_incremental - tt-rss.js
viewfeed() call in multifeed display
[tt-rss.git] / tt-rss.js
... / ...
CommitLineData
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
6var xmlhttp = false;
7
8var total_unread = 0;
9var first_run = true;
10
11var search_query = "";
12var search_mode = "";
13
14var display_tags = false;
15//var display_read_feeds = true;
16
17var 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.
23try {
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
34if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
35 xmlhttp = new XMLHttpRequest();
36}
37
38function 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
52function dlg_frefresh_callback() {
53 if (xmlhttp.readyState == 4) {
54 updateFeedList(false, false);
55 closeDlg();
56 }
57}
58
59function 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
68function 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
124function 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
138function 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
173function 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
196function 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
211function 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
221function 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
319function timeout() {
320 scheduleFeedUpdate(true);
321 setTimeout("timeout()", 1800*1000);
322}
323
324function resetSearch() {
325 var searchbox = document.getElementById("searchbox")
326
327 if (searchbox.value != "" && getActiveFeedId()) {
328 searchbox.value = "";
329 viewfeed(getActiveFeedId(), 0, "");
330 }
331}
332
333function search() {
334 viewCurrentFeed(0, "");
335}
336
337function 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
350function 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
372function 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
385function 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
407function 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
440function quickMenuGo() {
441
442 var chooser = document.getElementById("quickMenuChooser");
443 var opid = chooser[chooser.selectedIndex].id;
444
445 if (opid == "qmcPrefs") {
446 gotoPreferences();
447 }
448
449 if (opid == "qmcAdvSearch") {
450 displayDlg("search");
451 return;
452 }
453
454 if (opid == "qmcAddFeed") {
455 displayDlg("quickAddFeed");
456 return;
457 }
458
459 if (opid == "qmcRemoveFeed") {
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 if (opid == "qmcUpdateFeeds") {
472 scheduleFeedUpdate(true);
473 return;
474 }
475
476 if (opid == "qmcCatchupAll") {
477 catchupAllFeeds();
478 return;
479 }
480
481 if (opid == "qmcShowOnlyUnread") {
482 toggleDispRead();
483 return;
484 }
485
486}
487
488function qafAdd() {
489
490 if (!xmlhttp_ready(xmlhttp)) {
491 printLockingError();
492 return
493 }
494
495 var link = document.getElementById("qafInput");
496
497 if (link.value.length == 0) {
498 notify("Missing feed URL.");
499 } else {
500 notify("Adding feed...");
501
502 var feeds_doc = window.frames["feeds-frame"].document;
503
504 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
505
506 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
507 param_escape(link.value), true);
508 xmlhttp.onreadystatechange=dlg_frefresh_callback;
509 xmlhttp.send(null);
510
511 link.value = "";
512
513 }
514}
515
516function displayDlg(id, param) {
517
518 notify("");
519
520 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
521 param_escape(id) + "&param=" + param_escape(param), true);
522 xmlhttp.onreadystatechange=dialog_refresh_callback;
523 xmlhttp.send(null);
524
525}
526
527function closeDlg() {
528 var dlg = document.getElementById("userDlg");
529 dlg.style.display = "none";
530}
531
532function qfdDelete(feed_id) {
533
534 notify("Removing feed...");
535
536 var feeds_doc = window.frames["feeds-frame"].document;
537 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
538
539 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
540 xmlhttp.onreadystatechange=dlg_frefresh_callback;
541 xmlhttp.send(null);
542}
543
544
545function allFeedsMenuGo() {
546 var chooser = document.getElementById("allFeedsChooser");
547
548 var opname = chooser[chooser.selectedIndex].text;
549
550 if (opname == "Update") {
551 scheduleFeedUpdate(true);
552 return;
553 }
554
555 if (opname == "Mark as read") {
556 catchupAllFeeds();
557 return;
558 }
559
560 if (opname == "Show only read") {
561 toggleDispRead();
562 return;
563 }
564
565}
566
567function toggleDispRead() {
568 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
569
570 hide_read_feeds = !hide_read_feeds;
571
572 var feeds_doc = window.frames["feeds-frame"].document;
573
574 hideOrShowFeeds(feeds_doc, hide_read_feeds);
575
576 if (hide_read_feeds) {
577 setCookie("ttrss_vf_hreadf", 1);
578 } else {
579 setCookie("ttrss_vf_hreadf", 0);
580 }
581
582}