2 This program is Copyright (c) 2003-2005 Andrew Dolgov <cthulhoo@gmail.com>
3 Licensed under GPL v.2 or (at your preference) any later version.
11 var display_tags
= false;
13 var global_unread
= 0;
16 /*@if (@_jscript_version >= 5)
17 // JScript gives us Conditional compilation, we can cope with old IE versions.
18 // and security blocked creation of the objects.
20 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
23 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
30 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
31 xmlhttp
= new XMLHttpRequest();
34 function toggleTags() {
35 display_tags
= !display_tags
;
37 var p
= document
.getElementById("dispSwitchPrompt");
40 p
.innerHTML
= "display feeds";
42 p
.innerHTML
= "display tags";
48 function dlg_frefresh_callback() {
49 if (xmlhttp
.readyState
== 4) {
50 updateFeedList(false, false);
55 function dialog_refresh_callback() {
56 if (xmlhttp
.readyState
== 4) {
57 var dlg
= document
.getElementById("userDlg");
59 dlg
.innerHTML
= xmlhttp
.responseText
;
60 dlg
.style
.display
= "block";
64 function refetch_callback() {
65 if (xmlhttp
.readyState
== 4) {
67 // document.title = "Tiny Tiny RSS";
69 if (!xmlhttp
.responseXML
) {
70 notify("refetch_callback: backend did not return valid XML");
74 var reply
= xmlhttp
.responseXML
.firstChild
;
77 notify("refetch_callback: backend did not return expected XML object");
81 var error_code
= reply
.getAttribute("error-code");
83 if (error_code
&& error_code
!= 0) {
84 return fatalError(error_code
);
87 var f_document
= window
.frames
["feeds-frame"].document
;
89 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
90 var id
= reply
.childNodes
[l
].getAttribute("id");
91 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
93 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
94 var feedu
= f_document
.getElementById("FEEDU-" + id
);
95 var feedr
= f_document
.getElementById("FEEDR-" + id
);
97 /* TODO figure out how to update this from viewfeed.js->view()
100 if (id == "global-unread") {
104 if (feedctr
&& feedu
&& feedr
) {
106 feedu
.innerHTML
= ctr
;
109 feedctr
.className
= "odd";
110 if (!feedr
.className
.match("Unread")) {
111 feedr
.className
= feedr
.className
+ "Unread";
114 feedctr
.className
= "invisible";
115 feedr
.className
= feedr
.className
.replace("Unread", "");
121 notify("All feeds updated.");
126 function backend_sanity_check_callback() {
128 if (xmlhttp
.readyState
== 4) {
130 if (!xmlhttp
.responseXML
) {
135 var reply
= xmlhttp
.responseXML
.firstChild
;
142 var error_code
= reply
.getAttribute("error-code");
144 if (error_code
&& error_code
!= 0) {
145 return fatalError(error_code
);
152 /* wtf this is obsolete
153 function updateFeed(feed_id) {
155 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
157 if (xmlhttp_ready(xmlhttp)) {
158 xmlhttp.open("GET", query_str, true);
159 xmlhttp.onreadystatechange=feed_update_callback;
168 function scheduleFeedUpdate(force
) {
170 notify("Updating feeds in background...");
172 // document.title = "Tiny Tiny RSS - Updating...";
174 updateTitle("Updating...");
176 var query_str
= "backend.php?op=rpc&subop=";
179 query_str
= query_str
+ "forceUpdateAllFeeds";
181 query_str
= query_str
+ "updateAllFeeds";
192 query_str
= query_str
+ "&omode=" + omode
;
194 if (xmlhttp_ready(xmlhttp
)) {
195 xmlhttp
.open("GET", query_str
, true);
196 xmlhttp
.onreadystatechange
=refetch_callback
;
203 function updateFeedList(silent
, fetch
) {
205 // if (silent != true) {
206 // notify("Loading feed list...");
209 var query_str
= "backend.php?op=feeds";
212 query_str
= query_str
+ "&tags=1";
215 if (getActiveFeedId()) {
216 query_str
= query_str
+ "&actid=" + getActiveFeedId();
219 if (fetch
) query_str
= query_str
+ "&fetch=yes";
221 var feeds_frame
= document
.getElementById("feeds-frame");
223 feeds_frame
.src
= query_str
;
226 function catchupAllFeeds() {
228 var query_str
= "backend.php?op=feeds&subop=catchupAll";
230 notify("Marking all feeds as read...");
232 var feeds_frame
= document
.getElementById("feeds-frame");
234 feeds_frame
.src
= query_str
;
241 function viewCurrentFeed(skip
, subop
) {
243 if (getActiveFeedId()) {
244 viewfeed(getActiveFeedId(), skip
, subop
);
246 disableContainerChildren("headlinesToolbar", false, document
);
247 viewfeed(-1, skip
, subop
); // FIXME
251 function viewfeed(feed
, skip
, subop
) {
252 var f
= window
.frames
["feeds-frame"];
253 f
.viewfeed(feed
, skip
, subop
);
257 scheduleFeedUpdate(false);
258 setTimeout("timeout()", 1800*1000);
261 function resetSearch() {
262 var searchbox
= document
.getElementById("searchbox")
264 if (searchbox
.value
!= "" && getActiveFeedId()) {
265 searchbox
.value
= "";
266 viewfeed(getActiveFeedId(), 0, "");
271 viewCurrentFeed(0, "");
274 function localPiggieFunction(enable
) {
276 var query_str
= "backend.php?op=feeds&subop=piggie";
278 if (xmlhttp_ready(xmlhttp
)) {
280 xmlhttp
.open("GET", query_str
, true);
281 xmlhttp
.onreadystatechange
=feedlist_callback
;
287 function localHotkeyHandler(keycode
) {
289 /* if (keycode == 78) {
290 return moveToPost('next');
294 return moveToPost('prev');
297 if (keycode
== 82) { // r
298 return scheduleFeedUpdate(true);
301 if (keycode
== 85) { // u
302 if (getActiveFeedId()) {
303 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
307 if (keycode
== 65) { // a
308 return toggleDispRead();
311 // notify("KC: " + keycode);
315 function updateTitle(s
) {
316 var tmp
= "Tiny Tiny RSS";
318 if (global_unread
> 0) {
319 tmp
= tmp
+ " (" + global_unread
+ ")";
323 tmp
= tmp
+ " - " + s
;
325 document
.title
= tmp
;
328 function genericSanityCheck() {
330 if (!xmlhttp
) fatalError(1);
332 setCookie("ttrss_vf_test", "TEST");
334 if (getCookie("ttrss_vf_test") != "TEST") {
339 document.getElementById("headlines").innerHTML =
340 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
341 "to function properly. Your browser doesn't seem to support it.";
345 setCookie("ttrss_vf_test", "TEST");
346 if (getCookie("ttrss_vf_test") != "TEST") {
348 document.getElementById("headlines").innerHTML =
349 "<b>Fatal error:</b> This program requires cookies " +
350 "to function properly. Your browser doesn't seem to support them.";
360 disableContainerChildren("headlinesToolbar", true);
362 if (!genericSanityCheck())
365 xmlhttp
.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
366 xmlhttp
.onreadystatechange
=backend_sanity_check_callback
;
371 function init_second_stage() {
373 setCookie("ttrss_vf_actfeed", "");
375 updateFeedList(false, false);
376 document
.onkeydown
= hotkey_handler
;
378 var content
= document
.getElementById("content");
380 if (getCookie("ttrss_vf_vmode")) {
381 var viewbox
= document
.getElementById("viewbox");
382 viewbox
.value
= getCookie("ttrss_vf_vmode");
385 if (getCookie("ttrss_vf_limit")) {
386 var limitbox
= document
.getElementById("limitbox");
387 limitbox
.value
= getCookie("ttrss_vf_limit");
390 // if (getCookie("ttrss_vf_actfeed")) {
391 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
394 // setTimeout("timeout()", 2*1000);
395 // scheduleFeedUpdate(true);
397 var splash
= document
.getElementById("splash");
400 splash
.style
.display
= "none";
405 function quickMenuGo() {
407 var chooser
= document
.getElementById("quickMenuChooser");
408 var opid
= chooser
[chooser
.selectedIndex
].id
;
410 if (opid
== "qmcPrefs") {
414 if (opid
== "qmcAdvSearch") {
415 displayDlg("search");
419 if (opid
== "qmcAddFeed") {
420 displayDlg("quickAddFeed");
424 if (opid
== "qmcRemoveFeed") {
425 var actid
= getActiveFeedId();
428 notify("Please select some feed first.");
432 displayDlg("quickDelFeed", actid
);
436 if (opid
== "qmcUpdateFeeds") {
437 scheduleFeedUpdate(true);
441 if (opid
== "qmcCatchupAll") {
446 if (opid
== "qmcShowOnlyUnread") {
455 if (!xmlhttp_ready(xmlhttp
)) {
460 var link
= document
.getElementById("qafInput");
462 if (link
.value
.length
== 0) {
463 notify("Missing feed URL.");
465 notify("Adding feed...");
467 var feeds_doc
= window
.frames
["feeds-frame"].document
;
469 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
471 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
472 param_escape(link
.value
), true);
473 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
481 function displayDlg(id
, param
) {
485 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
486 param_escape(id
) + "¶m=" + param_escape(param
), true);
487 xmlhttp
.onreadystatechange
=dialog_refresh_callback
;
492 function closeDlg() {
493 var dlg
= document
.getElementById("userDlg");
494 dlg
.style
.display
= "none";
497 function qfdDelete(feed_id
) {
499 notify("Removing feed...");
501 var feeds_doc
= window
.frames
["feeds-frame"].document
;
502 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
504 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id
);
505 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
510 function allFeedsMenuGo() {
511 var chooser
= document
.getElementById("allFeedsChooser");
513 var opname
= chooser
[chooser
.selectedIndex
].text
;
515 if (opname
== "Update") {
516 scheduleFeedUpdate(true);
520 if (opname
== "Mark as read") {
525 if (opname
== "Show only read") {
532 function toggleDispRead() {
533 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
535 hide_read_feeds
= !hide_read_feeds
;
537 var feeds_doc
= window
.frames
["feeds-frame"].document
;
539 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
541 if (hide_read_feeds
) {
542 setCookie("ttrss_vf_hreadf", 1);
544 setCookie("ttrss_vf_hreadf", 0);