]>
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 qaf_add_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";
153 if (xmlhttp_ready(xmlhttp
)) {
154 xmlhttp
.open("GET", query_str
, true);
155 xmlhttp
.onreadystatechange
=refetch_callback
;
162 function updateFeedList(silent
, fetch
) {
164 // if (silent != true) {
165 // notify("Loading feed list...");
168 var query_str
= "backend.php?op=feeds";
171 query_str
= query_str
+ "&tags=1";
174 if (getActiveFeedId()) {
175 query_str
= query_str
+ "&actid=" + getActiveFeedId();
178 if (fetch
) query_str
= query_str
+ "&fetch=yes";
180 var feeds_frame
= document
.getElementById("feeds-frame");
182 feeds_frame
.src
= query_str
;
185 function catchupAllFeeds() {
187 var query_str
= "backend.php?op=feeds&subop=catchupAll";
189 notify("Marking all feeds as read...");
191 var feeds_frame
= document
.getElementById("feeds-frame");
193 feeds_frame
.src
= query_str
;
200 function viewCurrentFeed(skip
, subop
) {
202 if (getActiveFeedId()) {
203 viewfeed(getActiveFeedId(), skip
, subop
);
207 function viewfeed(feed
, skip
, subop
) {
209 // notify("Loading headlines...");
213 var searchbox
= document
.getElementById("searchbox");
216 search_query
= searchbox
.value
;
221 var searchmodebox
= document
.getElementById("searchmodebox");
224 search_mode
= searchmodebox
.value
;
229 setCookie("ttrss_vf_smode", search_mode
);
231 var viewbox
= document
.getElementById("viewbox");
236 view_mode
= viewbox
[viewbox
.selectedIndex
].text
;
238 view_mode
= "All Posts";
241 setCookie("ttrss_vf_vmode", view_mode
);
243 var limitbox
= document
.getElementById("limitbox");
248 limit
= limitbox
[limitbox
.selectedIndex
].text
;
249 setCookie("ttrss_vf_limit", limit
);
254 setActiveFeedId(feed
);
256 var f_doc
= frames
["feeds-frame"].document
;
258 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
260 if (subop
== "MarkAllRead") {
262 var feedr
= f_doc
.getElementById("FEEDR-" + feed
);
263 var feedctr
= f_doc
.getElementById("FEEDCTR-" + feed
);
265 feedctr
.className
= "invisible";
267 if (feedr
.className
.match("Unread")) {
268 feedr
.className
= feedr
.className
.replace("Unread", "");
272 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
273 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
) +
274 "&view=" + param_escape(view_mode
) + "&limit=" + limit
+
275 "&smode=" + param_escape(search_mode
);
277 if (search_query
!= "") {
278 query
= query
+ "&search=" + param_escape(search_query
);
281 var headlines_frame
= parent
.frames
["headlines-frame"];
283 headlines_frame
.location
.href
= query
+ "&addheader=true";
285 cleanSelected("feedsList");
286 var feedr
= document
.getElementById("FEEDR-" + feed
);
288 feedr
.className
= feedr
.className
+ "Selected";
291 disableContainerChildren("headlinesToolbar", false, doc
);
293 var btnMarkAsRead
= document
.getElementById("btnMarkFeedAsRead");
295 if (btnMarkAsRead
&& !isNumeric(feed
)) {
296 btnMarkAsRead
.disabled
= true;
297 btnMarkAsRead
.className
= "disabledButton";
306 scheduleFeedUpdate(true);
307 setTimeout("timeout()", 1800*1000);
310 function resetSearch() {
311 var searchbox
= document
.getElementById("searchbox")
313 if (searchbox
.value
!= "" && getActiveFeedId()) {
314 searchbox
.value
= "";
315 viewfeed(getActiveFeedId(), 0, "");
320 viewCurrentFeed(0, "");
323 function localPiggieFunction(enable
) {
325 var query_str
= "backend.php?op=feeds&subop=piggie";
327 if (xmlhttp_ready(xmlhttp
)) {
329 xmlhttp
.open("GET", query_str
, true);
330 xmlhttp
.onreadystatechange
=feedlist_callback
;
336 function localHotkeyHandler(keycode
) {
338 /* if (keycode == 78) {
339 return moveToPost('next');
343 return moveToPost('prev');
347 return scheduleFeedUpdate(true);
351 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
354 // notify("KC: " + keycode);
358 function updateTitle(s
) {
359 var tmp
= "Tiny Tiny RSS";
361 if (global_unread
> 0) {
362 tmp
= tmp
+ " (" + global_unread
+ ")";
366 tmp
= tmp
+ " - " + s
;
368 document
.title
= tmp
;
371 function genericSanityCheck() {
374 document
.getElementById("headlines").innerHTML
=
375 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
376 "to function properly. Your browser doesn't seem to support it.";
380 setCookie("ttrss_vf_test", "TEST");
381 if (getCookie("ttrss_vf_test") != "TEST") {
383 document
.getElementById("headlines").innerHTML
=
384 "<b>Fatal error:</b> This program requires cookies " +
385 "to function properly. Your browser doesn't seem to support them.";
395 disableContainerChildren("headlinesToolbar", true);
397 if (!genericSanityCheck())
400 setCookie("ttrss_vf_actfeed", "");
402 updateFeedList(false, false);
403 document
.onkeydown
= hotkey_handler
;
405 setTimeout("timeout()", 1800*1000);
406 scheduleFeedUpdate(true);
408 var content
= document
.getElementById("content");
410 if (getCookie("ttrss_vf_vmode")) {
411 var viewbox
= document
.getElementById("viewbox");
412 viewbox
.value
= getCookie("ttrss_vf_vmode");
415 if (getCookie("ttrss_vf_limit")) {
416 var limitbox
= document
.getElementById("limitbox");
417 limitbox
.value
= getCookie("ttrss_vf_limit");
420 // if (getCookie("ttrss_vf_actfeed")) {
421 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');
426 function quickMenuGo() {
427 var chooser
= document
.getElementById("quickMenuChooser");
429 var opname
= chooser
[chooser
.selectedIndex
].text
;
431 if (opname
== "Preferences") {
435 if (opname
== "Add new feed") {
436 displayDlg("quickAddFeed");
442 if (!xmlhttp_ready(xmlhttp
)) {
447 var link
= document
.getElementById("qafInput");
449 if (link
.value
.length
== 0) {
450 notify("Missing feed URL.");
452 notify("Adding feed...");
454 var feeds_doc
= window
.frames
["feeds-frame"].document
;
456 feeds_doc
.location
.href
= "backend.php?op=error&msg=Loading,%20please wait...";
458 xmlhttp
.open("GET", "backend.php?op=pref-feeds&subop=add&link=" +
459 param_escape(link
.value
), true);
460 xmlhttp
.onreadystatechange
=qaf_add_callback
;
468 function displayDlg(id
) {
470 xmlhttp
.open("GET", "backend.php?op=dlg&id=" +
471 param_escape(id
), true);
472 xmlhttp
.onreadystatechange
=dialog_refresh_callback
;
477 function closeDlg() {
478 var dlg
= document
.getElementById("userDlg");
479 dlg
.style
.display
= "none";