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;
13 /*@if (@_jscript_version >= 5)
14 // JScript gives us Conditional compilation, we can cope with old IE versions.
15 // and security blocked creation of the objects.
17 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
20 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
27 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
28 xmlhttp
= new XMLHttpRequest();
31 function toggleTags() {
32 display_tags
= !display_tags
;
34 var p
= document
.getElementById("dispSwitchPrompt");
37 p
.innerHTML
= "display feeds";
39 p
.innerHTML
= "display tags";
45 function dlg_frefresh_callback() {
46 if (xmlhttp
.readyState
== 4) {
47 notify(xmlhttp
.responseText
);
48 updateFeedList(false, false);
49 if (_qfd_deleted_feed
) {
50 var hframe
= document
.getElementById("headlines-frame");
52 hframe
.src
= "backend.php?op=error&msg=No%20feed%20selected.";
59 function dlg_submit_callback() {
60 if (xmlhttp
.readyState
== 4) {
61 notify(xmlhttp
.responseText
);
66 function dlg_display_callback() {
67 if (xmlhttp
.readyState
== 4) {
68 var dlg
= document
.getElementById("userDlg");
69 var dlg_s
= document
.getElementById("userDlgShadow");
71 dlg
.innerHTML
= xmlhttp
.responseText
;
72 dlg_s
.style
.display
= "block";
76 function hide_unread_callback() {
77 if (xmlhttp
.readyState
== 4) {
81 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
82 var value
= reply
.getAttribute("value");
83 var hide_read_feeds
= (value
!= "false")
84 var feeds_doc
= window
.frames
["feeds-frame"].document
;
86 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
88 if (hide_read_feeds
) {
89 setCookie("ttrss_vf_hreadf", 1);
91 setCookie("ttrss_vf_hreadf", 0);
95 exception_error("hide_unread_callback", e
);
101 function refetch_callback() {
102 if (xmlhttp
.readyState
== 4) {
105 if (!xmlhttp
.responseXML
) {
106 notify("refetch_callback: backend did not return valid XML");
110 var reply
= xmlhttp
.responseXML
.firstChild
;
113 notify("refetch_callback: backend did not return expected XML object");
118 var error_code
= reply
.getAttribute("error-code");
120 if (error_code
&& error_code
!= 0) {
121 return fatalError(error_code
);
124 var f_document
= window
.frames
["feeds-frame"].document
;
126 parse_counters(reply
, f_document
, window
);
128 debug("refetch_callback: done");
130 if (!daemon_enabled
) {
131 notify("All feeds updated.");
137 exception_error("refetch_callback", e
);
143 function backend_sanity_check_callback() {
145 if (xmlhttp
.readyState
== 4) {
149 if (!xmlhttp
.responseXML
) {
150 fatalError(3, "D001;" + xmlhttp
.responseText
);
154 var reply
= xmlhttp
.responseXML
.firstChild
;
157 fatalError(3, "D002;" + xmlhttp
.responseText
);
161 var error_code
= reply
.getAttribute("error-code");
163 if (error_code
&& error_code
!= 0) {
164 return fatalError(error_code
);
167 debug("sanity check ok");
172 exception_error("backend_sanity_check_callback", e
);
177 function scheduleFeedUpdate(force
) {
179 if (!daemon_enabled
) {
180 notify("Updating feeds, please wait.");
181 updateTitle("Updating");
184 var query_str
= "backend.php?op=rpc&subop=";
187 query_str
= query_str
+ "forceUpdateAllFeeds";
189 query_str
= query_str
+ "updateAllFeeds";
194 if (firsttime_update
&& !navigator
.userAgent
.match("Opera")) {
195 firsttime_update
= false;
205 query_str
= query_str
+ "&omode=" + omode
;
206 query_str
= query_str
+ "&uctr=" + global_unread
;
208 debug("in scheduleFeedUpdate");
210 if (xmlhttp_ready(xmlhttp
)) {
211 xmlhttp
.open("GET", query_str
, true);
212 xmlhttp
.onreadystatechange
=refetch_callback
;
219 function updateFeedList(silent
, fetch
) {
221 // if (silent != true) {
222 // notify("Loading feed list...");
225 var query_str
= "backend.php?op=feeds";
228 query_str
= query_str
+ "&tags=1";
231 if (getActiveFeedId()) {
232 query_str
= query_str
+ "&actid=" + getActiveFeedId();
235 if (navigator
.userAgent
.match("Opera")) {
236 var date
= new Date();
237 var timestamp
= Math
.round(date
.getTime() / 1000);
238 query_str
= query_str
+ "&ts=" + timestamp
241 if (fetch
) query_str
= query_str
+ "&fetch=yes";
243 var feeds_frame
= document
.getElementById("feeds-frame");
245 feeds_frame
.src
= query_str
;
248 function catchupAllFeeds() {
250 var query_str
= "backend.php?op=feeds&subop=catchupAll";
252 notify("Marking all feeds as read...");
254 var feeds_frame
= document
.getElementById("feeds-frame");
256 feeds_frame
.src
= query_str
;
263 function viewCurrentFeed(skip
, subop
) {
265 if (getActiveFeedId()) {
266 viewfeed(getActiveFeedId(), skip
, subop
);
268 disableContainerChildren("headlinesToolbar", false, document
);
269 viewfeed(-1, skip
, subop
); // FIXME
273 function viewfeed(feed
, skip
, subop
) {
274 var f
= window
.frames
["feeds-frame"];
275 f
.viewfeed(feed
, skip
, subop
);
279 scheduleFeedUpdate(false);
281 var refresh_time
= getCookie('ttrss_vf_refresh');
283 if (!refresh_time
) refresh_time
= 600;
285 setTimeout("timeout()", refresh_time
*1000);
288 function resetSearch() {
289 var searchbox
= document
.getElementById("searchbox")
291 if (searchbox
.value
!= "" && getActiveFeedId()) {
292 searchbox
.value
= "";
293 viewfeed(getActiveFeedId(), 0, "");
299 viewCurrentFeed(0, "");
302 function localPiggieFunction(enable
) {
304 var query_str
= "backend.php?op=feeds&subop=piggie";
306 if (xmlhttp_ready(xmlhttp
)) {
308 xmlhttp
.open("GET", query_str
, true);
309 xmlhttp
.onreadystatechange
=feedlist_callback
;
315 function localHotkeyHandler(keycode
) {
317 if (keycode
== 82) { // r
318 return scheduleFeedUpdate(true);
321 if (keycode
== 85) { // u
322 if (getActiveFeedId()) {
323 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
327 if (keycode
== 65) { // a
328 return toggleDispRead();
331 var f_doc
= window
.frames
["feeds-frame"].document
;
332 var feedlist
= f_doc
.getElementById('feedList');
334 if (keycode
== 74) { // j
335 var feed
= getActiveFeedId();
336 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
337 if (new_feed
) viewfeed(new_feed
, 0, '');
340 if (keycode
== 75) { // k
341 var feed
= getActiveFeedId();
342 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
343 if (new_feed
) viewfeed(new_feed
, 0, '');
346 // notify("KC: " + keycode);
350 // if argument is undefined, current subtitle is not updated
351 // use blank string to clear subtitle
352 function updateTitle(s
) {
353 var tmp
= "Tiny Tiny RSS";
355 if (s
!= undefined) {
356 current_subtitle
= s
;
359 if (global_unread
> 0) {
360 tmp
= tmp
+ " (" + global_unread
+ ")";
363 if (current_subtitle
) {
364 tmp
= tmp
+ " - " + current_subtitle
;
367 if (active_title_text
.length
> 0) {
368 tmp
= tmp
+ " > " + active_title_text
;
371 document
.title
= tmp
;
374 function genericSanityCheck() {
376 if (!xmlhttp
) fatalError(1);
378 setCookie("ttrss_vf_test", "TEST");
380 if (getCookie("ttrss_vf_test") != "TEST") {
391 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
393 if (arguments
.callee
.done
) return;
394 arguments
.callee
.done
= true;
396 disableContainerChildren("headlinesToolbar", true);
398 if (!genericSanityCheck())
401 if (getURLParam('debug')) {
402 document
.getElementById('debug_output').style
.display
= 'block';
403 debug('debug mode activated');
406 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
407 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
411 exception_error("init", e
);
415 function resize_feeds_frame() {
416 var f
= document
.getElementById("feeds-frame");
417 var tf
= document
.getElementById("mainFooter");
418 var th
= document
.getElementById("mainHeader");
420 f
.style
.height
= document
.body
.scrollHeight
- tf
.scrollHeight
-
421 th
.scrollHeight
- 50 + "px";
424 function init_second_stage() {
428 setCookie("ttrss_vf_actfeed", "");
430 updateFeedList(false, false);
431 document
.onkeydown
= hotkey_handler
;
433 var viewbox
= document
.getElementById("viewbox");
434 var limitbox
= document
.getElementById("limitbox");
436 dropboxSelect(viewbox
, getCookie("ttrss_vf_vmode"));
437 dropboxSelect(limitbox
, getCookie("ttrss_vf_limit"));
439 daemon_enabled
= getCookie("ttrss_vf_daemon");
441 // FIXME should be callled after window resize
443 if (navigator
.userAgent
.match("Opera")) {
444 resize_feeds_frame();
446 /* // fix headlines frame height for Opera
447 var h = document.getElementById("headlines");
448 var c = document.getElementById("content");
449 var nh = document.body.scrollHeight * 0.25;
451 h.style.height = nh + "px";
452 c.style.height = c.scrollHeight - nh + "px"; */
456 debug("second stage ok");
459 exception_error("init_second_stage", e
);
463 function quickMenuChange() {
464 var chooser
= document
.getElementById("quickMenuChooser");
465 var opid
= chooser
[chooser
.selectedIndex
].id
;
467 chooser
.selectedIndex
= 0;
471 function quickMenuGo(opid
) {
474 if (opid
== "qmcPrefs") {
478 if (opid
== "qmcSearch") {
479 displayDlg("search", getActiveFeedId());
483 if (opid
== "qmcAddFeed") {
484 displayDlg("quickAddFeed");
488 if (opid
== "qmcRemoveFeed") {
489 var actid
= getActiveFeedId();
492 notify("Please select some feed first.");
496 if (confirm("Remove current feed?")) {
503 if (opid
== "qmcUpdateFeeds") {
504 scheduleFeedUpdate(true);
508 if (opid
== "qmcCatchupAll") {
513 if (opid
== "qmcShowOnlyUnread") {
518 if (opid
== "qmcAddFilter") {
519 displayDlg("quickAddFilter", getActiveFeedId());
526 if (!xmlhttp_ready(xmlhttp
)) {
531 var link
= document
.getElementById("qafInput");
533 if (link
.value
.length
== 0) {
534 notify("Missing feed URL.");
536 notify("Adding feed...");
538 var cat
= document
.getElementById("qafCat");
542 cat_id
= cat
[cat
.selectedIndex
].id
;
547 var feeds_doc
= window
.frames
["feeds-frame"].document
;
549 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
551 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
552 param_escape(link
.value
) + "&cid=" + param_escape(cat_id
), true);
553 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
561 function qaddFilter() {
563 if (!xmlhttp_ready(xmlhttp
)) {
568 var regexp
= document
.getElementById("fadd_regexp");
569 var match
= document
.getElementById("fadd_match");
570 var feed
= document
.getElementById("fadd_feed");
571 var action
= document
.getElementById("fadd_action");
573 if (regexp
.value
.length
== 0) {
574 notify("Missing filter expression.");
576 notify("Adding filter...");
578 var v_match
= match
[match
.selectedIndex
].text
;
579 var feed_id
= feed
[feed
.selectedIndex
].id
;
580 var action_id
= action
[action
.selectedIndex
].id
;
582 xmlhttp
.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
583 param_escape(regexp
.value
) + "&match=" + v_match
+
584 "&fid=" + param_escape(feed_id
) + "&aid=" + param_escape(action_id
), true);
586 xmlhttp
.onreadystatechange
=dlg_submit_callback
;
595 function displayDlg(id
, param
) {
597 if (!xmlhttp_ready(xmlhttp
)) {
604 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
605 param_escape(id
) + "¶m=" + param_escape(param
), true);
606 xmlhttp
.onreadystatechange
=dlg_display_callback
;
612 function closeDlg() {
613 var dlg
= document
.getElementById("userDlgShadow");
614 dlg
.style
.display
= "none";
618 function qfdDelete(feed_id
) {
620 notify("Removing feed...");
622 if (!xmlhttp_ready(xmlhttp
)) {
627 // var feeds_doc = window.frames["feeds-frame"].document;
628 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
630 _qfd_deleted_feed
= feed_id
;
632 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
633 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
638 function allFeedsMenuChange() {
639 var chooser
= document
.getElementById("allFeedsChooser");
641 var opname
= chooser
[chooser
.selectedIndex
].text
;
643 chooser
.selectedIndex
= 0;
645 if (opname
== "Update") {
646 scheduleFeedUpdate(true);
650 if (opname
== "Mark as read") {
655 if (opname
== "Show only unread") {
662 function updateFeedTitle(t
) {
663 active_title_text
= t
;
667 function toggleDispRead() {
670 if (!xmlhttp_ready(xmlhttp
)) {
675 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
677 hide_read_feeds
= !hide_read_feeds
;
679 var query
= "backend.php?op=rpc&subop=setpref" +
680 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
682 xmlhttp
.open("GET", query
);
683 xmlhttp
.onreadystatechange
=hide_unread_callback
;
687 exception_error("toggleDispRead", e
);
691 function debug(msg
) {
692 var c
= document
.getElementById('debug_output');
693 if (c
&& c
.style
.display
== "block") {
694 while (c
.lastChild
!= 'undefined' && c
.childNodes
.length
> 20) {
695 c
.removeChild(c
.lastChild
);
699 var ts
= d
.getHours() + ":" + d
.getMinutes() + ":" + d
.getSeconds();
700 c
.innerHTML
= "<li>[" + ts
+ "] " + msg
+ "</li>" + c
.innerHTML
;