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