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