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 resize_feeds_frame() {
398 var f
= document
.getElementById("feeds-frame");
399 var tf
= document
.getElementById("mainFooter");
400 var th
= document
.getElementById("mainHeader");
402 f
.style
.height
= document
.body
.scrollHeight
- tf
.scrollHeight
-
403 th
.scrollHeight
- 50 + "px";
406 function init_second_stage() {
410 setCookie("ttrss_vf_actfeed", "");
412 updateFeedList(false, false);
413 document
.onkeydown
= hotkey_handler
;
415 var viewbox
= document
.getElementById("viewbox");
416 var limitbox
= document
.getElementById("limitbox");
418 dropboxSelect(viewbox
, getCookie("ttrss_vf_vmode"));
419 dropboxSelect(limitbox
, getCookie("ttrss_vf_limit"));
421 daemon_enabled
= getCookie("ttrss_vf_daemon");
423 // FIXME should be callled after window resize
425 if (navigator
.userAgent
.match("Opera")) {
426 resize_feeds_frame();
428 // fix headlines frame height for Opera
429 var h
= document
.getElementById("headlines");
430 var c
= document
.getElementById("content");
431 var nh
= document
.body
.scrollHeight
* 0.25;
433 h
.style
.height
= nh
+ "px";
434 c
.style
.height
= c
.scrollHeight
- nh
+ "px";
439 exception_error("init_second_stage", e
);
443 function quickMenuChange() {
444 var chooser
= document
.getElementById("quickMenuChooser");
445 var opid
= chooser
[chooser
.selectedIndex
].id
;
447 chooser
.selectedIndex
= 0;
451 function quickMenuGo(opid
) {
454 if (opid
== "qmcPrefs") {
458 if (opid
== "qmcSearch") {
459 displayDlg("search", getActiveFeedId());
463 if (opid
== "qmcAddFeed") {
464 displayDlg("quickAddFeed");
468 if (opid
== "qmcRemoveFeed") {
469 var actid
= getActiveFeedId();
472 notify("Please select some feed first.");
476 if (confirm("Remove current feed?")) {
483 if (opid
== "qmcUpdateFeeds") {
484 scheduleFeedUpdate(true);
488 if (opid
== "qmcCatchupAll") {
493 if (opid
== "qmcShowOnlyUnread") {
498 if (opid
== "qmcAddFilter") {
499 displayDlg("quickAddFilter", getActiveFeedId());
506 if (!xmlhttp_ready(xmlhttp
)) {
511 var link
= document
.getElementById("qafInput");
513 if (link
.value
.length
== 0) {
514 notify("Missing feed URL.");
516 notify("Adding feed...");
518 var cat
= document
.getElementById("qafCat");
522 cat_id
= cat
[cat
.selectedIndex
].id
;
527 var feeds_doc
= window
.frames
["feeds-frame"].document
;
529 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
531 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
532 param_escape(link
.value
) + "&cid=" + param_escape(cat_id
), true);
533 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
541 function qaddFilter() {
543 if (!xmlhttp_ready(xmlhttp
)) {
548 var regexp
= document
.getElementById("fadd_regexp");
549 var match
= document
.getElementById("fadd_match");
550 var feed
= document
.getElementById("fadd_feed");
551 var action
= document
.getElementById("fadd_action");
553 if (regexp
.value
.length
== 0) {
554 notify("Missing filter expression.");
556 notify("Adding filter...");
558 var v_match
= match
[match
.selectedIndex
].text
;
559 var feed_id
= feed
[feed
.selectedIndex
].id
;
560 var action_id
= action
[action
.selectedIndex
].id
;
562 xmlhttp
.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
563 param_escape(regexp
.value
) + "&match=" + v_match
+
564 "&fid=" + param_escape(feed_id
) + "&aid=" + param_escape(action_id
), true);
566 xmlhttp
.onreadystatechange
=dlg_submit_callback
;
575 function displayDlg(id
, param
) {
577 if (!xmlhttp_ready(xmlhttp
)) {
584 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
585 param_escape(id
) + "¶m=" + param_escape(param
), true);
586 xmlhttp
.onreadystatechange
=dlg_display_callback
;
592 function closeDlg() {
593 var dlg
= document
.getElementById("userDlgShadow");
594 dlg
.style
.display
= "none";
598 function qfdDelete(feed_id
) {
600 notify("Removing feed...");
602 if (!xmlhttp_ready(xmlhttp
)) {
607 // var feeds_doc = window.frames["feeds-frame"].document;
608 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
610 _qfd_deleted_feed
= feed_id
;
612 xmlhttp
.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id
);
613 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
618 function allFeedsMenuChange() {
619 var chooser
= document
.getElementById("allFeedsChooser");
621 var opname
= chooser
[chooser
.selectedIndex
].text
;
623 chooser
.selectedIndex
= 0;
625 if (opname
== "Update") {
626 scheduleFeedUpdate(true);
630 if (opname
== "Mark as read") {
635 if (opname
== "Show only unread") {
642 function updateFeedTitle(t
) {
643 active_title_text
= t
;
647 function toggleDispRead() {
650 if (!xmlhttp_ready(xmlhttp
)) {
655 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
657 hide_read_feeds
= !hide_read_feeds
;
659 var query
= "backend.php?op=rpc&subop=setpref" +
660 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds
);
662 xmlhttp
.open("GET", query
);
663 xmlhttp
.onreadystatechange
=hide_unread_callback
;
667 exception_error("toggleDispRead", e
);