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;
12 var cookie_lifetime
= 0;
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.
19 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
22 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
29 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
30 xmlhttp
= new XMLHttpRequest();
33 function toggleTags() {
34 display_tags
= !display_tags
;
36 var p
= document
.getElementById("dispSwitchPrompt");
39 p
.innerHTML
= "display feeds";
41 p
.innerHTML
= "display tags";
47 function dlg_frefresh_callback() {
48 if (xmlhttp
.readyState
== 4) {
49 notify(xmlhttp
.responseText
);
50 updateFeedList(false, false);
51 if (_qfd_deleted_feed
) {
52 var hframe
= document
.getElementById("headlines-frame");
54 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
61 function dlg_submit_callback() {
62 if (xmlhttp
.readyState
== 4) {
63 notify(xmlhttp
.responseText
);
68 function dlg_display_callback() {
69 if (xmlhttp
.readyState
== 4) {
70 var dlg
= document
.getElementById("userDlg");
71 var dlg_s
= document
.getElementById("userDlgShadow");
73 dlg
.innerHTML
= xmlhttp
.responseText
;
74 dlg_s
.style
.display
= "block";
78 function hide_unread_callback() {
79 if (xmlhttp
.readyState
== 4) {
83 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
84 var value
= reply
.getAttribute("value");
85 var hide_read_feeds
= (value
!= "false")
86 var feeds_doc
= window
.frames
["feeds-frame"].document
;
88 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
90 if (hide_read_feeds
) {
91 setCookie("ttrss_vf_hreadf", 1);
93 setCookie("ttrss_vf_hreadf", 0);
97 exception_error("hide_unread_callback", e
);
103 function refetch_callback() {
104 if (xmlhttp
.readyState
== 4) {
107 var date
= new Date();
109 last_refetch
= date
.getTime() / 1000;
111 if (!xmlhttp
.responseXML
) {
112 notify("refetch_callback: backend did not return valid XML");
116 var reply
= xmlhttp
.responseXML
.firstChild
;
119 notify("refetch_callback: backend did not return expected XML object");
124 var error_code
= reply
.getAttribute("error-code");
126 if (error_code
&& error_code
!= 0) {
127 return fatalError(error_code
, reply
.getAttribute("error-msg"));
130 var f_document
= window
.frames
["feeds-frame"].document
;
132 parse_counters(reply
, f_document
, window
, true);
134 debug("refetch_callback: done");
136 if (!daemon_enabled
) {
137 notify("All feeds updated.");
143 exception_error("refetch_callback", e
);
149 function backend_sanity_check_callback() {
151 if (xmlhttp
.readyState
== 4) {
155 if (!xmlhttp
.responseXML
) {
156 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
160 var reply
= xmlhttp
.responseXML
.firstChild
;
163 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
167 var error_code
= reply
.getAttribute("error-code");
169 if (error_code
&& error_code
!= 0) {
170 return fatalError(error_code
, reply
.getAttribute("error-msg"));
173 debug("sanity check ok");
178 exception_error("backend_sanity_check_callback", e
);
183 function scheduleFeedUpdate(force
) {
185 if (!daemon_enabled
) {
186 notify("Updating feeds, please wait.");
187 updateTitle("Updating");
190 var query_str
= "backend.php?op=rpc&subop=";
193 query_str
= query_str
+ "forceUpdateAllFeeds";
195 query_str
= query_str
+ "updateAllFeeds";
200 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
201 firsttime_update
= false;
211 query_str
= query_str
+ "&omode=" + omode
;
212 query_str
= query_str
+ "&uctr=" + global_unread
;
214 debug("in scheduleFeedUpdate");
216 var date
= new Date();
218 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
219 debug("xmlhttp seems to be stuck, aborting");
223 if (xmlhttp_ready(xmlhttp
)) {
224 xmlhttp
.open("GET", query_str
, true);
225 xmlhttp
.onreadystatechange
=refetch_callback
;
228 debug("xmlhttp busy");
233 function updateFeedList(silent
, fetch
) {
235 // if (silent != true) {
236 // notify("Loading feed list...");
239 var query_str
= "backend.php?op=feeds";
242 query_str
= query_str
+ "&tags=1";
245 if (getActiveFeedId()) {
246 query_str
= query_str
+ "&actid=" + getActiveFeedId();
249 if (navigator
.userAgent
.match("Opera")) {
250 var date
= new Date();
251 var timestamp
= Math
.round(date
.getTime() / 1000);
252 query_str
= query_str
+ "&ts=" + timestamp
255 if (fetch
) query_str
= query_str
+ "&fetch=yes";
257 var feeds_frame
= document
.getElementById("feeds-frame");
259 feeds_frame
.src
= query_str
;
262 function catchupAllFeeds() {
264 var query_str
= "backend.php?op=feeds&subop=catchupAll";
266 notify("Marking all feeds as read...");
268 var feeds_frame
= document
.getElementById("feeds-frame");
270 feeds_frame
.src
= query_str
;
277 function viewCurrentFeed(skip
, subop
) {
279 if (getActiveFeedId()) {
280 viewfeed(getActiveFeedId(), skip
, subop
);
282 disableContainerChildren("headlinesToolbar", false, document
);
283 viewfeed(-1, skip
, subop
); // FIXME
287 function viewfeed(feed
, skip
, subop
) {
288 var f
= window
.frames
["feeds-frame"];
289 f
.viewfeed(feed
, skip
, subop
);
293 scheduleFeedUpdate(false);
295 var refresh_time
= getCookie('ttrss_vf_refresh');
297 if (!refresh_time
) refresh_time
= 600;
299 setTimeout("timeout()", refresh_time
*1000);
302 function resetSearch() {
303 var searchbox
= document
.getElementById("searchbox")
305 if (searchbox
.value
!= "" && getActiveFeedId()) {
306 searchbox
.value
= "";
307 viewfeed(getActiveFeedId(), 0, "");
313 viewCurrentFeed(0, "");
316 function localPiggieFunction(enable
) {
318 var query_str
= "backend.php?op=feeds&subop=piggie";
320 if (xmlhttp_ready(xmlhttp
)) {
322 xmlhttp
.open("GET", query_str
, true);
323 xmlhttp
.onreadystatechange
=feedlist_callback
;
329 function localHotkeyHandler(keycode
) {
331 if (keycode
== 82) { // r
332 return scheduleFeedUpdate(true);
335 if (keycode
== 85) { // u
336 if (getActiveFeedId()) {
337 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
341 if (keycode
== 65) { // a
342 return toggleDispRead();
345 var f_doc
= window
.frames
["feeds-frame"].document
;
346 var feedlist
= f_doc
.getElementById('feedList');
348 if (keycode
== 74) { // j
349 var feed
= getActiveFeedId();
350 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
351 if (new_feed
) viewfeed(new_feed
, 0, '');
354 if (keycode
== 75) { // k
355 var feed
= getActiveFeedId();
356 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
357 if (new_feed
) viewfeed(new_feed
, 0, '');
360 // notify("KC: " + keycode);
364 // if argument is undefined, current subtitle is not updated
365 // use blank string to clear subtitle
366 function updateTitle(s
) {
367 var tmp
= "Tiny Tiny RSS";
369 if (s
!= undefined) {
370 current_subtitle
= s
;
373 if (global_unread
> 0) {
374 tmp
= tmp
+ " (" + global_unread
+ ")";
377 if (current_subtitle
) {
378 tmp
= tmp
+ " - " + current_subtitle
;
381 if (active_title_text
.length
> 0) {
382 tmp
= tmp
+ " > " + active_title_text
;
385 document
.title
= tmp
;
388 function genericSanityCheck() {
390 if (!xmlhttp
) fatalError(1);
392 setCookie("ttrss_vf_test", "TEST");
394 if (getCookie("ttrss_vf_test") != "TEST") {
405 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
407 if (arguments
.callee
.done
) return;
408 arguments
.callee
.done
= true;
410 disableContainerChildren("headlinesToolbar", true);
412 if (!genericSanityCheck())
415 if (getURLParam('debug')) {
416 document
.getElementById('debug_output').style
.display
= 'block';
417 debug('debug mode activated');
420 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
421 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
425 exception_error("init", e
);
429 function resize_feeds_frame() {
430 var f
= document
.getElementById("feeds-frame");
431 var tf
= document
.getElementById("mainFooter");
432 var th
= document
.getElementById("mainHeader");
434 f
.style
.height
= document
.body
.scrollHeight
- tf
.scrollHeight
-
435 th
.scrollHeight
- 50 + "px";
438 function init_second_stage() {
442 cookie_lifetime
= getCookie("ttrss_cltime");
444 delCookie("ttrss_vf_test");
446 setCookie("ttrss_vf_actfeed", "");
448 updateFeedList(false, false);
449 document
.onkeydown
= hotkey_handler
;
451 var viewbox
= document
.getElementById("viewbox");
452 var limitbox
= document
.getElementById("limitbox");
454 dropboxSelect(viewbox
, getCookie("ttrss_vf_vmode"));
455 dropboxSelect(limitbox
, getCookie("ttrss_vf_limit"));
457 daemon_enabled
= getCookie("ttrss_vf_daemon");
459 // FIXME should be callled after window resize
461 if (navigator
.userAgent
.match("Opera")) {
462 resize_feeds_frame();
464 /* // fix headlines frame height for Opera
465 var h = document.getElementById("headlines");
466 var c = document.getElementById("content");
467 var nh = document.body.scrollHeight * 0.25;
469 h.style.height = nh + "px";
470 c.style.height = c.scrollHeight - nh + "px"; */
474 debug("second stage ok");
477 exception_error("init_second_stage", e
);
481 function quickMenuChange() {
482 var chooser
= document
.getElementById("quickMenuChooser");
483 var opid
= chooser
[chooser
.selectedIndex
].id
;
485 chooser
.selectedIndex
= 0;
489 function quickMenuGo(opid
) {
492 if (opid
== "qmcPrefs") {
496 if (opid
== "qmcSearch") {
497 displayDlg("search", getActiveFeedId());
501 if (opid
== "qmcAddFeed") {
502 displayDlg("quickAddFeed");
506 if (opid
== "qmcRemoveFeed") {
507 var actid
= getActiveFeedId();
510 notify("Please select some feed first.");
514 if (confirm("Remove current feed?")) {
521 if (opid
== "qmcUpdateFeeds") {
522 scheduleFeedUpdate(true);
526 if (opid
== "qmcCatchupAll") {
531 if (opid
== "qmcShowOnlyUnread") {
536 if (opid
== "qmcAddFilter") {
537 displayDlg("quickAddFilter", getActiveFeedId());
540 exception_error("quickMenuGo", e
);
546 if (!xmlhttp_ready(xmlhttp
)) {
551 var link
= document
.getElementById("qafInput");
553 if (link
.value
.length
== 0) {
554 notify("Missing feed URL.");
556 notify("Adding feed...");
558 var cat
= document
.getElementById("qafCat");
562 cat_id
= cat
[cat
.selectedIndex
].id
;
567 var feeds_doc
= window
.frames
["feeds-frame"].document
;
569 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
571 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
572 param_escape(link
.value
) + "&cid=" + param_escape(cat_id
), true);
573 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
581 function qaddFilter() {
583 if (!xmlhttp_ready(xmlhttp
)) {
588 var regexp
= document
.getElementById("fadd_regexp");
589 var match
= document
.getElementById("fadd_match");
590 var feed
= document
.getElementById("fadd_feed");
591 var action
= document
.getElementById("fadd_action");
593 if (regexp
.value
.length
== 0) {
594 notify("Missing filter expression.");
596 notify("Adding filter...");
598 var v_match
= match
[match
.selectedIndex
].text
;
599 var feed_id
= feed
[feed
.selectedIndex
].id
;
600 var action_id
= action
[action
.selectedIndex
].id
;
602 xmlhttp
.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
603 param_escape(regexp
.value
) + "&match=" + v_match
+
604 "&fid=" + param_escape(feed_id
) + "&aid=" + param_escape(action_id
), true);
606 xmlhttp
.onreadystatechange
=dlg_submit_callback
;
615 function displayDlg(id
, param
) {
617 if (!xmlhttp_ready(xmlhttp
)) {
624 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
625 param_escape(id
) + "¶m=" + param_escape(param
), true);
626 xmlhttp
.onreadystatechange
=dlg_display_callback
;
632 function closeDlg() {
633 var dlg
= document
.getElementById("userDlgShadow");
634 dlg
.style
.display
= "none";
638 function qfdDelete(feed_id
) {
640 notify("Removing feed...");
642 if (!xmlhttp_ready(xmlhttp
)) {
647 // var feeds_doc = window.frames["feeds-frame"].document;
648 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
650 _qfd_deleted_feed
= feed_id
;
652 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
653 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
658 function updateFeedTitle(t
) {
659 active_title_text
= t
;
663 function toggleDispRead() {
666 if (!xmlhttp_ready(xmlhttp
)) {
671 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
673 hide_read_feeds
= !hide_read_feeds
;
675 var query
= "backend.php?op=rpc&subop=setpref" +
676 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
678 xmlhttp
.open("GET", query
);
679 xmlhttp
.onreadystatechange
=hide_unread_callback
;
683 exception_error("toggleDispRead", e
);
687 function debug(msg
) {
688 var c
= document
.getElementById('debug_output');
689 if (c
&& c
.style
.display
== "block") {
690 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 20) {
691 c
.removeChild(c
.lastChild
);
695 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
696 ":" + leading_zero(d
.getSeconds());
697 c
.innerHTML
= "<li>[" + ts
+ "] " + msg
+ "</li>" + c
.innerHTML
;
701 function fatalError(code
, message
) {
703 var fe
= document
.getElementById("fatal_error");
704 var fc
= document
.getElementById("fatal_error_msg");
706 fc
.innerHTML
= "Code " + code
+ ": " + message
;
708 fe
.style
.display
= "block";
711 exception_error("fatalError", e
);