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.
7 var xmlhttp_rpc = false;
8 var xmlhttp_view = false;
13 var active_post_id = false;
14 var active_feed_id = false;
15 var active_offset = false;
17 var search_query = "";
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");
28 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
29 xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP");
38 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
39 xmlhttp = new XMLHttpRequest();
40 xmlhttp_rpc = new XMLHttpRequest();
41 xmlhttp_view = new XMLHttpRequest();
44 function feedlist_callback() {
45 var container = document.getElementById('feeds');
46 if (xmlhttp.readyState == 4) {
47 container.innerHTML=xmlhttp.responseText;
50 scheduleFeedUpdate(false);
51 if (getCookie("ttrss_vf_actfeed")) {
52 viewfeed(getCookie("ttrss_vf_actfeed"), 0, "");
61 function refetch_callback() {
63 if (xmlhttp_rpc.readyState == 4) {
64 notify("All feeds updated");
65 var container = document.getElementById('feeds');
66 container.innerHTML = xmlhttp_rpc.responseText;
67 document.title = "Tiny Tiny RSS";
69 cleanSelected("feedsList");
71 var feedr = document.getElementById("FEEDR-" + active_feed_id);
73 feedr.className = feedr.className + "Selected";
79 function updateFeed(feed_id) {
81 var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id;
83 if (xmlhttp_ready(xmlhttp_rpc)) {
84 xmlhttp_rpc.open("GET", query_str, true);
85 xmlhttp_rpc.onreadystatechange=feed_update_callback;
86 xmlhttp_rpc.send(null);
93 function scheduleFeedUpdate(force) {
95 notify("Updating feeds in background...");
97 document.title = "Tiny Tiny RSS - Updating...";
99 var query_str = "backend.php?op=rpc&subop=";
102 query_str = query_str + "forceUpdateAllFeeds";
104 query_str = query_str + "updateAllFeeds";
107 if (xmlhttp_ready(xmlhttp_rpc)) {
108 xmlhttp_rpc.open("GET", query_str, true);
109 xmlhttp_rpc.onreadystatechange=refetch_callback;
110 xmlhttp_rpc.send(null);
116 function updateFeedList(silent, fetch) {
118 if (silent != true) {
119 notify("Loading feed list...");
122 var query_str = "backend.php?op=feeds";
124 if (fetch) query_str = query_str + "&fetch=yes";
126 if (xmlhttp_ready(xmlhttp)) {
127 xmlhttp.open("GET", query_str, true);
128 xmlhttp.onreadystatechange=feedlist_callback;
136 function catchupPage(feed) {
138 if (!xmlhttp_ready(xmlhttp)) {
143 var content = document.getElementById("headlinesList");
145 var rows = new Array();
147 for (i = 0; i < content.rows.length; i++) {
148 var row_id = content.rows[i].id.replace("RROW-", "");
149 if (row_id.length > 0) {
150 if (content.rows[i].className.match("Unread")) {
152 content.rows[i].className = content.rows[i].className.replace("Unread", "");
155 var upd_img_pic = document.getElementById("FUPDPIC-" + row_id);
157 upd_img_pic.innerHTML = "";
162 if (rows.length > 0) {
164 var feedr = document.getElementById("FEEDR-" + feed);
165 var feedu = document.getElementById("FEEDU-" + feed);
167 feedu.innerHTML = feedu.innerHTML - rows.length;
169 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
170 feedr.className = feedr.className + "Unread";
171 } else if (feedu.innerHTML <= 0) {
172 feedr.className = feedr.className.replace("Unread", "");
175 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
176 param_escape(rows.toString());
178 notify("Marking this page as read...");
180 var button = document.getElementById("btnCatchupPage");
183 button.className = "disabledButton";
187 xmlhttp.open("GET", query_str, true);
188 xmlhttp.onreadystatechange=notify_callback;
192 notify("No unread items on this page.");
197 function catchupAllFeeds() {
199 if (!xmlhttp_ready(xmlhttp)) {
203 var query_str = "backend.php?op=feeds&subop=catchupAll";
205 notify("Marking all feeds as read...");
207 xmlhttp.open("GET", query_str, true);
208 xmlhttp.onreadystatechange=feedlist_callback;
213 function viewCurrentFeed(skip, subop) {
214 if (active_feed_id ) {
215 viewfeed(active_feed_id, skip, subop);
219 function viewfeed(feed, skip, subop) {
221 // notify("Loading headlines...");
225 var searchbox = document.getElementById("searchbox");
228 search_query = searchbox.value;
233 var viewbox = document.getElementById("viewbox");
238 view_mode = viewbox.value;
240 view_mode = "All Posts";
243 setCookie("ttrss_vf_vmode", view_mode);
245 var limitbox = document.getElementById("limitbox");
250 limit = limitbox.value;
251 setCookie("ttrss_vf_limit", limit);
256 if (active_feed_id != feed || skip != active_offset) {
257 active_post_id = false;
260 active_feed_id = feed;
261 active_offset = skip;
263 setCookie("ttrss_vf_actfeed", feed);
265 if (subop == "MarkAllRead") {
267 var feedr = document.getElementById("FEEDR-" + feed);
268 var feedt = document.getElementById("FEEDT-" + feed);
269 var feedu = document.getElementById("FEEDU-" + feed);
271 feedu.innerHTML = "0";
273 if (feedr.className.match("Unread")) {
274 feedr.className = feedr.className.replace("Unread", "");
278 var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) +
279 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) +
280 "&view=" + param_escape(view_mode) + "&limit=" + limit;
282 if (search_query != "") {
283 query = query + "&search=" + param_escape(search_query);
286 var headlines_frame = document.getElementById("headlines-frame");
288 headlines_frame.src = query + "&addheader=true";
290 cleanSelected("feedsList");
291 var feedr = document.getElementById("FEEDR-" + feed);
293 feedr.className = feedr.className + "Selected";
296 disableContainerChildren("headlinesToolbar", false);
303 scheduleFeedUpdate(true);
304 setTimeout("timeout()", 1800*1000);
307 function resetSearch() {
308 document.getElementById("searchbox").value = "";
309 if (active_feed_id) {
310 viewfeed(active_feed_id, 0, "");
315 if (active_feed_id) {
316 viewfeed(active_feed_id, 0, "");
318 notify("Please select some feed first.");
322 function localPiggieFunction(enable) {
324 var query_str = "backend.php?op=feeds&subop=piggie";
326 if (xmlhttp_ready(xmlhttp)) {
328 xmlhttp.open("GET", query_str, true);
329 xmlhttp.onreadystatechange=feedlist_callback;
336 function moveToPost(mode) {
338 var rows = getVisibleHeadlineIds();
343 if (active_post_id == false) {
344 next_id = getFirstVisibleHeadlineId();
345 prev_id = getLastVisibleHeadlineId();
347 for (var i = 0; i < rows.length; i++) {
348 if (rows[i] == active_post_id) {
355 if (mode == "next") {
356 if (next_id != undefined) {
357 view(next_id, active_feed_id);
359 _viewfeed_autoselect_first = true;
360 viewfeed(active_feed_id, active_offset+15);
364 if (mode == "prev") {
365 if ( prev_id != undefined) {
366 view(prev_id, active_feed_id);
368 _viewfeed_autoselect_last = true;
369 viewfeed(active_feed_id, active_offset-15);
376 function localHotkeyHandler(keycode) {
378 /* if (keycode == 78) {
379 return moveToPost('next');
383 return moveToPost('prev');
387 return scheduleFeedUpdate(true);
391 return viewfeed(active_feed_id, active_offset, "ForceUpdate");
394 // notify("KC: " + keycode);
400 disableContainerChildren("headlinesToolbar", true);
404 if (xmlhttp && !xmlhttp_rpc) {
405 xmlhttp_rpc = xmlhttp;
406 xmlhttp_view = xmlhttp;
409 if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) {
410 document.getElementById("headlines").innerHTML =
411 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
412 "to function properly. Your browser doesn't seem to support it.";
416 updateFeedList(false, false);
417 document.onkeydown = hotkey_handler;
418 setTimeout("timeout()", 1800*1000);
420 var content = document.getElementById("content");
422 if (getCookie("ttrss_vf_vmode")) {
423 var viewbox = document.getElementById("viewbox");
424 viewbox.value = getCookie("ttrss_vf_vmode");
427 if (getCookie("ttrss_vf_limit")) {
428 var limitbox = document.getElementById("limitbox");
429 limitbox.value = getCookie("ttrss_vf_limit");