]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
printFeedEntry now expects $link
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
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
76798ff3 8var total_unread = 0;
525116d4 9var first_run = true;
76798ff3 10
c374a3fe 11var search_query = "";
52b51244 12var search_mode = "";
c374a3fe 13
8143ae1f 14var display_tags = false;
3745788e 15//var display_read_feeds = true;
8143ae1f 16
fc69e641
AD
17var global_unread = 0;
18
1cd17194
AD
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
8143ae1f
AD
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
6de5d056 52function dlg_frefresh_callback() {
1cd17194 53 if (xmlhttp.readyState == 4) {
e2f8f7b4 54 updateFeedList(false, false);
f84a97a3 55 closeDlg();
c0e5a40e 56 }
1cd17194 57}
e2f8f7b4 58
f84a97a3
AD
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}
1a66d16e 67
8158c57a 68function refetch_callback() {
29fb8c70 69 if (xmlhttp.readyState == 4) {
310da49d 70
fc69e641 71// document.title = "Tiny Tiny RSS";
310da49d 72
bc18bcdd
AD
73 if (!xmlhttp.responseXML) {
74 notify("refetch_callback: backend did not return valid XML");
75 return;
76 }
77
090e250b
AD
78 var reply = xmlhttp.responseXML.firstChild;
79
bc18bcdd
AD
80 if (!reply) {
81 notify("refetch_callback: backend did not return expected XML object");
82 return;
9cab3250 83 }
bc18bcdd 84
090e250b
AD
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");
525116d4 90
090e250b
AD
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
fc69e641
AD
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
8143ae1f
AD
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", "");
090e250b 114 }
090e250b
AD
115 }
116 }
fc69e641
AD
117
118 updateTitle("");
119 notify("All feeds updated.");
120
090e250b
AD
121 }
122}
1a66d16e 123
295f9b42
AD
124function backend_sanity_check_callback() {
125
126 if (xmlhttp.readyState == 4) {
127
128 if (!xmlhttp.responseXML) {
129 fatalError(3);
130 return;
131 }
132
133 var reply = xmlhttp.responseXML.firstChild;
134
135 if (!reply) {
136 fatalError(3);
137 return;
138 }
139
140 var error_code = reply.getAttribute("code");
141
142 if (error_code && error_code != 0) {
143 return fatalError(error_code);
144 }
145
146 init_second_stage();
147 }
148}
149
caa4e57f
AD
150function updateFeed(feed_id) {
151
152 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
153
29fb8c70
AD
154 if (xmlhttp_ready(xmlhttp)) {
155 xmlhttp.open("GET", query_str, true);
156 xmlhttp.onreadystatechange=feed_update_callback;
157 xmlhttp.send(null);
caa4e57f
AD
158 } else {
159 printLockingError();
160 }
161
162}
163
cb246176 164function scheduleFeedUpdate(force) {
525116d4
AD
165
166 notify("Updating feeds in background...");
167
fc69e641
AD
168// document.title = "Tiny Tiny RSS - Updating...";
169
170 updateTitle("Updating...");
55193822 171
cb246176
AD
172 var query_str = "backend.php?op=rpc&subop=";
173
174 if (force) {
c3b81db0 175 query_str = query_str + "forceUpdateAllFeeds";
cb246176 176 } else {
c3b81db0 177 query_str = query_str + "updateAllFeeds";
cb246176 178 }
525116d4 179
9826bd2e
AD
180 var omode;
181
182 if (display_tags) {
183 omode = "t";
184 } else {
185 omode = "fl";
186 }
187
188 query_str = query_str + "&omode=" + omode;
189
29fb8c70
AD
190 if (xmlhttp_ready(xmlhttp)) {
191 xmlhttp.open("GET", query_str, true);
192 xmlhttp.onreadystatechange=refetch_callback;
193 xmlhttp.send(null);
525116d4
AD
194 } else {
195 printLockingError();
c0e5a40e 196 }
525116d4 197}
1cd17194 198
525116d4 199function updateFeedList(silent, fetch) {
c0e5a40e 200
1a66d16e
AD
201// if (silent != true) {
202// notify("Loading feed list...");
203// }
82baad4a 204
331900c6
AD
205 var query_str = "backend.php?op=feeds";
206
8143ae1f
AD
207 if (display_tags) {
208 query_str = query_str + "&tags=1";
209 }
210
86741347
AD
211 if (getActiveFeedId()) {
212 query_str = query_str + "&actid=" + getActiveFeedId();
175847de
AD
213 }
214
1a66d16e 215 if (fetch) query_str = query_str + "&fetch=yes";
e1123aee 216
1a66d16e 217 var feeds_frame = document.getElementById("feeds-frame");
e1123aee 218
1a66d16e
AD
219 feeds_frame.src = query_str;
220}
175847de 221
476cac42 222function catchupAllFeeds() {
076682aa 223
476cac42
AD
224 var query_str = "backend.php?op=feeds&subop=catchupAll";
225
226 notify("Marking all feeds as read...");
227
1a66d16e
AD
228 var feeds_frame = document.getElementById("feeds-frame");
229
230 feeds_frame.src = query_str;
476cac42 231
fc69e641
AD
232 global_unread = 0;
233 updateTitle();
234
476cac42 235}
1cd17194 236
f0601b87 237function viewCurrentFeed(skip, subop) {
1a66d16e 238
86741347
AD
239 if (getActiveFeedId()) {
240 viewfeed(getActiveFeedId(), skip, subop);
033e47e0
AD
241 } else {
242 disableContainerChildren("headlinesToolbar", false, document);
243 viewfeed(-1, skip, subop); // FIXME
f0601b87
AD
244 }
245}
246
476cac42 247function viewfeed(feed, skip, subop) {
db8d6f67
AD
248 var f = window.frames["feeds-frame"];
249 f.viewfeed(feed, skip, subop);
9cfc649a
AD
250}
251
40d13c28 252function timeout() {
cb246176 253 scheduleFeedUpdate(true);
ac53063a 254 setTimeout("timeout()", 1800*1000);
ac53063a
AD
255}
256
c374a3fe 257function resetSearch() {
64c620ce
AD
258 var searchbox = document.getElementById("searchbox")
259
86741347 260 if (searchbox.value != "" && getActiveFeedId()) {
64c620ce 261 searchbox.value = "";
86741347 262 viewfeed(getActiveFeedId(), 0, "");
ac43eba1 263 }
c374a3fe 264}
ac53063a 265
f0601b87 266function search() {
4ce19859 267 viewCurrentFeed(0, "");
76798ff3 268}
1cd17194 269
13ad9102
AD
270function localPiggieFunction(enable) {
271 if (enable) {
272 var query_str = "backend.php?op=feeds&subop=piggie";
273
c0e5a40e 274 if (xmlhttp_ready(xmlhttp)) {
13ad9102
AD
275
276 xmlhttp.open("GET", query_str, true);
277 xmlhttp.onreadystatechange=feedlist_callback;
278 xmlhttp.send(null);
279 }
280 }
281}
282
9cfc649a
AD
283function localHotkeyHandler(keycode) {
284
f0601b87 285/* if (keycode == 78) {
c3a8d71a 286 return moveToPost('next');
9cfc649a
AD
287 }
288
289 if (keycode == 80) {
c3a8d71a 290 return moveToPost('prev');
f0601b87 291 } */
c3a8d71a 292
b623b3ed 293 if (keycode == 82) { // r
c3a8d71a
AD
294 return scheduleFeedUpdate(true);
295 }
296
b623b3ed
AD
297 if (keycode == 85) { // u
298 if (getActiveFeedId()) {
299 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
300 }
301 }
302
303 if (keycode == 65) { // a
304 return toggleDispRead();
c3a8d71a
AD
305 }
306
307// notify("KC: " + keycode);
308
9cfc649a
AD
309}
310
fc69e641
AD
311function updateTitle(s) {
312 var tmp = "Tiny Tiny RSS";
313
314 if (global_unread > 0) {
315 tmp = tmp + " (" + global_unread + ")";
316 }
317
318 if (s) {
319 tmp = tmp + " - " + s;
320 }
321 document.title = tmp;
322}
323
22a93ad8 324function genericSanityCheck() {
ac43eba1 325
295f9b42
AD
326 if (!xmlhttp) fatalError(1);
327
328 setCookie("ttrss_vf_test", "TEST");
329
330 if (getCookie("ttrss_vf_test") != "TEST") {
331 fatalError(2);
332 }
333
334/* if (!xmlhttp) {
c3a8d71a 335 document.getElementById("headlines").innerHTML =
29fb8c70 336 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
c3a8d71a 337 "to function properly. Your browser doesn't seem to support it.";
22a93ad8
AD
338 return false;
339 }
340
341 setCookie("ttrss_vf_test", "TEST");
342 if (getCookie("ttrss_vf_test") != "TEST") {
343
344 document.getElementById("headlines").innerHTML =
345 "<b>Fatal error:</b> This program requires cookies " +
346 "to function properly. Your browser doesn't seem to support them.";
347
348 return false;
295f9b42 349 } */
c3a8d71a 350
22a93ad8
AD
351 return true;
352}
353
354function init() {
355
356 disableContainerChildren("headlinesToolbar", true);
357
358 if (!genericSanityCheck())
359 return;
360
295f9b42
AD
361 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
362 xmlhttp.onreadystatechange=backend_sanity_check_callback;
363 xmlhttp.send(null);
364
365}
366
367function init_second_stage() {
368
fe2f1970
AD
369 setCookie("ttrss_vf_actfeed", "");
370
476cac42 371 updateFeedList(false, false);
13ad9102 372 document.onkeydown = hotkey_handler;
70830c87
AD
373
374 var content = document.getElementById("content");
ac43eba1 375
ac43eba1
AD
376 if (getCookie("ttrss_vf_vmode")) {
377 var viewbox = document.getElementById("viewbox");
378 viewbox.value = getCookie("ttrss_vf_vmode");
379 }
47179952 380
a8d28f48
AD
381 if (getCookie("ttrss_vf_limit")) {
382 var limitbox = document.getElementById("limitbox");
383 limitbox.value = getCookie("ttrss_vf_limit");
384 }
86741347
AD
385
386// if (getCookie("ttrss_vf_actfeed")) {
387// viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
388// }
389
13bb6bbe 390// setTimeout("timeout()", 2*1000);
295f9b42
AD
391// scheduleFeedUpdate(true);
392
2f587484
AD
393 var splash = document.getElementById("splash");
394
395 if (splash) {
396 splash.style.display = "none";
397 }
295f9b42 398
1cd17194 399}
ac43eba1 400
e2f8f7b4 401function quickMenuGo() {
e2f8f7b4 402
cbe45fa8
AD
403 var chooser = document.getElementById("quickMenuChooser");
404 var opid = chooser[chooser.selectedIndex].id;
e2f8f7b4 405
cbe45fa8 406 if (opid == "qmcPrefs") {
e2f8f7b4
AD
407 gotoPreferences();
408 }
409
cbe45fa8 410 if (opid == "qmcAdvSearch") {
033e47e0
AD
411 displayDlg("search");
412 return;
413 }
414
cbe45fa8 415 if (opid == "qmcAddFeed") {
f84a97a3 416 displayDlg("quickAddFeed");
6de5d056
AD
417 return;
418 }
419
cbe45fa8 420 if (opid == "qmcRemoveFeed") {
6de5d056
AD
421 var actid = getActiveFeedId();
422
423 if (!actid) {
424 notify("Please select some feed first.");
425 return;
426 }
427
428 displayDlg("quickDelFeed", actid);
429 return;
e2f8f7b4 430 }
7a991cac 431
cbe45fa8 432 if (opid == "qmcUpdateFeeds") {
7a991cac
AD
433 scheduleFeedUpdate(true);
434 return;
435 }
436
cbe45fa8 437 if (opid == "qmcCatchupAll") {
7a991cac
AD
438 catchupAllFeeds();
439 return;
440 }
441
cbe45fa8 442 if (opid == "qmcShowOnlyUnread") {
7a991cac
AD
443 toggleDispRead();
444 return;
445 }
446
e2f8f7b4
AD
447}
448
449function qafAdd() {
ac43eba1 450
e2f8f7b4
AD
451 if (!xmlhttp_ready(xmlhttp)) {
452 printLockingError();
453 return
454 }
455
456 var link = document.getElementById("qafInput");
457
458 if (link.value.length == 0) {
459 notify("Missing feed URL.");
460 } else {
461 notify("Adding feed...");
462
463 var feeds_doc = window.frames["feeds-frame"].document;
464
465 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
466
467 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
468 param_escape(link.value), true);
6de5d056 469 xmlhttp.onreadystatechange=dlg_frefresh_callback;
e2f8f7b4
AD
470 xmlhttp.send(null);
471
472 link.value = "";
473
474 }
f84a97a3
AD
475}
476
6de5d056 477function displayDlg(id, param) {
e2f8f7b4 478
40d601c5
AD
479 notify("");
480
f84a97a3 481 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
6de5d056 482 param_escape(id) + "&param=" + param_escape(param), true);
f84a97a3
AD
483 xmlhttp.onreadystatechange=dialog_refresh_callback;
484 xmlhttp.send(null);
e2f8f7b4
AD
485
486}
f84a97a3
AD
487
488function closeDlg() {
489 var dlg = document.getElementById("userDlg");
490 dlg.style.display = "none";
491}
492
6de5d056
AD
493function qfdDelete(feed_id) {
494
495 notify("Removing feed...");
496
497 var feeds_doc = window.frames["feeds-frame"].document;
498 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
499
500 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id);
501 xmlhttp.onreadystatechange=dlg_frefresh_callback;
502 xmlhttp.send(null);
6de5d056 503}
033e47e0 504
3745788e
AD
505
506function allFeedsMenuGo() {
507 var chooser = document.getElementById("allFeedsChooser");
508
509 var opname = chooser[chooser.selectedIndex].text;
510
511 if (opname == "Update") {
512 scheduleFeedUpdate(true);
513 return;
514 }
515
516 if (opname == "Mark as read") {
517 catchupAllFeeds();
518 return;
519 }
520
cbe45fa8 521 if (opname == "Show only read") {
3745788e
AD
522 toggleDispRead();
523 return;
524 }
525
526}
527
528function toggleDispRead() {
529 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
530
531 hide_read_feeds = !hide_read_feeds;
532
533 var feeds_doc = window.frames["feeds-frame"].document;
534
535 hideOrShowFeeds(feeds_doc, hide_read_feeds);
536
537 if (hide_read_feeds) {
538 setCookie("ttrss_vf_hreadf", 1);
539 } else {
540 setCookie("ttrss_vf_hreadf", 0);
541 }
542
543}
295f9b42
AD
544
545