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 var firsttime_update
= true;
14 /*@if (@_jscript_version >= 5)
15 // JScript gives us Conditional compilation, we can cope with old IE versions.
16 // and security blocked creation of the objects.
18 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
21 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
28 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
29 xmlhttp
= new XMLHttpRequest();
32 function toggleTags() {
33 display_tags
= !display_tags
;
35 var p
= document
.getElementById("dispSwitchPrompt");
38 p
.innerHTML
= "display feeds";
40 p
.innerHTML
= "display tags";
46 function dlg_frefresh_callback() {
47 if (xmlhttp
.readyState
== 4) {
48 notify(xmlhttp
.responseText
);
49 updateFeedList(false, false);
50 if (_qfd_deleted_feed
) {
51 var hframe
= document
.getElementById("headlines-frame");
53 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
60 function dlg_submit_callback() {
61 if (xmlhttp
.readyState
== 4) {
62 notify(xmlhttp
.responseText
);
67 function dlg_display_callback() {
68 if (xmlhttp
.readyState
== 4) {
69 var dlg
= document
.getElementById("userDlg");
70 var dlg_s
= document
.getElementById("userDlgShadow");
72 dlg
.innerHTML
= xmlhttp
.responseText
;
73 dlg_s
.style
.display
= "block";
77 function hide_unread_callback() {
78 if (xmlhttp
.readyState
== 4) {
82 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
83 var value
= reply
.getAttribute("value");
84 var hide_read_feeds
= (value
!= "false")
85 var feeds_doc
= window
.frames
["feeds-frame"].document
;
87 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
89 if (hide_read_feeds
) {
90 setCookie("ttrss_vf_hreadf", 1);
92 setCookie("ttrss_vf_hreadf", 0);
96 exception_error("hide_unread_callback", e
);
102 function refetch_callback() {
103 if (xmlhttp
.readyState
== 4) {
106 var date
= new Date();
108 last_refetch
= date
.getTime() / 1000;
110 if (!xmlhttp
.responseXML
) {
111 notify("refetch_callback: backend did not return valid XML");
115 var reply
= xmlhttp
.responseXML
.firstChild
;
118 notify("refetch_callback: backend did not return expected XML object");
123 var error_code
= reply
.getAttribute("error-code");
125 if (error_code
&& error_code
!= 0) {
126 return fatalError(error_code
);
129 var f_document
= window
.frames
["feeds-frame"].document
;
131 parse_counters(reply
, f_document
, window
, true);
133 debug("refetch_callback: done");
135 if (!daemon_enabled
) {
136 notify("All feeds updated.");
142 exception_error("refetch_callback", e
);
148 function backend_sanity_check_callback() {
150 if (xmlhttp
.readyState
== 4) {
154 if (!xmlhttp
.responseXML
) {
155 fatalError(3, "D001;" + xmlhttp
.responseText
);
159 var reply
= xmlhttp
.responseXML
.firstChild
;
162 fatalError(3, "D002;" + xmlhttp
.responseText
);
166 var error_code
= reply
.getAttribute("error-code");
168 if (error_code
&& error_code
!= 0) {
169 return fatalError(error_code
);
172 debug("sanity check ok");
177 exception_error("backend_sanity_check_callback", e
);
182 function scheduleFeedUpdate(force
) {
184 if (!daemon_enabled
) {
185 notify("Updating feeds, please wait.");
186 updateTitle("Updating");
189 var query_str
= "backend.php?op=rpc&subop=";
192 query_str
= query_str
+ "forceUpdateAllFeeds";
194 query_str
= query_str
+ "updateAllFeeds";
199 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
200 firsttime_update
= false;
210 query_str
= query_str
+ "&omode=" + omode
;
211 query_str
= query_str
+ "&uctr=" + global_unread
;
213 debug("in scheduleFeedUpdate");
215 var date
= new Date();
217 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
218 debug("xmlhttp seems to be stuck, aborting");
222 if (xmlhttp_ready(xmlhttp
)) {
223 xmlhttp
.open("GET", query_str
, true);
224 xmlhttp
.onreadystatechange
=refetch_callback
;
227 debug("xmlhttp busy");
232 function updateFeedList(silent
, fetch
) {
234 // if (silent != true) {
235 // notify("Loading feed list...");
238 var query_str
= "backend.php?op=feeds";
241 query_str
= query_str
+ "&tags=1";
244 if (getActiveFeedId()) {
245 query_str
= query_str
+ "&actid=" + getActiveFeedId();
248 if (navigator
.userAgent
.match("Opera")) {
249 var date
= new Date();
250 var timestamp
= Math
.round(date
.getTime() / 1000);
251 query_str
= query_str
+ "&ts=" + timestamp
254 if (fetch
) query_str
= query_str
+ "&fetch=yes";
256 var feeds_frame
= document
.getElementById("feeds-frame");
258 feeds_frame
.src
= query_str
;
261 function catchupAllFeeds() {
263 var query_str
= "backend.php?op=feeds&subop=catchupAll";
265 notify("Marking all feeds as read...");
267 var feeds_frame
= document
.getElementById("feeds-frame");
269 feeds_frame
.src
= query_str
;
276 function viewCurrentFeed(skip
, subop
) {
278 if (getActiveFeedId()) {
279 viewfeed(getActiveFeedId(), skip
, subop
);
281 disableContainerChildren("headlinesToolbar", false, document
);
282 viewfeed(-1, skip
, subop
); // FIXME
286 function viewfeed(feed
, skip
, subop
) {
287 var f
= window
.frames
["feeds-frame"];
288 f
.viewfeed(feed
, skip
, subop
);
292 scheduleFeedUpdate(false);
294 var refresh_time
= getCookie('ttrss_vf_refresh');
296 if (!refresh_time
) refresh_time
= 600;
298 setTimeout("timeout()", refresh_time
*1000);
301 function resetSearch() {
302 var searchbox
= document
.getElementById("searchbox")
304 if (searchbox
.value
!= "" && getActiveFeedId()) {
305 searchbox
.value
= "";
306 viewfeed(getActiveFeedId(), 0, "");
312 viewCurrentFeed(0, "");
315 function localPiggieFunction(enable
) {
317 var query_str
= "backend.php?op=feeds&subop=piggie";
319 if (xmlhttp_ready(xmlhttp
)) {
321 xmlhttp
.open("GET", query_str
, true);
322 xmlhttp
.onreadystatechange
=feedlist_callback
;
328 function localHotkeyHandler(keycode
) {
330 if (keycode
== 82) { // r
331 return scheduleFeedUpdate(true);
334 if (keycode
== 85) { // u
335 if (getActiveFeedId()) {
336 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
340 if (keycode
== 65) { // a
341 return toggleDispRead();
344 var f_doc
= window
.frames
["feeds-frame"].document
;
345 var feedlist
= f_doc
.getElementById('feedList');
347 if (keycode
== 74) { // j
348 var feed
= getActiveFeedId();
349 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
350 if (new_feed
) viewfeed(new_feed
, 0, '');
353 if (keycode
== 75) { // k
354 var feed
= getActiveFeedId();
355 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
356 if (new_feed
) viewfeed(new_feed
, 0, '');
359 // notify("KC: " + keycode);
363 // if argument is undefined, current subtitle is not updated
364 // use blank string to clear subtitle
365 function updateTitle(s
) {
366 var tmp
= "Tiny Tiny RSS";
368 if (s
!= undefined) {
369 current_subtitle
= s
;
372 if (global_unread
> 0) {
373 tmp
= tmp
+ " (" + global_unread
+ ")";
376 if (current_subtitle
) {
377 tmp
= tmp
+ " - " + current_subtitle
;
380 if (active_title_text
.length
> 0) {
381 tmp
= tmp
+ " > " + active_title_text
;
384 document
.title
= tmp
;
387 function genericSanityCheck() {
389 if (!xmlhttp
) fatalError(1);
391 setCookie("ttrss_vf_test", "TEST");
393 if (getCookie("ttrss_vf_test") != "TEST") {
404 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
406 if (arguments
.callee
.done
) return;
407 arguments
.callee
.done
= true;
409 disableContainerChildren("headlinesToolbar", true);
411 if (!genericSanityCheck())
414 if (getURLParam('debug')) {
415 document
.getElementById('debug_output').style
.display
= 'block';
416 debug('debug mode activated');
419 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
420 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
424 exception_error("init", e
);
428 function resize_feeds_frame() {
429 var f
= document
.getElementById("feeds-frame");
430 var tf
= document
.getElementById("mainFooter");
431 var th
= document
.getElementById("mainHeader");
433 f
.style
.height
= document
.body
.scrollHeight
- tf
.scrollHeight
-
434 th
.scrollHeight
- 50 + "px";
437 function init_second_stage() {
441 setCookie("ttrss_vf_actfeed", "");
443 updateFeedList(false, false);
444 document
.onkeydown
= hotkey_handler
;
446 var viewbox
= document
.getElementById("viewbox");
447 var limitbox
= document
.getElementById("limitbox");
449 dropboxSelect(viewbox
, getCookie("ttrss_vf_vmode"));
450 dropboxSelect(limitbox
, getCookie("ttrss_vf_limit"));
452 daemon_enabled
= getCookie("ttrss_vf_daemon");
454 // FIXME should be callled after window resize
456 if (navigator
.userAgent
.match("Opera")) {
457 resize_feeds_frame();
459 /* // fix headlines frame height for Opera
460 var h = document.getElementById("headlines");
461 var c = document.getElementById("content");
462 var nh = document.body.scrollHeight * 0.25;
464 h.style.height = nh + "px";
465 c.style.height = c.scrollHeight - nh + "px"; */
469 debug("second stage ok");
472 exception_error("init_second_stage", e
);
476 function quickMenuChange() {
477 var chooser
= document
.getElementById("quickMenuChooser");
478 var opid
= chooser
[chooser
.selectedIndex
].id
;
480 chooser
.selectedIndex
= 0;
484 function quickMenuGo(opid
) {
487 if (opid
== "qmcPrefs") {
491 if (opid
== "qmcSearch") {
492 displayDlg("search", getActiveFeedId());
496 if (opid
== "qmcAddFeed") {
497 displayDlg("quickAddFeed");
501 if (opid
== "qmcRemoveFeed") {
502 var actid
= getActiveFeedId();
505 notify("Please select some feed first.");
509 if (confirm("Remove current feed?")) {
516 if (opid
== "qmcUpdateFeeds") {
517 scheduleFeedUpdate(true);
521 if (opid
== "qmcCatchupAll") {
526 if (opid
== "qmcShowOnlyUnread") {
531 if (opid
== "qmcAddFilter") {
532 displayDlg("quickAddFilter", getActiveFeedId());
539 if (!xmlhttp_ready(xmlhttp
)) {
544 var link
= document
.getElementById("qafInput");
546 if (link
.value
.length
== 0) {
547 notify("Missing feed URL.");
549 notify("Adding feed...");
551 var cat
= document
.getElementById("qafCat");
555 cat_id
= cat
[cat
.selectedIndex
].id
;
560 var feeds_doc
= window
.frames
["feeds-frame"].document
;
562 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
564 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
565 param_escape(link
.value
) + "&cid=" + param_escape(cat_id
), true);
566 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
574 function qaddFilter() {
576 if (!xmlhttp_ready(xmlhttp
)) {
581 var regexp
= document
.getElementById("fadd_regexp");
582 var match
= document
.getElementById("fadd_match");
583 var feed
= document
.getElementById("fadd_feed");
584 var action
= document
.getElementById("fadd_action");
586 if (regexp
.value
.length
== 0) {
587 notify("Missing filter expression.");
589 notify("Adding filter...");
591 var v_match
= match
[match
.selectedIndex
].text
;
592 var feed_id
= feed
[feed
.selectedIndex
].id
;
593 var action_id
= action
[action
.selectedIndex
].id
;
595 xmlhttp
.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
596 param_escape(regexp
.value
) + "&match=" + v_match
+
597 "&fid=" + param_escape(feed_id
) + "&aid=" + param_escape(action_id
), true);
599 xmlhttp
.onreadystatechange
=dlg_submit_callback
;
608 function displayDlg(id
, param
) {
610 if (!xmlhttp_ready(xmlhttp
)) {
617 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
618 param_escape(id
) + "¶m=" + param_escape(param
), true);
619 xmlhttp
.onreadystatechange
=dlg_display_callback
;
625 function closeDlg() {
626 var dlg
= document
.getElementById("userDlgShadow");
627 dlg
.style
.display
= "none";
631 function qfdDelete(feed_id
) {
633 notify("Removing feed...");
635 if (!xmlhttp_ready(xmlhttp
)) {
640 // var feeds_doc = window.frames["feeds-frame"].document;
641 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
643 _qfd_deleted_feed
= feed_id
;
645 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
646 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
651 function allFeedsMenuChange() {
652 var chooser
= document
.getElementById("allFeedsChooser");
654 var opname
= chooser
[chooser
.selectedIndex
].text
;
656 chooser
.selectedIndex
= 0;
658 if (opname
== "Update") {
659 scheduleFeedUpdate(true);
663 if (opname
== "Mark as read") {
668 if (opname
== "Show only unread") {
675 function updateFeedTitle(t
) {
676 active_title_text
= t
;
680 function toggleDispRead() {
683 if (!xmlhttp_ready(xmlhttp
)) {
688 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
690 hide_read_feeds
= !hide_read_feeds
;
692 var query
= "backend.php?op=rpc&subop=setpref" +
693 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
695 xmlhttp
.open("GET", query
);
696 xmlhttp
.onreadystatechange
=hide_unread_callback
;
700 exception_error("toggleDispRead", e
);
704 function debug(msg
) {
705 var c
= document
.getElementById('debug_output');
706 if (c
&& c
.style
.display
== "block") {
707 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 20) {
708 c
.removeChild(c
.lastChild
);
712 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
713 ":" + leading_zero(d
.getSeconds());
714 c
.innerHTML
= "<li>[" + ts
+ "] " + msg
+ "</li>" + c
.innerHTML
;