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 hide_unread_callback() {
62 if (xmlhttp
.readyState
== 4) {
66 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
67 var value
= reply
.getAttribute("value");
68 var hide_read_feeds
= (value
!= "false")
69 var feeds_doc
= window
.frames
["feeds-frame"].document
;
71 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
73 if (hide_read_feeds
) {
74 setCookie("ttrss_vf_hreadf", 1);
76 setCookie("ttrss_vf_hreadf", 0);
80 exception_error("hide_unread_callback", e
);
86 function refetch_callback() {
87 if (xmlhttp
.readyState
== 4) {
90 var date
= new Date();
92 last_refetch
= date
.getTime() / 1000;
94 if (!xmlhttp
.responseXML
) {
95 notify("refetch_callback: backend did not return valid XML");
99 var reply
= xmlhttp
.responseXML
.firstChild
;
102 notify("refetch_callback: backend did not return expected XML object");
107 var error_code
= reply
.getAttribute("error-code");
109 if (error_code
&& error_code
!= 0) {
110 return fatalError(error_code
, reply
.getAttribute("error-msg"));
113 var f_document
= window
.frames
["feeds-frame"].document
;
115 parse_counters(reply
, f_document
, window
, true);
117 debug("refetch_callback: done");
119 if (!daemon_enabled
) {
120 notify("All feeds updated.");
126 exception_error("refetch_callback", e
);
132 function backend_sanity_check_callback() {
134 if (xmlhttp
.readyState
== 4) {
138 if (!xmlhttp
.responseXML
) {
139 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp
.responseText
);
143 var reply
= xmlhttp
.responseXML
.firstChild
;
146 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp
.responseText
);
150 var error_code
= reply
.getAttribute("error-code");
152 if (error_code
&& error_code
!= 0) {
153 return fatalError(error_code
, reply
.getAttribute("error-msg"));
156 debug("sanity check ok");
161 exception_error("backend_sanity_check_callback", e
);
166 function scheduleFeedUpdate(force
) {
168 if (!daemon_enabled
) {
169 notify("Updating feeds, please wait.");
170 updateTitle("Updating");
173 var query_str
= "backend.php?op=rpc&subop=";
176 query_str
= query_str
+ "forceUpdateAllFeeds";
178 query_str
= query_str
+ "updateAllFeeds";
183 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
184 firsttime_update
= false;
194 query_str
= query_str
+ "&omode=" + omode
;
195 query_str
= query_str
+ "&uctr=" + global_unread
;
197 debug("in scheduleFeedUpdate");
199 var date
= new Date();
201 if (!xmlhttp_ready(xmlhttp
) && last_refetch
< date
.getTime() / 1000 - 60) {
202 debug("xmlhttp seems to be stuck, aborting");
206 if (xmlhttp_ready(xmlhttp
)) {
207 xmlhttp
.open("GET", query_str
, true);
208 xmlhttp
.onreadystatechange
=refetch_callback
;
211 debug("xmlhttp busy");
216 function updateFeedList(silent
, fetch
) {
218 // if (silent != true) {
219 // notify("Loading feed list...");
222 var query_str
= "backend.php?op=feeds";
225 query_str
= query_str
+ "&tags=1";
228 if (getActiveFeedId()) {
229 query_str
= query_str
+ "&actid=" + getActiveFeedId();
232 if (navigator
.userAgent
.match("Opera")) {
233 var date
= new Date();
234 var timestamp
= Math
.round(date
.getTime() / 1000);
235 query_str
= query_str
+ "&ts=" + timestamp
238 if (fetch
) query_str
= query_str
+ "&fetch=yes";
240 var feeds_frame
= document
.getElementById("feeds-frame");
242 feeds_frame
.src
= query_str
;
245 function catchupAllFeeds() {
247 var query_str
= "backend.php?op=feeds&subop=catchupAll";
249 notify("Marking all feeds as read...");
251 var feeds_frame
= document
.getElementById("feeds-frame");
253 feeds_frame
.src
= query_str
;
260 function viewCurrentFeed(skip
, subop
) {
262 if (getActiveFeedId()) {
263 viewfeed(getActiveFeedId(), skip
, subop
);
265 disableContainerChildren("headlinesToolbar", false, document
);
266 viewfeed(-1, skip
, subop
); // FIXME
270 function viewfeed(feed
, skip
, subop
) {
271 var f
= window
.frames
["feeds-frame"];
272 f
.viewfeed(feed
, skip
, subop
);
276 scheduleFeedUpdate(false);
278 var refresh_time
= getCookie('ttrss_vf_refresh');
280 if (!refresh_time
) refresh_time
= 600;
282 setTimeout("timeout()", refresh_time
*1000);
285 function resetSearch() {
286 var searchbox
= document
.getElementById("searchbox")
288 if (searchbox
.value
!= "" && getActiveFeedId()) {
289 searchbox
.value
= "";
290 viewfeed(getActiveFeedId(), 0, "");
296 viewCurrentFeed(0, "");
299 function localPiggieFunction(enable
) {
301 var query_str
= "backend.php?op=feeds&subop=piggie";
303 if (xmlhttp_ready(xmlhttp
)) {
305 xmlhttp
.open("GET", query_str
, true);
306 xmlhttp
.onreadystatechange
=feedlist_callback
;
312 function localHotkeyHandler(keycode
) {
314 if (keycode
== 82) { // r
315 return scheduleFeedUpdate(true);
318 if (keycode
== 85) { // u
319 if (getActiveFeedId()) {
320 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
324 if (keycode
== 65) { // a
325 return toggleDispRead();
328 var f_doc
= window
.frames
["feeds-frame"].document
;
329 var feedlist
= f_doc
.getElementById('feedList');
331 if (keycode
== 74) { // j
332 var feed
= getActiveFeedId();
333 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
334 if (new_feed
) viewfeed(new_feed
, 0, '');
337 if (keycode
== 75) { // k
338 var feed
= getActiveFeedId();
339 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
340 if (new_feed
) viewfeed(new_feed
, 0, '');
343 // notify("KC: " + keycode);
347 // if argument is undefined, current subtitle is not updated
348 // use blank string to clear subtitle
349 function updateTitle(s
) {
350 var tmp
= "Tiny Tiny RSS";
352 if (s
!= undefined) {
353 current_subtitle
= s
;
356 if (global_unread
> 0) {
357 tmp
= tmp
+ " (" + global_unread
+ ")";
360 if (current_subtitle
) {
361 tmp
= tmp
+ " - " + current_subtitle
;
364 if (active_title_text
.length
> 0) {
365 tmp
= tmp
+ " > " + active_title_text
;
368 document
.title
= tmp
;
371 function genericSanityCheck() {
373 if (!xmlhttp
) fatalError(1);
375 setCookie("ttrss_vf_test", "TEST");
377 if (getCookie("ttrss_vf_test") != "TEST") {
388 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
390 if (arguments
.callee
.done
) return;
391 arguments
.callee
.done
= true;
393 disableContainerChildren("headlinesToolbar", true);
395 if (!genericSanityCheck())
398 if (getURLParam('debug')) {
399 document
.getElementById('debug_output').style
.display
= 'block';
400 debug('debug mode activated');
403 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
404 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
408 exception_error("init", e
);
412 function resize_feeds_frame() {
413 var f
= document
.getElementById("feeds-frame");
414 var tf
= document
.getElementById("mainFooter");
415 var th
= document
.getElementById("mainHeader");
417 f
.style
.height
= document
.body
.scrollHeight
- tf
.scrollHeight
-
418 th
.scrollHeight
- 50 + "px";
421 function init_second_stage() {
425 cookie_lifetime
= getCookie("ttrss_cltime");
427 delCookie("ttrss_vf_test");
429 setCookie("ttrss_vf_actfeed", "");
431 updateFeedList(false, false);
432 document
.onkeydown
= hotkey_handler
;
434 var viewbox
= document
.getElementById("viewbox");
435 var limitbox
= document
.getElementById("limitbox");
437 dropboxSelect(viewbox
, getCookie("ttrss_vf_vmode"));
438 dropboxSelect(limitbox
, getCookie("ttrss_vf_limit"));
440 daemon_enabled
= getCookie("ttrss_vf_daemon");
442 // FIXME should be callled after window resize
444 if (navigator
.userAgent
.match("Opera")) {
445 resize_feeds_frame();
447 /* // fix headlines frame height for Opera
448 var h = document.getElementById("headlines");
449 var c = document.getElementById("content");
450 var nh = document.body.scrollHeight * 0.25;
452 h.style.height = nh + "px";
453 c.style.height = c.scrollHeight - nh + "px"; */
457 debug("second stage ok");
460 exception_error("init_second_stage", e
);
464 function quickMenuChange() {
465 var chooser
= document
.getElementById("quickMenuChooser");
466 var opid
= chooser
[chooser
.selectedIndex
].id
;
468 chooser
.selectedIndex
= 0;
472 function quickMenuGo(opid
) {
475 if (opid
== "qmcPrefs") {
479 if (opid
== "qmcSearch") {
480 displayDlg("search", getActiveFeedId());
484 if (opid
== "qmcAddFeed") {
485 displayDlg("quickAddFeed");
489 if (opid
== "qmcRemoveFeed") {
490 var actid
= getActiveFeedId();
493 notify("Please select some feed first.");
497 if (confirm("Remove current feed?")) {
504 if (opid
== "qmcUpdateFeeds") {
505 scheduleFeedUpdate(true);
509 if (opid
== "qmcCatchupAll") {
514 if (opid
== "qmcShowOnlyUnread") {
519 if (opid
== "qmcAddFilter") {
520 displayDlg("quickAddFilter", getActiveFeedId());
523 exception_error("quickMenuGo", e
);
529 if (!xmlhttp_ready(xmlhttp
)) {
534 var link
= document
.getElementById("qafInput");
536 if (link
.value
.length
== 0) {
537 alert("Error: No feed URL given.");
538 } else if (link
.value
.match("http://") == null &&
539 link
.value
.match("https://") == null) {
540 alert("Error: Invalid feed URL.");
542 notify("Adding feed...");
546 var cat
= document
.getElementById("qafCat");
550 cat_id
= cat
[cat
.selectedIndex
].id
;
555 var feeds_doc
= window
.frames
["feeds-frame"].document
;
557 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
559 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
560 param_escape(link
.value
) + "&cid=" + param_escape(cat_id
), true);
561 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
569 function qfdDelete(feed_id
) {
571 notify("Removing feed...");
573 if (!xmlhttp_ready(xmlhttp
)) {
578 // var feeds_doc = window.frames["feeds-frame"].document;
579 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
581 _qfd_deleted_feed
= feed_id
;
583 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
584 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
589 function updateFeedTitle(t
) {
590 active_title_text
= t
;
594 function toggleDispRead() {
597 if (!xmlhttp_ready(xmlhttp
)) {
602 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
604 hide_read_feeds
= !hide_read_feeds
;
606 var query
= "backend.php?op=rpc&subop=setpref" +
607 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
609 xmlhttp
.open("GET", query
);
610 xmlhttp
.onreadystatechange
=hide_unread_callback
;
614 exception_error("toggleDispRead", e
);
618 function debug(msg
) {
619 var c
= document
.getElementById('debug_output');
620 if (c
&& c
.style
.display
== "block") {
621 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 20) {
622 c
.removeChild(c
.lastChild
);
626 var ts
= leading_zero(d
.getHours()) + ":" + leading_zero(d
.getMinutes()) +
627 ":" + leading_zero(d
.getSeconds());
628 c
.innerHTML
= "<li>[" + ts
+ "] " + msg
+ "</li>" + c
.innerHTML
;
632 function fatalError(code
, message
) {
634 var fe
= document
.getElementById("fatal_error");
635 var fc
= document
.getElementById("fatal_error_msg");
637 fc
.innerHTML
= "Code " + code
+ ": " + message
;
639 fe
.style
.display
= "block";
642 exception_error("fatalError", e
);