]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
fix title display bug on refetch
[tt-rss.git] / tt-rss.js
1 var xmlhttp = false;
2 var total_unread = 0;
3 var first_run = true;
4 var display_tags = false;
5 var global_unread = -1;
6 var active_title_text = "";
7 var current_subtitle = "";
8 var daemon_enabled = false;
9 var _qfd_deleted_feed = 0;
10
11 /*@cc_on @*/
12 /*@if (@_jscript_version >= 5)
13 // JScript gives us Conditional compilation, we can cope with old IE versions.
14 // and security blocked creation of the objects.
15 try {
16 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
17 } catch (e) {
18 try {
19 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
20 } catch (E) {
21 xmlhttp = false;
22 }
23 }
24 @end @*/
25
26 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
27 xmlhttp = new XMLHttpRequest();
28 }
29
30 function toggleTags() {
31 display_tags = !display_tags;
32
33 var p = document.getElementById("dispSwitchPrompt");
34
35 if (display_tags) {
36 p.innerHTML = "display feeds";
37 } else {
38 p.innerHTML = "display tags";
39 }
40
41 updateFeedList();
42 }
43
44 function dlg_frefresh_callback() {
45 if (xmlhttp.readyState == 4) {
46 notify(xmlhttp.responseText);
47 updateFeedList(false, false);
48 if (_qfd_deleted_feed) {
49 var hframe = document.getElementById("headlines-frame");
50 if (hframe) {
51 hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
52 }
53 }
54 closeDlg();
55 }
56 }
57
58 function dlg_submit_callback() {
59 if (xmlhttp.readyState == 4) {
60 notify(xmlhttp.responseText);
61 closeDlg();
62 }
63 }
64
65 function dlg_display_callback() {
66 if (xmlhttp.readyState == 4) {
67 var dlg = document.getElementById("userDlg");
68 var dlg_s = document.getElementById("userDlgShadow");
69
70 dlg.innerHTML = xmlhttp.responseText;
71 dlg_s.style.display = "block";
72 }
73 }
74
75 function hide_unread_callback() {
76 if (xmlhttp.readyState == 4) {
77
78 try {
79
80 var reply = xmlhttp.responseXML.firstChild.firstChild;
81 var value = reply.getAttribute("value");
82 var hide_read_feeds = (value != "false")
83 var feeds_doc = window.frames["feeds-frame"].document;
84
85 hideOrShowFeeds(feeds_doc, hide_read_feeds);
86
87 if (hide_read_feeds) {
88 setCookie("ttrss_vf_hreadf", 1);
89 } else {
90 setCookie("ttrss_vf_hreadf", 0);
91 }
92
93 } catch (e) {
94 exception_error("hide_unread_callback", e);
95 }
96
97 }
98 }
99
100 function refetch_callback() {
101 if (xmlhttp.readyState == 4) {
102 try {
103
104 if (!xmlhttp.responseXML) {
105 notify("refetch_callback: backend did not return valid XML");
106 return;
107 }
108
109 var reply = xmlhttp.responseXML.firstChild;
110
111 if (!reply) {
112 notify("refetch_callback: backend did not return expected XML object");
113 updateTitle("");
114 return;
115 }
116
117 var error_code = reply.getAttribute("error-code");
118
119 if (error_code && error_code != 0) {
120 return fatalError(error_code);
121 }
122
123 var f_document = window.frames["feeds-frame"].document;
124
125 parse_counters(reply, f_document, window);
126
127 if (!daemon_enabled) {
128 notify("All feeds updated.");
129 updateTitle("");
130 }
131 } catch (e) {
132 exception_error("refetch_callback", e);
133 updateTitle("");
134 }
135 }
136 }
137
138 function backend_sanity_check_callback() {
139
140 if (xmlhttp.readyState == 4) {
141
142 try {
143
144 if (!xmlhttp.responseXML) {
145 fatalError(3);
146 return;
147 }
148
149 var reply = xmlhttp.responseXML.firstChild;
150
151 if (!reply) {
152 fatalError(3);
153 return;
154 }
155
156 var error_code = reply.getAttribute("error-code");
157
158 if (error_code && error_code != 0) {
159 return fatalError(error_code);
160 }
161
162 init_second_stage();
163
164 } catch (e) {
165 exception_error("backend_sanity_check_callback", e);
166 }
167 }
168 }
169
170 function scheduleFeedUpdate(force) {
171
172 if (!daemon_enabled) {
173 notify("Updating feeds, please wait.");
174 updateTitle("Updating");
175 }
176
177 var query_str = "backend.php?op=rpc&subop=";
178
179 if (force) {
180 query_str = query_str + "forceUpdateAllFeeds";
181 } else {
182 query_str = query_str + "updateAllFeeds";
183 }
184
185 var omode;
186
187 if (display_tags) {
188 omode = "t";
189 } else {
190 omode = "fl";
191 }
192
193 query_str = query_str + "&omode=" + omode;
194 query_str = query_str + "&uctr=" + global_unread;
195
196 if (xmlhttp_ready(xmlhttp)) {
197 xmlhttp.open("GET", query_str, true);
198 xmlhttp.onreadystatechange=refetch_callback;
199 xmlhttp.send(null);
200 } else {
201 printLockingError();
202 }
203 }
204
205 function updateFeedList(silent, fetch) {
206
207 // if (silent != true) {
208 // notify("Loading feed list...");
209 // }
210
211 var query_str = "backend.php?op=feeds";
212
213 if (display_tags) {
214 query_str = query_str + "&tags=1";
215 }
216
217 if (getActiveFeedId()) {
218 query_str = query_str + "&actid=" + getActiveFeedId();
219 }
220
221 if (fetch) query_str = query_str + "&fetch=yes";
222
223 var feeds_frame = document.getElementById("feeds-frame");
224
225 feeds_frame.src = query_str;
226 }
227
228 function catchupAllFeeds() {
229
230 var query_str = "backend.php?op=feeds&subop=catchupAll";
231
232 notify("Marking all feeds as read...");
233
234 var feeds_frame = document.getElementById("feeds-frame");
235
236 feeds_frame.src = query_str;
237
238 global_unread = 0;
239 updateTitle("");
240
241 }
242
243 function viewCurrentFeed(skip, subop) {
244
245 if (getActiveFeedId()) {
246 viewfeed(getActiveFeedId(), skip, subop);
247 } else {
248 disableContainerChildren("headlinesToolbar", false, document);
249 viewfeed(-1, skip, subop); // FIXME
250 }
251 }
252
253 function viewfeed(feed, skip, subop) {
254 var f = window.frames["feeds-frame"];
255 f.viewfeed(feed, skip, subop);
256 }
257
258 function timeout() {
259 scheduleFeedUpdate(false);
260
261 var refresh_time = getCookie('ttrss_vf_refresh');
262
263 if (!refresh_time) refresh_time = 600;
264
265 setTimeout("timeout()", refresh_time*1000);
266 }
267
268 function resetSearch() {
269 var searchbox = document.getElementById("searchbox")
270
271 if (searchbox.value != "" && getActiveFeedId()) {
272 searchbox.value = "";
273 viewfeed(getActiveFeedId(), 0, "");
274 }
275 }
276
277 function search() {
278 closeDlg();
279 viewCurrentFeed(0, "");
280 }
281
282 function localPiggieFunction(enable) {
283 if (enable) {
284 var query_str = "backend.php?op=feeds&subop=piggie";
285
286 if (xmlhttp_ready(xmlhttp)) {
287
288 xmlhttp.open("GET", query_str, true);
289 xmlhttp.onreadystatechange=feedlist_callback;
290 xmlhttp.send(null);
291 }
292 }
293 }
294
295 function localHotkeyHandler(keycode) {
296
297 /* if (keycode == 78) {
298 return moveToPost('next');
299 }
300
301 if (keycode == 80) {
302 return moveToPost('prev');
303 } */
304
305 if (keycode == 82) { // r
306 return scheduleFeedUpdate(true);
307 }
308
309 if (keycode == 85) { // u
310 if (getActiveFeedId()) {
311 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
312 }
313 }
314
315 if (keycode == 65) { // a
316 return toggleDispRead();
317 }
318
319 var f_doc = window.frames["feeds-frame"].document;
320 var feedlist = f_doc.getElementById('feedList');
321
322 if (keycode == 74) { // j
323 var feed = getActiveFeedId();
324 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
325 if (new_feed) viewfeed(new_feed, 0, '');
326 }
327
328 if (keycode == 75) { // k
329 var feed = getActiveFeedId();
330 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
331 if (new_feed) viewfeed(new_feed, 0, '');
332 }
333
334 // notify("KC: " + keycode);
335
336 }
337
338 // if argument is undefined, current subtitle is not updated
339 // use blank string to clear subtitle
340 function updateTitle(s) {
341 var tmp = "Tiny Tiny RSS";
342
343 if (s != undefined) {
344 current_subtitle = s;
345 }
346
347 if (global_unread > 0) {
348 tmp = tmp + " (" + global_unread + ")";
349 }
350
351 if (current_subtitle) {
352 tmp = tmp + " - " + current_subtitle;
353 }
354
355 if (active_title_text.length > 0) {
356 tmp = tmp + " > " + active_title_text;
357 }
358
359 document.title = tmp;
360 }
361
362 function genericSanityCheck() {
363
364 if (!xmlhttp) fatalError(1);
365
366 setCookie("ttrss_vf_test", "TEST");
367
368 if (getCookie("ttrss_vf_test") != "TEST") {
369 fatalError(2);
370 }
371
372 return true;
373 }
374
375 function init() {
376
377 try {
378
379 disableContainerChildren("headlinesToolbar", true);
380
381 if (!genericSanityCheck())
382 return;
383
384 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
385 xmlhttp.onreadystatechange=backend_sanity_check_callback;
386 xmlhttp.send(null);
387
388 } catch (e) {
389 exception_error("init", e);
390 }
391 }
392
393 function init_second_stage() {
394
395 try {
396
397 setCookie("ttrss_vf_actfeed", "");
398
399 updateFeedList(false, false);
400 document.onkeydown = hotkey_handler;
401
402 var viewbox = document.getElementById("viewbox");
403 var limitbox = document.getElementById("limitbox");
404
405 dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
406 dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
407
408 daemon_enabled = getCookie("ttrss_vf_daemon");
409
410 } catch (e) {
411 exception_error("init_second_stage", e);
412 }
413 }
414
415 function quickMenuChange() {
416 var chooser = document.getElementById("quickMenuChooser");
417 var opid = chooser[chooser.selectedIndex].id;
418
419 chooser.selectedIndex = 0;
420 quickMenuGo(opid);
421 }
422
423 function quickMenuGo(opid) {
424
425
426 if (opid == "qmcPrefs") {
427 gotoPreferences();
428 }
429
430 if (opid == "qmcSearch") {
431 displayDlg("search", getActiveFeedId());
432 return;
433 }
434
435 if (opid == "qmcAddFeed") {
436 displayDlg("quickAddFeed");
437 return;
438 }
439
440 if (opid == "qmcRemoveFeed") {
441 var actid = getActiveFeedId();
442
443 if (!actid) {
444 notify("Please select some feed first.");
445 return;
446 }
447
448 if (confirm("Remove current feed?")) {
449 qfdDelete(actid);
450 }
451
452 return;
453 }
454
455 if (opid == "qmcUpdateFeeds") {
456 scheduleFeedUpdate(true);
457 return;
458 }
459
460 if (opid == "qmcCatchupAll") {
461 catchupAllFeeds();
462 return;
463 }
464
465 if (opid == "qmcShowOnlyUnread") {
466 toggleDispRead();
467 return;
468 }
469
470 if (opid == "qmcAddFilter") {
471 displayDlg("quickAddFilter", getActiveFeedId());
472 }
473
474 }
475
476 function qafAdd() {
477
478 if (!xmlhttp_ready(xmlhttp)) {
479 printLockingError();
480 return
481 }
482
483 var link = document.getElementById("qafInput");
484
485 if (link.value.length == 0) {
486 notify("Missing feed URL.");
487 } else {
488 notify("Adding feed...");
489
490 var cat = document.getElementById("qafCat");
491 var cat_id = "";
492
493 if (cat) {
494 cat_id = cat[cat.selectedIndex].id;
495 } else {
496 cat_id = 0;
497 }
498
499 var feeds_doc = window.frames["feeds-frame"].document;
500
501 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
502
503 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
504 param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
505 xmlhttp.onreadystatechange=dlg_frefresh_callback;
506 xmlhttp.send(null);
507
508 link.value = "";
509
510 }
511 }
512
513 function qaddFilter() {
514
515 if (!xmlhttp_ready(xmlhttp)) {
516 printLockingError();
517 return
518 }
519
520 var regexp = document.getElementById("fadd_regexp");
521 var match = document.getElementById("fadd_match");
522 var feed = document.getElementById("fadd_feed");
523 var action = document.getElementById("fadd_action");
524
525 if (regexp.value.length == 0) {
526 notify("Missing filter expression.");
527 } else {
528 notify("Adding filter...");
529
530 var v_match = match[match.selectedIndex].text;
531 var feed_id = feed[feed.selectedIndex].id;
532 var action_id = action[action.selectedIndex].id;
533
534 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add&regexp=" +
535 param_escape(regexp.value) + "&match=" + v_match +
536 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
537
538 xmlhttp.onreadystatechange=dlg_submit_callback;
539 xmlhttp.send(null);
540
541 regexp.value = "";
542 }
543
544 }
545
546
547 function displayDlg(id, param) {
548
549 if (!xmlhttp_ready(xmlhttp)) {
550 printLockingError();
551 return
552 }
553
554 notify("");
555
556 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
557 param_escape(id) + "&param=" + param_escape(param), true);
558 xmlhttp.onreadystatechange=dlg_display_callback;
559 xmlhttp.send(null);
560
561 disableHotkeys();
562 }
563
564 function closeDlg() {
565 var dlg = document.getElementById("userDlgShadow");
566 dlg.style.display = "none";
567 enableHotkeys();
568 }
569
570 function qfdDelete(feed_id) {
571
572 notify("Removing feed...");
573
574 if (!xmlhttp_ready(xmlhttp)) {
575 printLockingError();
576 return
577 }
578
579 // var feeds_doc = window.frames["feeds-frame"].document;
580 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
581
582 _qfd_deleted_feed = feed_id;
583
584 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
585 xmlhttp.onreadystatechange=dlg_frefresh_callback;
586 xmlhttp.send(null);
587 }
588
589
590 function allFeedsMenuChange() {
591 var chooser = document.getElementById("allFeedsChooser");
592
593 var opname = chooser[chooser.selectedIndex].text;
594
595 chooser.selectedIndex = 0;
596
597 if (opname == "Update") {
598 scheduleFeedUpdate(true);
599 return;
600 }
601
602 if (opname == "Mark as read") {
603 catchupAllFeeds();
604 return;
605 }
606
607 if (opname == "Show only unread") {
608 toggleDispRead();
609 return;
610 }
611
612 }
613
614 function updateFeedTitle(t) {
615 active_title_text = t;
616 updateTitle();
617 }
618
619 function toggleDispRead() {
620 try {
621
622 if (!xmlhttp_ready(xmlhttp)) {
623 printLockingError();
624 return
625 }
626
627 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
628
629 hide_read_feeds = !hide_read_feeds;
630
631 var query = "backend.php?op=rpc&subop=setpref" +
632 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
633
634 xmlhttp.open("GET", query);
635 xmlhttp.onreadystatechange=hide_unread_callback;
636 xmlhttp.send(null);
637
638 } catch (e) {
639 exception_error("toggleDispRead", e);
640 }
641 }
642