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";
52 function feedlist_callback() {
53 var container = document.getElementById('feeds');
54 if (xmlhttp.readyState == 4) {
55 container.innerHTML=xmlhttp.responseText;
58 scheduleFeedUpdate(false);
59 if (getCookie("ttrss_vf_actfeed")) {
60 viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
70 function refetch_callback() {
71 if (xmlhttp.readyState == 4) {
73 // document.title = "Tiny Tiny RSS";
75 if (!xmlhttp.responseXML) {
76 notify("refetch_callback: backend did not return valid XML");
80 var reply = xmlhttp.responseXML.firstChild;
83 notify("refetch_callback: backend did not return expected XML object");
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 updateFeed(feed_id) {
128 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
130 if (xmlhttp_ready(xmlhttp)) {
131 xmlhttp.open("GET", query_str, true);
132 xmlhttp.onreadystatechange=feed_update_callback;
140 function scheduleFeedUpdate(force) {
142 notify("Updating feeds in background...");
144 // document.title = "Tiny Tiny RSS - Updating...";
146 updateTitle("Updating...");
148 var query_str = "backend.php?op=rpc&subop=";
151 query_str = query_str + "forceUpdateAllFeeds";
153 query_str = query_str + "updateAllFeeds";
156 if (xmlhttp_ready(xmlhttp)) {
157 xmlhttp.open("GET", query_str, true);
158 xmlhttp.onreadystatechange=refetch_callback;
165 function updateFeedList(silent, fetch) {
167 // if (silent != true) {
168 // notify("Loading feed list...");
171 var query_str = "backend.php?op=feeds";
174 query_str = query_str + "&tags=1";
177 if (getActiveFeedId()) {
178 query_str = query_str + "&actid=" + getActiveFeedId();
181 if (fetch) query_str = query_str + "&fetch=yes";
183 var feeds_frame = document.getElementById("feeds-frame");
185 feeds_frame.src = query_str;
188 function catchupAllFeeds() {
190 var query_str = "backend.php?op=feeds&subop=catchupAll";
192 notify("Marking all feeds as read...");
194 var feeds_frame = document.getElementById("feeds-frame");
196 feeds_frame.src = query_str;
203 function viewCurrentFeed(skip, subop) {
205 if (getActiveFeedId()) {
206 viewfeed(getActiveFeedId(), skip, subop);
210 function viewfeed(feed, skip, subop) {
212 // notify("Loading headlines...");
216 var searchbox = document.getElementById("searchbox");
219 search_query = searchbox.value;
224 var searchmodebox = document.getElementById("searchmodebox");
227 search_mode = searchmodebox.value;
232 setCookie("ttrss_vf_smode", search_mode);
234 var viewbox = document.getElementById("viewbox");
239 view_mode = viewbox[viewbox.selectedIndex].text;
241 view_mode = "All Posts";
244 setCookie("ttrss_vf_vmode", view_mode);
246 var limitbox = document.getElementById("limitbox");
251 limit = limitbox[limitbox.selectedIndex].text;
252 setCookie("ttrss_vf_limit", limit);
257 setActiveFeedId(feed);
259 var f_doc = frames["feeds-frame"].document;
261 // f_doc.getElementById("ACTFEEDID").innerHTML = feed;
263 if (subop == "MarkAllRead") {
265 var feedr = f_doc.getElementById("FEEDR-" + feed);
266 var feedctr = f_doc.getElementById("FEEDCTR-" + feed);
268 feedctr.className = "invisible";
270 if (feedr.className.match("Unread")) {
271 feedr.className = feedr.className.replace("Unread", "");
275 var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
276 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
277 "&view=" + param_escape(view_mode) + "&limit=" + limit +
278 "&smode=" + param_escape(search_mode);
280 if (search_query != "") {
281 query = query + "&search=" + param_escape(search_query);
284 var headlines_frame = parent.frames["headlines-frame"];
286 headlines_frame.location.href = query + "&addheader=true";
288 cleanSelected("feedsList");
289 var feedr = document.getElementById("FEEDR-" + feed);
291 feedr.className = feedr.className + "Selected";
294 disableContainerChildren("headlinesToolbar", false, doc);
296 var btnMarkAsRead = document.getElementById("btnMarkFeedAsRead");
298 if (btnMarkAsRead && (feed < 0 || !isNumeric(feed))) {
299 btnMarkAsRead.disabled = true;
300 btnMarkAsRead.className = "disabledButton";
309 scheduleFeedUpdate(true);
310 setTimeout("timeout()", 1800*1000);
313 function resetSearch() {
314 var searchbox = document.getElementById("searchbox")
316 if (searchbox.value != "" && getActiveFeedId()) {
317 searchbox.value = "";
318 viewfeed(getActiveFeedId(), 0, "");
323 viewCurrentFeed(0, "");
326 function localPiggieFunction(enable) {
328 var query_str = "backend.php?op=feeds&subop=piggie";
330 if (xmlhttp_ready(xmlhttp)) {
332 xmlhttp.open("GET", query_str, true);
333 xmlhttp.onreadystatechange=feedlist_callback;
339 function localHotkeyHandler(keycode) {
341 /* if (keycode == 78) {
342 return moveToPost('next');
346 return moveToPost('prev');
350 return scheduleFeedUpdate(true);
354 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
357 // notify("KC: " + keycode);
361 function updateTitle(s) {
362 var tmp = "Tiny Tiny RSS";
364 if (global_unread > 0) {
365 tmp = tmp + " (" + global_unread + ")";
369 tmp = tmp + " - " + s;
371 document.title = tmp;
374 function genericSanityCheck() {
377 document.getElementById("headlines").innerHTML =
378 "<b>Fatal error:</b> This program requires XmlHttpRequest " +
379 "to function properly. Your browser doesn't seem to support it.";
383 setCookie("ttrss_vf_test", "TEST");
384 if (getCookie("ttrss_vf_test") != "TEST") {
386 document.getElementById("headlines").innerHTML =
387 "<b>Fatal error:</b> This program requires cookies " +
388 "to function properly. Your browser doesn't seem to support them.";
398 disableContainerChildren("headlinesToolbar", true);
400 if (!genericSanityCheck())
403 setCookie("ttrss_vf_actfeed", "");
405 updateFeedList(false, false);
406 document.onkeydown = hotkey_handler;
408 setTimeout("timeout()", 1800*1000);
409 scheduleFeedUpdate(true);
411 var content = document.getElementById("content");
413 if (getCookie("ttrss_vf_vmode")) {
414 var viewbox = document.getElementById("viewbox");
415 viewbox.value = getCookie("ttrss_vf_vmode");
418 if (getCookie("ttrss_vf_limit")) {
419 var limitbox = document.getElementById("limitbox");
420 limitbox.value = getCookie("ttrss_vf_limit");
423 // if (getCookie("ttrss_vf_actfeed")) {
424 // viewfeed(getCookie("ttrss_vf_actfeed"), 0, '');