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 if (!daemon_enabled
) {
129 notify("All feeds updated.");
133 exception_error("refetch_callback", e
);
139 function backend_sanity_check_callback() {
141 if (xmlhttp
.readyState
== 4) {
145 if (!xmlhttp
.responseXML
) {
150 var reply
= xmlhttp
.responseXML
.firstChild
;
157 var error_code
= reply
.getAttribute("error-code");
159 if (error_code
&& error_code
!= 0) {
160 return fatalError(error_code
);
166 exception_error("backend_sanity_check_callback", e
);
171 function scheduleFeedUpdate(force
) {
173 if (!daemon_enabled
) {
174 notify("Updating feeds, please wait.");
175 updateTitle("Updating");
178 var query_str
= "backend.php?op=rpc&subop=";
181 query_str
= query_str
+ "forceUpdateAllFeeds";
183 query_str
= query_str
+ "updateAllFeeds";
188 if (firsttime_update
) {
189 firsttime_update
= false;
199 query_str
= query_str
+ "&omode=" + omode
;
200 query_str
= query_str
+ "&uctr=" + global_unread
;
203 if (xmlhttp_ready(xmlhttp
)) {
204 xmlhttp
.open("GET", query_str
, true);
205 xmlhttp
.onreadystatechange
=refetch_callback
;
212 function updateFeedList(silent
, fetch
) {
214 // if (silent != true) {
215 // notify("Loading feed list...");
218 var query_str
= "backend.php?op=feeds";
221 query_str
= query_str
+ "&tags=1";
224 if (getActiveFeedId()) {
225 query_str
= query_str
+ "&actid=" + getActiveFeedId();
228 if (fetch
) query_str
= query_str
+ "&fetch=yes";
230 var feeds_frame
= document
.getElementById("feeds-frame");
232 feeds_frame
.src
= query_str
;
235 function catchupAllFeeds() {
237 var query_str
= "backend.php?op=feeds&subop=catchupAll";
239 notify("Marking all feeds as read...");
241 var feeds_frame
= document
.getElementById("feeds-frame");
243 feeds_frame
.src
= query_str
;
250 function viewCurrentFeed(skip
, subop
) {
252 if (getActiveFeedId()) {
253 viewfeed(getActiveFeedId(), skip
, subop
);
255 disableContainerChildren("headlinesToolbar", false, document
);
256 viewfeed(-1, skip
, subop
); // FIXME
260 function viewfeed(feed
, skip
, subop
) {
261 var f
= window
.frames
["feeds-frame"];
262 f
.viewfeed(feed
, skip
, subop
);
266 scheduleFeedUpdate(false);
268 var refresh_time
= getCookie('ttrss_vf_refresh');
270 if (!refresh_time
) refresh_time
= 600;
272 setTimeout("timeout()", refresh_time
*1000);
275 function resetSearch() {
276 var searchbox
= document
.getElementById("searchbox")
278 if (searchbox
.value
!= "" && getActiveFeedId()) {
279 searchbox
.value
= "";
280 viewfeed(getActiveFeedId(), 0, "");
286 viewCurrentFeed(0, "");
289 function localPiggieFunction(enable
) {
291 var query_str
= "backend.php?op=feeds&subop=piggie";
293 if (xmlhttp_ready(xmlhttp
)) {
295 xmlhttp
.open("GET", query_str
, true);
296 xmlhttp
.onreadystatechange
=feedlist_callback
;
302 function localHotkeyHandler(keycode
) {
304 if (keycode
== 82) { // r
305 return scheduleFeedUpdate(true);
308 if (keycode
== 85) { // u
309 if (getActiveFeedId()) {
310 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
314 if (keycode
== 65) { // a
315 return toggleDispRead();
318 var f_doc
= window
.frames
["feeds-frame"].document
;
319 var feedlist
= f_doc
.getElementById('feedList');
321 if (keycode
== 74) { // j
322 var feed
= getActiveFeedId();
323 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'prev');
324 if (new_feed
) viewfeed(new_feed
, 0, '');
327 if (keycode
== 75) { // k
328 var feed
= getActiveFeedId();
329 var new_feed
= getRelativeFeedId(feedlist
, feed
, 'next');
330 if (new_feed
) viewfeed(new_feed
, 0, '');
333 // notify("KC: " + keycode);
337 // if argument is undefined, current subtitle is not updated
338 // use blank string to clear subtitle
339 function updateTitle(s
) {
340 var tmp
= "Tiny Tiny RSS";
342 if (s
!= undefined) {
343 current_subtitle
= s
;
346 if (global_unread
> 0) {
347 tmp
= tmp
+ " (" + global_unread
+ ")";
350 if (current_subtitle
) {
351 tmp
= tmp
+ " - " + current_subtitle
;
354 if (active_title_text
.length
> 0) {
355 tmp
= tmp
+ " > " + active_title_text
;
358 document
.title
= tmp
;
361 function genericSanityCheck() {
363 if (!xmlhttp
) fatalError(1);
365 setCookie("ttrss_vf_test", "TEST");
367 if (getCookie("ttrss_vf_test") != "TEST") {
378 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
380 if (arguments
.callee
.done
) return;
381 arguments
.callee
.done
= true;
383 disableContainerChildren("headlinesToolbar", true);
385 if (!genericSanityCheck())
388 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
389 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
393 exception_error("init", e
);
397 function init_second_stage() {
401 setCookie("ttrss_vf_actfeed", "");
403 updateFeedList(false, false);
404 document
.onkeydown
= hotkey_handler
;
406 var viewbox
= document
.getElementById("viewbox");
407 var limitbox
= document
.getElementById("limitbox");
409 dropboxSelect(viewbox
, getCookie("ttrss_vf_vmode"));
410 dropboxSelect(limitbox
, getCookie("ttrss_vf_limit"));
412 daemon_enabled
= getCookie("ttrss_vf_daemon");
414 if (navigator
.userAgent
.match("Opera")) {
415 var f
= document
.getElementById("feeds-frame");
416 f
.style
.height
= document
.body
.scrollHeight
- 200 + "px";
420 exception_error("init_second_stage", e
);
424 function quickMenuChange() {
425 var chooser
= document
.getElementById("quickMenuChooser");
426 var opid
= chooser
[chooser
.selectedIndex
].id
;
428 chooser
.selectedIndex
= 0;
432 function quickMenuGo(opid
) {
435 if (opid
== "qmcPrefs") {
439 if (opid
== "qmcSearch") {
440 displayDlg("search", getActiveFeedId());
444 if (opid
== "qmcAddFeed") {
445 displayDlg("quickAddFeed");
449 if (opid
== "qmcRemoveFeed") {
450 var actid
= getActiveFeedId();
453 notify("Please select some feed first.");
457 if (confirm("Remove current feed?")) {
464 if (opid
== "qmcUpdateFeeds") {
465 scheduleFeedUpdate(true);
469 if (opid
== "qmcCatchupAll") {
474 if (opid
== "qmcShowOnlyUnread") {
479 if (opid
== "qmcAddFilter") {
480 displayDlg("quickAddFilter", getActiveFeedId());
487 if (!xmlhttp_ready(xmlhttp
)) {
492 var link
= document
.getElementById("qafInput");
494 if (link
.value
.length
== 0) {
495 notify("Missing feed URL.");
497 notify("Adding feed...");
499 var cat
= document
.getElementById("qafCat");
503 cat_id
= cat
[cat
.selectedIndex
].id
;
508 var feeds_doc
= window
.frames
["feeds-frame"].document
;
510 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
512 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
513 param_escape(link
.value
) + "&cid=" + param_escape(cat_id
), true);
514 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
522 function qaddFilter() {
524 if (!xmlhttp_ready(xmlhttp
)) {
529 var regexp
= document
.getElementById("fadd_regexp");
530 var match
= document
.getElementById("fadd_match");
531 var feed
= document
.getElementById("fadd_feed");
532 var action
= document
.getElementById("fadd_action");
534 if (regexp
.value
.length
== 0) {
535 notify("Missing filter expression.");
537 notify("Adding filter...");
539 var v_match
= match
[match
.selectedIndex
].text
;
540 var feed_id
= feed
[feed
.selectedIndex
].id
;
541 var action_id
= action
[action
.selectedIndex
].id
;
543 xmlhttp
.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
544 param_escape(regexp
.value
) + "&match=" + v_match
+
545 "&fid=" + param_escape(feed_id
) + "&aid=" + param_escape(action_id
), true);
547 xmlhttp
.onreadystatechange
=dlg_submit_callback
;
556 function displayDlg(id
, param
) {
558 if (!xmlhttp_ready(xmlhttp
)) {
565 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
566 param_escape(id
) + "¶m=" + param_escape(param
), true);
567 xmlhttp
.onreadystatechange
=dlg_display_callback
;
573 function closeDlg() {
574 var dlg
= document
.getElementById("userDlgShadow");
575 dlg
.style
.display
= "none";
579 function qfdDelete(feed_id
) {
581 notify("Removing feed...");
583 if (!xmlhttp_ready(xmlhttp
)) {
588 // var feeds_doc = window.frames["feeds-frame"].document;
589 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
591 _qfd_deleted_feed
= feed_id
;
593 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
594 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
599 function allFeedsMenuChange() {
600 var chooser
= document
.getElementById("allFeedsChooser");
602 var opname
= chooser
[chooser
.selectedIndex
].text
;
604 chooser
.selectedIndex
= 0;
606 if (opname
== "Update") {
607 scheduleFeedUpdate(true);
611 if (opname
== "Mark as read") {
616 if (opname
== "Show only unread") {
623 function updateFeedTitle(t
) {
624 active_title_text
= t
;
628 function toggleDispRead() {
631 if (!xmlhttp_ready(xmlhttp
)) {
636 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
638 hide_read_feeds
= !hide_read_feeds
;
640 var query
= "backend.php?op=rpc&subop=setpref" +
641 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
643 xmlhttp
.open("GET", query
);
644 xmlhttp
.onreadystatechange
=hide_unread_callback
;
648 exception_error("toggleDispRead", e
);