]>
git.wh0rd.org - tt-rss.git/blob - tt-rss.js
830bf07443e3b714dbeaa90e2761bf8fa11b9617
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 search_query
= "";
14 var display_tags
= false;
15 //var display_read_feeds = true;
17 var global_unread
= 0;
20 /*@if (@_jscript_version >= 5)
21 // JScript gives us Conditional compilation, we can cope with old IE versions.
22 // and security blocked creation of the objects.
24 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
27 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
34 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
35 xmlhttp
= new XMLHttpRequest();
38 function toggleTags() {
39 display_tags
= !display_tags
;
41 var p
= document
.getElementById("dispSwitchPrompt");
44 p
.innerHTML
= "display feeds";
46 p
.innerHTML
= "display tags";
52 function dlg_frefresh_callback() {
53 if (xmlhttp
.readyState
== 4) {
54 updateFeedList(false, false);
59 function dialog_refresh_callback() {
60 if (xmlhttp
.readyState
== 4) {
61 var dlg
= document
.getElementById("userDlg");
63 dlg
.innerHTML
= xmlhttp
.responseText
;
64 dlg
.style
.display
= "block";
68 function refetch_callback() {
69 if (xmlhttp
.readyState
== 4) {
71 // document.title = "Tiny Tiny RSS";
73 if (!xmlhttp
.responseXML
) {
74 notify("refetch_callback: backend did not return valid XML");
78 var reply
= xmlhttp
.responseXML
.firstChild
;
81 notify("refetch_callback: backend did not return expected XML object");
85 var f_document
= window
.frames
["feeds-frame"].document
;
87 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
88 var id
= reply
.childNodes
[l
].getAttribute("id");
89 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
91 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
92 var feedu
= f_document
.getElementById("FEEDU-" + id
);
93 var feedr
= f_document
.getElementById("FEEDR-" + id
);
95 /* TODO figure out how to update this from viewfeed.js->view()
98 if (id == "global-unread") {
102 if (feedctr
&& feedu
&& feedr
) {
104 feedu
.innerHTML
= ctr
;
107 feedctr
.className
= "odd";
108 if (!feedr
.className
.match("Unread")) {
109 feedr
.className
= feedr
.className
+ "Unread";
112 feedctr
.className
= "invisible";
113 feedr
.className
= feedr
.className
.replace("Unread", "");
119 notify("All feeds updated.");
124 function updateFeed(feed_id
) {
126 var query_str
= "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id
;
128 if (xmlhttp_ready(xmlhttp
)) {
129 xmlhttp
.open("GET", query_str
, true);
130 xmlhttp
.onreadystatechange
=feed_update_callback
;
138 function scheduleFeedUpdate(force
) {
140 notify("Updating feeds in background...");
142 // document.title = "Tiny Tiny RSS - Updating...";
144 updateTitle("Updating...");
146 var query_str
= "backend.php?op=rpc&subop=";
149 query_str
= query_str
+ "forceUpdateAllFeeds";
151 query_str
= query_str
+ "updateAllFeeds";
162 query_str
= query_str
+ "&omode=" + omode
;
164 if (xmlhttp_ready(xmlhttp
)) {
165 xmlhttp
.open("GET", query_str
, true);
166 xmlhttp
.onreadystatechange
=refetch_callback
;
173 function updateFeedList(silent
, fetch
) {
175 // if (silent != true) {
176 // notify("Loading feed list...");
179 var query_str
= "backend.php?op=feeds";
182 query_str
= query_str
+ "&tags=1";
185 if (getActiveFeedId()) {
186 query_str
= query_str
+ "&actid=" + getActiveFeedId();
189 if (fetch
) query_str
= query_str
+ "&fetch=yes";
191 var feeds_frame
= document
.getElementById("feeds-frame");
193 feeds_frame
.src
= query_str
;
196 function catchupAllFeeds() {
198 var query_str
= "backend.php?op=feeds&subop=catchupAll";
200 notify("Marking all feeds as read...");
202 var feeds_frame
= document
.getElementById("feeds-frame");
204 feeds_frame
.src
= query_str
;
211 function viewCurrentFeed(skip
, subop
) {
213 if (getActiveFeedId()) {
214 viewfeed(getActiveFeedId(), skip
, subop
);
216 disableContainerChildren("headlinesToolbar", false, document
);
217 viewfeed(-1, skip
, subop
); // FIXME
221 function viewfeed(feed
, skip
, subop
) {
223 // notify("Loading headlines...");
227 var searchbox
= document
.getElementById("searchbox");
230 search_query
= searchbox
.value
;
235 var searchmodebox
= document
.getElementById("searchmodebox");
238 search_mode
= searchmodebox
.value
;
243 setCookie("ttrss_vf_smode", search_mode
);
245 var viewbox
= document
.getElementById("viewbox");
250 view_mode
= viewbox
[viewbox
.selectedIndex
].text
;
252 view_mode
= "All Posts";
255 setCookie("ttrss_vf_vmode", view_mode
);
257 var limitbox
= document
.getElementById("limitbox");
262 limit
= limitbox
[limitbox
.selectedIndex
].text
;
263 setCookie("ttrss_vf_limit", limit
);
268 setActiveFeedId(feed
);
270 var f_doc
= frames
["feeds-frame"].document
;
272 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
274 if (subop
== "MarkAllRead") {
276 var feedr
= f_doc
.getElementById("FEEDR-" + feed
);
277 var feedctr
= f_doc
.getElementById("FEEDCTR-" + feed
);
279 feedctr
.className
= "invisible";
281 if (feedr
.className
.match("Unread")) {
282 feedr
.className
= feedr
.className
.replace("Unread", "");
286 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
287 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
) +
288 "&view=" + param_escape(view_mode
) + "&limit=" + limit
+
289 "&smode=" + param_escape(search_mode
);
291 if (search_query
!= "") {
292 query
= query
+ "&search=" + param_escape(search_query
);
295 var headlines_frame
= parent
.frames
["headlines-frame"];
297 headlines_frame
.location
.href
= query
+ "&addheader=true";
299 cleanSelected("feedsList");
300 var feedr
= document
.getElementById("FEEDR-" + feed
);
302 feedr
.className
= feedr
.className
+ "Selected";
305 disableContainerChildren("headlinesToolbar", false, doc
);
307 var btnMarkAsRead
= document
.getElementById("btnMarkFeedAsRead");
309 if (btnMarkAsRead
&& !isNumeric(feed
)) {
310 btnMarkAsRead
.disabled
= true;
311 btnMarkAsRead
.className
= "disabledButton";
320 scheduleFeedUpdate(true);
321 setTimeout("timeout()", 1800*1000);
324 function resetSearch() {
325 var searchbox
= document
.getElementById("searchbox")
327 if (searchbox
.value
!= "" && getActiveFeedId()) {
328 searchbox
.value
= "";
329 viewfeed(getActiveFeedId(), 0, "");
334 viewCurrentFeed(0, "");
337 function localPiggieFunction(enable
) {
339 var query_str
= "backend.php?op=feeds&subop=piggie";
341 if (xmlhttp_ready(xmlhttp
)) {
343 xmlhttp
.open("GET", query_str
, true);
344 xmlhttp
.onreadystatechange
=feedlist_callback
;
350 function localHotkeyHandler(keycode
) {
352 /* if (keycode == 78) {
353 return moveToPost('next');
357 return moveToPost('prev');
361 return scheduleFeedUpdate(true);
365 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
368 // notify("KC: " + keycode);
372 function updateTitle(s
) {
373 var tmp
= "Tiny Tiny RSS";
375 if (global_unread
> 0) {
376 tmp
= tmp
+ " (" + global_unread
+ ")";
380 tmp
= tmp
+ " - " + s
;
382 document
.title
= tmp
;
385 function genericSanityCheck() {
388 document
.getElementById("headlines").innerHTML
=
389 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
390 "to function properly. Your browser doesn't seem to support it.";
394 setCookie("ttrss_vf_test", "TEST");
395 if (getCookie("ttrss_vf_test") != "TEST") {
397 document
.getElementById("headlines").innerHTML
=
398 "<b>Fatal error:</b> This program requires cookies " +
399 "to function properly. Your browser doesn't seem to support them.";
409 disableContainerChildren("headlinesToolbar", true);
411 if (!genericSanityCheck())
414 setCookie("ttrss_vf_actfeed", "");
416 updateFeedList(false, false);
417 document
.onkeydown
= hotkey_handler
;
419 setTimeout("timeout()", 1800*1000);
420 scheduleFeedUpdate(true);
422 var content
= document
.getElementById("content");
424 if (getCookie("ttrss_vf_vmode")) {
425 var viewbox
= document
.getElementById("viewbox");
426 viewbox
.value
= getCookie("ttrss_vf_vmode");
429 if (getCookie("ttrss_vf_limit")) {
430 var limitbox
= document
.getElementById("limitbox");
431 limitbox
.value
= getCookie("ttrss_vf_limit");
434 // if (getCookie("ttrss_vf_actfeed")) {
435 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
440 function quickMenuGo() {
442 var chooser
= document
.getElementById("quickMenuChooser");
443 var opid
= chooser
[chooser
.selectedIndex
].id
;
445 if (opid
== "qmcPrefs") {
449 if (opid
== "qmcAdvSearch") {
450 displayDlg("search");
454 if (opid
== "qmcAddFeed") {
455 displayDlg("quickAddFeed");
459 if (opid
== "qmcRemoveFeed") {
460 var actid
= getActiveFeedId();
463 notify("Please select some feed first.");
467 displayDlg("quickDelFeed", actid
);
471 if (opid
== "qmcUpdateFeeds") {
472 scheduleFeedUpdate(true);
476 if (opid
== "qmcCatchupAll") {
481 if (opid
== "qmcShowOnlyUnread") {
490 if (!xmlhttp_ready(xmlhttp
)) {
495 var link
= document
.getElementById("qafInput");
497 if (link
.value
.length
== 0) {
498 notify("Missing feed URL.");
500 notify("Adding feed...");
502 var feeds_doc
= window
.frames
["feeds-frame"].document
;
504 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
506 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
507 param_escape(link
.value
), true);
508 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
516 function displayDlg(id
, param
) {
520 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
521 param_escape(id
) + "¶m=" + param_escape(param
), true);
522 xmlhttp
.onreadystatechange
=dialog_refresh_callback
;
527 function closeDlg() {
528 var dlg
= document
.getElementById("userDlg");
529 dlg
.style
.display
= "none";
532 function qfdDelete(feed_id
) {
534 notify("Removing feed...");
536 var feeds_doc
= window
.frames
["feeds-frame"].document
;
537 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
539 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id
);
540 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
545 function allFeedsMenuGo() {
546 var chooser
= document
.getElementById("allFeedsChooser");
548 var opname
= chooser
[chooser
.selectedIndex
].text
;
550 if (opname
== "Update") {
551 scheduleFeedUpdate(true);
555 if (opname
== "Mark as read") {
560 if (opname
== "Show only read") {
567 function toggleDispRead() {
568 var hide_read_feeds
= (getCookie("ttrss_vf_hreadf") == 1);
570 hide_read_feeds
= !hide_read_feeds
;
572 var feeds_doc
= window
.frames
["feeds-frame"].document
;
574 hideOrShowFeeds(feeds_doc
, hide_read_feeds
);
576 if (hide_read_feeds
) {
577 setCookie("ttrss_vf_hreadf", 1);
579 setCookie("ttrss_vf_hreadf", 0);