]>
git.wh0rd.org - tt-rss.git/blob - tt-rss.js
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;
16 var global_unread
= 0;
19 /*@if (@_jscript_version >= 5)
20 // JScript gives us Conditional compilation, we can cope with old IE versions.
21 // and security blocked creation of the objects.
23 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
26 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
33 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
34 xmlhttp
= new XMLHttpRequest();
37 function toggleTags() {
38 display_tags
= !display_tags
;
40 var p
= document
.getElementById("dispSwitchPrompt");
43 p
.innerHTML
= "display feeds";
45 p
.innerHTML
= "display tags";
51 function dlg_frefresh_callback() {
52 if (xmlhttp
.readyState
== 4) {
53 updateFeedList(false, false);
58 function dialog_refresh_callback() {
59 if (xmlhttp
.readyState
== 4) {
60 var dlg
= document
.getElementById("userDlg");
62 dlg
.innerHTML
= xmlhttp
.responseText
;
63 dlg
.style
.display
= "block";
67 function refetch_callback() {
68 if (xmlhttp
.readyState
== 4) {
70 // document.title = "Tiny Tiny RSS";
72 if (!xmlhttp
.responseXML
) {
73 notify("refetch_callback: backend did not return valid XML");
77 var reply
= xmlhttp
.responseXML
.firstChild
;
80 notify("refetch_callback: backend did not return expected XML object");
84 var f_document
= window
.frames
["feeds-frame"].document
;
86 for (var l
= 0; l
< reply
.childNodes
.length
; l
++) {
87 var id
= reply
.childNodes
[l
].getAttribute("id");
88 var ctr
= reply
.childNodes
[l
].getAttribute("counter");
90 var feedctr
= f_document
.getElementById("FEEDCTR-" + id
);
91 var feedu
= f_document
.getElementById("FEEDU-" + id
);
92 var feedr
= f_document
.getElementById("FEEDR-" + id
);
94 /* TODO figure out how to update this from viewfeed.js->view()
97 if (id == "global-unread") {
101 if (feedctr
&& feedu
&& feedr
) {
103 feedu
.innerHTML
= ctr
;
106 feedctr
.className
= "odd";
107 if (!feedr
.className
.match("Unread")) {
108 feedr
.className
= feedr
.className
+ "Unread";
111 feedctr
.className
= "invisible";
112 feedr
.className
= feedr
.className
.replace("Unread", "");
118 notify("All feeds updated.");
123 function updateFeed(feed_id
) {
125 var query_str
= "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id
;
127 if (xmlhttp_ready(xmlhttp
)) {
128 xmlhttp
.open("GET", query_str
, true);
129 xmlhttp
.onreadystatechange
=feed_update_callback
;
137 function scheduleFeedUpdate(force
) {
139 notify("Updating feeds in background...");
141 // document.title = "Tiny Tiny RSS - Updating...";
143 updateTitle("Updating...");
145 var query_str
= "backend.php?op=rpc&subop=";
148 query_str
= query_str
+ "forceUpdateAllFeeds";
150 query_str
= query_str
+ "updateAllFeeds";
161 query_str
= query_str
+ "&omode=" + omode
;
163 if (xmlhttp_ready(xmlhttp
)) {
164 xmlhttp
.open("GET", query_str
, true);
165 xmlhttp
.onreadystatechange
=refetch_callback
;
172 function updateFeedList(silent
, fetch
) {
174 // if (silent != true) {
175 // notify("Loading feed list...");
178 var query_str
= "backend.php?op=feeds";
181 query_str
= query_str
+ "&tags=1";
184 if (getActiveFeedId()) {
185 query_str
= query_str
+ "&actid=" + getActiveFeedId();
188 if (fetch
) query_str
= query_str
+ "&fetch=yes";
190 var feeds_frame
= document
.getElementById("feeds-frame");
192 feeds_frame
.src
= query_str
;
195 function catchupAllFeeds() {
197 var query_str
= "backend.php?op=feeds&subop=catchupAll";
199 notify("Marking all feeds as read...");
201 var feeds_frame
= document
.getElementById("feeds-frame");
203 feeds_frame
.src
= query_str
;
210 function viewCurrentFeed(skip
, subop
) {
212 if (getActiveFeedId()) {
213 viewfeed(getActiveFeedId(), skip
, subop
);
215 disableContainerChildren("headlinesToolbar", false, document
);
216 viewfeed(-1, skip
, subop
); // FIXME
220 function viewfeed(feed
, skip
, subop
) {
222 // notify("Loading headlines...");
226 var searchbox
= document
.getElementById("searchbox");
229 search_query
= searchbox
.value
;
234 var searchmodebox
= document
.getElementById("searchmodebox");
237 search_mode
= searchmodebox
.value
;
242 setCookie("ttrss_vf_smode", search_mode
);
244 var viewbox
= document
.getElementById("viewbox");
249 view_mode
= viewbox
[viewbox
.selectedIndex
].text
;
251 view_mode
= "All Posts";
254 setCookie("ttrss_vf_vmode", view_mode
);
256 var limitbox
= document
.getElementById("limitbox");
261 limit
= limitbox
[limitbox
.selectedIndex
].text
;
262 setCookie("ttrss_vf_limit", limit
);
267 setActiveFeedId(feed
);
269 var f_doc
= frames
["feeds-frame"].document
;
271 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
273 if (subop
== "MarkAllRead") {
275 var feedr
= f_doc
.getElementById("FEEDR-" + feed
);
276 var feedctr
= f_doc
.getElementById("FEEDCTR-" + feed
);
278 feedctr
.className
= "invisible";
280 if (feedr
.className
.match("Unread")) {
281 feedr
.className
= feedr
.className
.replace("Unread", "");
285 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
286 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
) +
287 "&view=" + param_escape(view_mode
) + "&limit=" + limit
+
288 "&smode=" + param_escape(search_mode
);
290 if (search_query
!= "") {
291 query
= query
+ "&search=" + param_escape(search_query
);
294 var headlines_frame
= parent
.frames
["headlines-frame"];
296 headlines_frame
.location
.href
= query
+ "&addheader=true";
298 cleanSelected("feedsList");
299 var feedr
= document
.getElementById("FEEDR-" + feed
);
301 feedr
.className
= feedr
.className
+ "Selected";
304 disableContainerChildren("headlinesToolbar", false, doc
);
306 var btnMarkAsRead
= document
.getElementById("btnMarkFeedAsRead");
308 if (btnMarkAsRead
&& !isNumeric(feed
)) {
309 btnMarkAsRead
.disabled
= true;
310 btnMarkAsRead
.className
= "disabledButton";
319 scheduleFeedUpdate(true);
320 setTimeout("timeout()", 1800*1000);
323 function resetSearch() {
324 var searchbox
= document
.getElementById("searchbox")
326 if (searchbox
.value
!= "" && getActiveFeedId()) {
327 searchbox
.value
= "";
328 viewfeed(getActiveFeedId(), 0, "");
333 viewCurrentFeed(0, "");
336 function localPiggieFunction(enable
) {
338 var query_str
= "backend.php?op=feeds&subop=piggie";
340 if (xmlhttp_ready(xmlhttp
)) {
342 xmlhttp
.open("GET", query_str
, true);
343 xmlhttp
.onreadystatechange
=feedlist_callback
;
349 function localHotkeyHandler(keycode
) {
351 /* if (keycode == 78) {
352 return moveToPost('next');
356 return moveToPost('prev');
360 return scheduleFeedUpdate(true);
364 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
367 // notify("KC: " + keycode);
371 function updateTitle(s
) {
372 var tmp
= "Tiny Tiny RSS";
374 if (global_unread
> 0) {
375 tmp
= tmp
+ " (" + global_unread
+ ")";
379 tmp
= tmp
+ " - " + s
;
381 document
.title
= tmp
;
384 function genericSanityCheck() {
387 document
.getElementById("headlines").innerHTML
=
388 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
389 "to function properly. Your browser doesn't seem to support it.";
393 setCookie("ttrss_vf_test", "TEST");
394 if (getCookie("ttrss_vf_test") != "TEST") {
396 document
.getElementById("headlines").innerHTML
=
397 "<b>Fatal error:</b> This program requires cookies " +
398 "to function properly. Your browser doesn't seem to support them.";
408 disableContainerChildren("headlinesToolbar", true);
410 if (!genericSanityCheck())
413 setCookie("ttrss_vf_actfeed", "");
415 updateFeedList(false, false);
416 document
.onkeydown
= hotkey_handler
;
418 setTimeout("timeout()", 1800*1000);
419 scheduleFeedUpdate(true);
421 var content
= document
.getElementById("content");
423 if (getCookie("ttrss_vf_vmode")) {
424 var viewbox
= document
.getElementById("viewbox");
425 viewbox
.value
= getCookie("ttrss_vf_vmode");
428 if (getCookie("ttrss_vf_limit")) {
429 var limitbox
= document
.getElementById("limitbox");
430 limitbox
.value
= getCookie("ttrss_vf_limit");
433 // if (getCookie("ttrss_vf_actfeed")) {
434 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
439 function quickMenuGo() {
440 var chooser
= document
.getElementById("quickMenuChooser");
442 var opname
= chooser
[chooser
.selectedIndex
].text
;
444 if (opname
== "Preferences") {
448 if (opname
== "Extended search") {
449 displayDlg("search");
453 if (opname
.match("Add new feed")) {
454 displayDlg("quickAddFeed");
458 if (opname
.match("Remove this feed")) {
459 var actid
= getActiveFeedId();
462 notify("Please select some feed first.");
466 displayDlg("quickDelFeed", actid
);
473 if (!xmlhttp_ready(xmlhttp
)) {
478 var link
= document
.getElementById("qafInput");
480 if (link
.value
.length
== 0) {
481 notify("Missing feed URL.");
483 notify("Adding feed...");
485 var feeds_doc
= window
.frames
["feeds-frame"].document
;
487 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
489 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
490 param_escape(link
.value
), true);
491 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;
499 function displayDlg(id
, param
) {
503 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
504 param_escape(id
) + "¶m=" + param_escape(param
), true);
505 xmlhttp
.onreadystatechange
=dialog_refresh_callback
;
510 function closeDlg() {
511 var dlg
= document
.getElementById("userDlg");
512 dlg
.style
.display
= "none";
515 function qfdDelete(feed_id
) {
517 notify("Removing feed...");
519 var feeds_doc
= window
.frames
["feeds-frame"].document
;
520 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
522 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id
);
523 xmlhttp
.onreadystatechange
=dlg_frefresh_callback
;