6 var display_tags
= false;
8 var global_unread
= -1;
10 var active_title_text
= "";
12 var current_subtitle
= "";
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);
55 function dlg_submit_callback() {
56 if (xmlhttp
.readyState
== 4) {
57 notify(xmlhttp
.responseText
);
62 function dlg_display_callback() {
63 if (xmlhttp
.readyState
== 4) {
64 var dlg
= document
.getElementById("userDlg");
65 var dlg_s
= document
.getElementById("userDlgShadow");
67 dlg
.innerHTML
= xmlhttp
.responseText
;
68 dlg_s
.style
.display
= "block";
72 function refetch_callback() {
73 if (xmlhttp
.readyState
== 4) {
76 if (!xmlhttp
.responseXML
) {
77 notify("refetch_callback: backend did not return valid XML");
81 var reply
= xmlhttp
.responseXML
.firstChild
;
84 notify("refetch_callback: backend did not return expected XML object");
88 var error_code
= reply
.getAttribute("error-code");
90 if (error_code
&& error_code
!= 0) {
91 return fatalError(error_code
);
94 var f_document
= window
.frames
["feeds-frame"].document
;
96 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
97 var id
= reply
.childNodes
[l
].getAttribute("id");
98 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
100 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
101 var feedu
= f_document
.getElementById("FEEDU-" + id
);
102 var feedr
= f_document
.getElementById("FEEDR-" + id
);
104 if (id
== "global-unread") {
109 if (feedctr
&& feedu
&& feedr
) {
111 feedu
.innerHTML
= ctr
;
114 feedctr
.className
= "odd";
115 if (!feedr
.className
.match("Unread")) {
116 feedr
.className
= feedr
.className
+ "Unread";
119 feedctr
.className
= "invisible";
120 feedr
.className
= feedr
.className
.replace("Unread", "");
126 notify("All feeds updated.");
128 exception_error("refetch_callback", e
);
133 function backend_sanity_check_callback() {
135 if (xmlhttp
.readyState
== 4) {
139 if (!xmlhttp
.responseXML
) {
144 var reply
= xmlhttp
.responseXML
.firstChild
;
151 var error_code
= reply
.getAttribute("error-code");
153 if (error_code
&& error_code
!= 0) {
154 return fatalError(error_code
);
160 exception_error("backend_sanity_check_callback", e
);
165 function scheduleFeedUpdate(force
) {
167 notify("Updating feeds in background...");
169 // document.title = "Tiny Tiny RSS - Updating...";
171 updateTitle("Updating");
173 var query_str
= "backend.php?op=rpc&subop=";
176 query_str
= query_str
+ "forceUpdateAllFeeds";
178 query_str
= query_str
+ "updateAllFeeds";
189 query_str
= query_str
+ "&omode=" + omode
;
191 if (xmlhttp_ready(xmlhttp
)) {
192 xmlhttp
.open("GET", query_str
, true);
193 xmlhttp
.onreadystatechange
=refetch_callback
;
200 function updateFeedList(silent
, fetch
) {
202 // if (silent != true) {
203 // notify("Loading feed list...");
206 var query_str
= "backend.php?op=feeds";
209 query_str
= query_str
+ "&tags=1";
212 if (getActiveFeedId()) {
213 query_str
= query_str
+ "&actid=" + getActiveFeedId();
216 if (fetch
) query_str
= query_str
+ "&fetch=yes";
218 var feeds_frame
= document
.getElementById("feeds-frame");
220 feeds_frame
.src
= query_str
;
223 function catchupAllFeeds() {
225 var query_str
= "backend.php?op=feeds&subop=catchupAll";
227 notify("Marking all feeds as read...");
229 var feeds_frame
= document
.getElementById("feeds-frame");
231 feeds_frame
.src
= query_str
;
238 function viewCurrentFeed(skip
, subop
) {
240 if (getActiveFeedId()) {
241 viewfeed(getActiveFeedId(), skip
, subop
);
243 disableContainerChildren("headlinesToolbar", false, document
);
244 viewfeed(-1, skip
, subop
); // FIXME
248 function viewfeed(feed
, skip
, subop
) {
249 var f
= window
.frames
["feeds-frame"];
250 f
.viewfeed(feed
, skip
, subop
);
254 scheduleFeedUpdate(false);
255 setTimeout("timeout()", 1800*1000);
258 function resetSearch() {
259 var searchbox
= document
.getElementById("searchbox")
261 if (searchbox
.value
!= "" && getActiveFeedId()) {
262 searchbox
.value
= "";
263 viewfeed(getActiveFeedId(), 0, "");
268 viewCurrentFeed(0, "");
271 function localPiggieFunction(enable
) {
273 var query_str
= "backend.php?op=feeds&subop=piggie";
275 if (xmlhttp_ready(xmlhttp
)) {
277 xmlhttp
.open("GET", query_str
, true);
278 xmlhttp
.onreadystatechange
=feedlist_callback
;
284 function localHotkeyHandler(keycode
) {
286 /* if (keycode == 78) {
287 return moveToPost('next');
291 return moveToPost('prev');
294 if (keycode
== 82) { // r
295 return scheduleFeedUpdate(true);
298 if (keycode
== 85) { // u
299 if (getActiveFeedId()) {
300 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
304 if (keycode
== 65) { // a
305 return toggleDispRead();
308 var f_doc
= window
.frames
["feeds-frame"].document
;
309 var feedlist
= f_doc
.getElementById('feedList');
311 if (keycode
== 74) { // j
312 var feed
= getActiveFeedId();
313 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
314 if (new_feed
) viewfeed(new_feed
, 0, '');
317 if (keycode
== 75) { // k
318 var feed
= getActiveFeedId();
319 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
320 if (new_feed
) viewfeed(new_feed
, 0, '');
323 // notify("KC: " + keycode);
327 // if argument is undefined, current subtitle is not updated
328 // use blank string to clear subtitle
329 function updateTitle(s
) {
330 var tmp
= "Tiny Tiny RSS";
332 if (s
&& s
.length
> 0) {
333 current_subtitle
= s
;
336 if (global_unread
> 0) {
337 tmp
= tmp
+ " (" + global_unread
+ ")";
341 tmp
= tmp
+ " - " + current_subtitle
;
344 if (active_title_text
.length
> 0) {
345 tmp
= tmp
+ " > " + active_title_text
;
348 document
.title
= tmp
;
351 function genericSanityCheck() {
353 if (!xmlhttp
) fatalError(1);
355 setCookie("ttrss_vf_test", "TEST");
357 if (getCookie("ttrss_vf_test") != "TEST") {
368 disableContainerChildren("headlinesToolbar", true);
370 if (!genericSanityCheck())
373 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
374 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
378 exception_error("init", e
);
382 function init_second_stage() {
386 setCookie("ttrss_vf_actfeed", "");
388 updateFeedList(false, false);
389 document
.onkeydown
= hotkey_handler
;
391 var content
= document
.getElementById("content");
393 if (getCookie("ttrss_vf_vmode")) {
394 var viewbox
= document
.getElementById("viewbox");
395 viewbox
.value
= getCookie("ttrss_vf_vmode");
398 if (getCookie("ttrss_vf_limit")) {
399 var limitbox
= document
.getElementById("limitbox");
400 limitbox
.value
= getCookie("ttrss_vf_limit");
403 // if (getCookie("ttrss_vf_actfeed")) {
404 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
407 // setTimeout("timeout()", 2*1000);
408 // scheduleFeedUpdate(true);
411 exception_error("init_second_stage", e
);
415 function quickMenuGo() {
417 var chooser
= document
.getElementById("quickMenuChooser");
418 var opid
= chooser
[chooser
.selectedIndex
].id
;
420 if (opid
== "qmcPrefs") {
424 if (opid
== "qmcAdvSearch") {
425 displayDlg("search");
429 if (opid
== "qmcAddFeed") {
430 displayDlg("quickAddFeed");
434 if (opid
== "qmcRemoveFeed") {
435 var actid
= getActiveFeedId();
438 notify("Please select some feed first.");
442 if (confirm("Remove current feed?")) {
449 if (opid
== "qmcUpdateFeeds") {
450 scheduleFeedUpdate(true);
454 if (opid
== "qmcCatchupAll") {
459 if (opid
== "qmcShowOnlyUnread") {
464 if (opid
== "qmcAddFilter") {
465 displayDlg("quickAddFilter", getActiveFeedId());
472 if (!xmlhttp_ready(xmlhttp
)) {
477 var link
= document
.getElementById("qafInput");
479 if (link
.value
.length
== 0) {
480 notify("Missing feed URL.");
482 notify("Adding feed...");
484 var feeds_doc
= window
.frames
["feeds-frame"].document
;
486 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
488 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
489 param_escape(link
.value
), true);
490 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
498 function qaddFilter() {
500 if (!xmlhttp_ready(xmlhttp
)) {
505 var regexp
= document
.getElementById("fadd_regexp");
506 var match
= document
.getElementById("fadd_match");
507 var feed
= document
.getElementById("fadd_feed");
508 var action
= document
.getElementById("fadd_action");
510 if (regexp
.value
.length
== 0) {
511 notify("Missing filter expression.");
513 notify("Adding filter...");
515 var v_match
= match
[match
.selectedIndex
].text
;
516 var feed_id
= feed
[feed
.selectedIndex
].id
;
517 var action_id
= action
[action
.selectedIndex
].id
;
519 xmlhttp
.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
520 param_escape(regexp
.value
) + "&match=" + v_match
+
521 "&fid=" + param_escape(feed_id
) + "&aid=" + param_escape(action_id
), true);
523 xmlhttp
.onreadystatechange
=dlg_submit_callback
;
532 function displayDlg(id
, param
) {
536 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
537 param_escape(id
) + "¶m=" + param_escape(param
), true);
538 xmlhttp
.onreadystatechange
=dlg_display_callback
;
543 function closeDlg() {
544 var dlg
= document
.getElementById("userDlgShadow");
545 dlg
.style
.display
= "none";
548 function qfdDelete(feed_id
) {
550 notify("Removing feed...");
552 // var feeds_doc = window.frames["feeds-frame"].document;
553 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
555 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
556 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
561 function allFeedsMenuGo() {
562 var chooser
= document
.getElementById("allFeedsChooser");
564 var opname
= chooser
[chooser
.selectedIndex
].text
;
566 if (opname
== "Update") {
567 scheduleFeedUpdate(true);
571 if (opname
== "Mark as read") {
576 if (opname
== "Show only unread") {
583 function updateFeedTitle(t
) {
584 active_title_text
= t
;
588 function toggleDispRead() {
589 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
591 hide_read_feeds
= !hide_read_feeds
;
593 var feeds_doc
= window
.frames
["feeds-frame"].document
;
595 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
597 if (hide_read_feeds
) {
598 setCookie("ttrss_vf_hreadf", 1);
600 setCookie("ttrss_vf_hreadf", 0);