]>
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.
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 total_feed_entries
= false;
19 var search_query
= "";
22 /*@if (@_jscript_version >= 5)
23 // JScript gives us Conditional compilation, we can cope with old IE versions.
24 // and security blocked creation of the objects.
26 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
29 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
30 xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP");
31 xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP");
40 if (!xmlhttp
&& typeof XMLHttpRequest
!='undefined') {
41 xmlhttp
= new XMLHttpRequest();
42 xmlhttp_rpc
= new XMLHttpRequest();
43 xmlhttp_view
= new XMLHttpRequest();
46 function feedlist_callback() {
47 var container
= document
.getElementById('feeds');
48 if (xmlhttp
.readyState
== 4) {
49 container
.innerHTML
=xmlhttp
.responseText
;
52 scheduleFeedUpdate(false);
61 function viewfeed_callback() {
62 var container = document.getElementById('headlines');
63 if (xmlhttp.readyState == 4) {
64 container.innerHTML = xmlhttp.responseText;
66 var factive = document.getElementById("FACTIVE");
67 var funread = document.getElementById("FUNREAD");
68 var ftotal = document.getElementById("FTOTAL");
70 if (_viewfeed_autoselect_first == true) {
71 _viewfeed_autoselect_first = false;
72 view(getFirstVisibleHeadlineId(), active_feed_id);
75 if (_viewfeed_autoselect_last == true) {
76 _viewfeed_autoselect_last = false;
77 view(getLastVisibleHeadlineId(), active_feed_id);
80 if (ftotal && factive && funread) {
81 var feed_id = factive.innerHTML;
83 var feedr = document.getElementById("FEEDR-" + feed_id);
84 var feedt = document.getElementById("FEEDT-" + feed_id);
85 var feedu = document.getElementById("FEEDU-" + feed_id);
87 feedt.innerHTML = ftotal.innerHTML;
88 feedu.innerHTML = funread.innerHTML;
90 total_feed_entries = ftotal.innerHTML;
92 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
93 feedr.className = feedr.className + "Unread";
94 } else if (feedu.innerHTML <= 0) {
95 feedr.className = feedr.className.replace("Unread", "");
98 cleanSelected("feedsList");
100 feedr.className = feedr.className + "Selected";
103 var searchbox = document.getElementById("searchbox");
104 searchbox.value = search_query;
106 markHeadline(active_post_id);
113 function refetch_callback() {
115 if (xmlhttp_rpc
.readyState
== 4) {
116 notify("All feeds updated");
117 var container
= document
.getElementById('feeds');
118 container
.innerHTML
= xmlhttp_rpc
.responseText
;
119 document
.title
= "Tiny Tiny RSS";
123 function updateFeed(feed_id
) {
125 var query_str
= "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id
;
127 if (xmlhttp_ready(xmlhttp_rpc
)) {
128 xmlhttp_rpc
.open("GET", query_str
, true);
129 xmlhttp_rpc
.onreadystatechange
=feed_update_callback
;
130 xmlhttp_rpc
.send(null);
137 function scheduleFeedUpdate(force
) {
139 notify("Updating feeds in background...");
141 document
.title
= "Tiny Tiny RSS - Updating...";
143 var query_str
= "backend.php?op=rpc&subop=";
146 query_str
= query_str
+ "forceUpdateAllFeeds";
148 query_str
= query_str
+ "updateAllFeeds";
151 if (xmlhttp_ready(xmlhttp_rpc
)) {
152 xmlhttp_rpc
.open("GET", query_str
, true);
153 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
154 xmlhttp_rpc
.send(null);
160 function updateFeedList(silent
, fetch
) {
162 if (silent
!= true) {
163 notify("Loading feed list...");
166 var query_str
= "backend.php?op=feeds";
168 if (fetch
) query_str
= query_str
+ "&fetch=yes";
170 if (xmlhttp_ready(xmlhttp
)) {
171 xmlhttp
.open("GET", query_str
, true);
172 xmlhttp
.onreadystatechange
=feedlist_callback
;
180 function catchupPage(feed) {
182 if (!xmlhttp_ready(xmlhttp)) {
187 var content = document.getElementById("headlinesList");
189 var rows = new Array();
191 for (i = 0; i < content.rows.length; i++) {
192 var row_id = content.rows[i].id.replace("RROW-", "");
193 if (row_id.length > 0) {
194 if (content.rows[i].className.match("Unread")) {
196 content.rows[i].className = content.rows[i].className.replace("Unread", "");
199 var upd_img_pic = document.getElementById("FUPDPIC-" + row_id);
201 upd_img_pic.innerHTML = "";
206 if (rows.length > 0) {
208 var feedr = document.getElementById("FEEDR-" + feed);
209 var feedu = document.getElementById("FEEDU-" + feed);
211 feedu.innerHTML = feedu.innerHTML - rows.length;
213 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
214 feedr.className = feedr.className + "Unread";
215 } else if (feedu.innerHTML <= 0) {
216 feedr.className = feedr.className.replace("Unread", "");
219 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
220 param_escape(rows.toString());
222 notify("Marking this page as read...");
224 var button = document.getElementById("btnCatchupPage");
227 button.className = "disabledButton";
231 xmlhttp.open("GET", query_str, true);
232 xmlhttp.onreadystatechange=notify_callback;
236 notify("No unread items on this page.");
241 function catchupAllFeeds() {
243 if (!xmlhttp_ready(xmlhttp
)) {
247 var query_str
= "backend.php?op=feeds&subop=catchupAll";
249 notify("Marking all feeds as read...");
251 xmlhttp
.open("GET", query_str
, true);
252 xmlhttp
.onreadystatechange
=feedlist_callback
;
257 function viewCurrentFeed(skip
, subop
) {
258 if (active_feed_id
) {
259 viewfeed(active_feed_id
, skip
, subop
);
263 function viewfeed(feed
, skip
, subop
) {
267 var searchbox
= document
.getElementById("searchbox");
270 search_query
= searchbox
.value
;
275 var viewbox
= document
.getElementById("viewbox");
280 view_mode
= viewbox
.value
;
282 view_mode
= "All Posts";
285 if (skip
< 0 || skip
> total_feed_entries
) {
289 if (!xmlhttp_ready(xmlhttp
)) {
294 if (active_feed_id
!= feed
|| skip
!= active_offset
) {
295 active_post_id
= false;
298 active_feed_id
= feed
;
299 active_offset
= skip
;
301 if (subop
== "MarkAllRead") {
303 var feedr
= document
.getElementById("FEEDR-" + feed
);
304 var feedt
= document
.getElementById("FEEDT-" + feed
);
305 var feedu
= document
.getElementById("FEEDU-" + feed
);
307 feedu
.innerHTML
= "0";
309 if (feedr
.className
.match("Unread")) {
310 feedr
.className
= feedr
.className
.replace("Unread", "");
314 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
315 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
) +
316 "&view=" + param_escape(view_mode
);
318 if (search_query
!= "") {
319 query
= query
+ "&search=" + param_escape(search_query
);
322 var headlines_frame
= document
.getElementById("headlines-frame");
324 headlines_frame
.src
= query
+ "&addheader=true";
326 var feedr
= document
.getElementById("FEEDR-" + feed
);
328 cleanSelected("feedsList");
329 feedr
.className
= feedr
.className
+ "Selected";
331 var ftitle_d
= document
.getElementById("headlinesTitle");
332 var ftitle_s
= document
.getElementById("FEEDN-" + feed
);
334 ftitle_d
.innerHTML
= ftitle_s
.innerHTML
;
341 function view(id,feed_id) {
345 if (!xmlhttp_ready(xmlhttp_view)) {
350 var crow = document.getElementById("RROW-" + id);
352 if (crow.className.match("Unread")) {
353 var umark = document.getElementById("FEEDU-" + feed_id);
354 umark.innerHTML = umark.innerHTML - 1;
355 crow.className = crow.className.replace("Unread", "");
357 if (umark.innerHTML == "0") {
358 var feedr = document.getElementById("FEEDR-" + feed_id);
359 feedr.className = feedr.className.replace("Unread", "");
365 cleanSelected("headlinesList");
366 // crow.className = crow.className + "Selected";
368 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
371 upd_img_pic.innerHTML = "";
374 // document.getElementById('content').innerHTML='Loading, please wait...';
376 var unread_rows = getVisibleUnreadHeadlines();
378 if (unread_rows.length == 0) {
379 var button = document.getElementById("btnCatchupPage");
381 button.className = "disabledButton";
388 var content = document.getElementById("content-frame");
390 content.src = "backend.php?op=view&addheader=true&id=" + param_escape(id);
391 markHeadline(active_post_id);
397 scheduleFeedUpdate(true);
398 setTimeout("timeout()", 1800*1000);
401 function resetSearch() {
402 document
.getElementById("searchbox").value
= "";
403 viewfeed(active_feed_id
, 0, "");
407 if (active_feed_id
) {
408 viewfeed(active_feed_id
, 0, "");
410 notify("Please select some feed first.");
414 function localPiggieFunction(enable
) {
416 var query_str
= "backend.php?op=feeds&subop=piggie";
418 if (xmlhttp_ready(xmlhttp
)) {
420 xmlhttp
.open("GET", query_str
, true);
421 xmlhttp
.onreadystatechange
=feedlist_callback
;
428 function moveToPost(mode) {
430 var rows = getVisibleHeadlineIds();
435 if (active_post_id == false) {
436 next_id = getFirstVisibleHeadlineId();
437 prev_id = getLastVisibleHeadlineId();
439 for (var i = 0; i < rows.length; i++) {
440 if (rows[i] == active_post_id) {
447 if (mode == "next") {
448 if (next_id != undefined) {
449 view(next_id, active_feed_id);
451 _viewfeed_autoselect_first = true;
452 viewfeed(active_feed_id, active_offset+15);
456 if (mode == "prev") {
457 if ( prev_id != undefined) {
458 view(prev_id, active_feed_id);
460 _viewfeed_autoselect_last = true;
461 viewfeed(active_feed_id, active_offset-15);
468 function localHotkeyHandler(keycode
) {
470 /* if (keycode == 78) {
471 return moveToPost('next');
475 return moveToPost('prev');
479 return scheduleFeedUpdate(true);
483 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
486 // notify("KC: " + keycode);
494 if (xmlhttp
&& !xmlhttp_rpc
) {
495 xmlhttp_rpc
= xmlhttp
;
496 xmlhttp_view
= xmlhttp
;
499 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
500 document
.getElementById("headlines").innerHTML
=
501 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
502 "to function properly. Your browser doesn't seem to support it.";
506 updateFeedList(false, false);
507 document
.onkeydown
= hotkey_handler
;
508 setTimeout("timeout()", 1800*1000);
510 var content
= document
.getElementById("content");