]>
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);
60 function refetch_callback() {
62 if (xmlhttp_rpc
.readyState
== 4) {
63 notify("All feeds updated");
64 var container
= document
.getElementById('feeds');
65 container
.innerHTML
= xmlhttp_rpc
.responseText
;
66 document
.title
= "Tiny Tiny RSS";
70 function updateFeed(feed_id
) {
72 var query_str
= "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id
;
74 if (xmlhttp_ready(xmlhttp_rpc
)) {
75 xmlhttp_rpc
.open("GET", query_str
, true);
76 xmlhttp_rpc
.onreadystatechange
=feed_update_callback
;
77 xmlhttp_rpc
.send(null);
84 function scheduleFeedUpdate(force
) {
86 notify("Updating feeds in background...");
88 document
.title
= "Tiny Tiny RSS - Updating...";
90 var query_str
= "backend.php?op=rpc&subop=";
93 query_str
= query_str
+ "forceUpdateAllFeeds";
95 query_str
= query_str
+ "updateAllFeeds";
98 if (xmlhttp_ready(xmlhttp_rpc
)) {
99 xmlhttp_rpc
.open("GET", query_str
, true);
100 xmlhttp_rpc
.onreadystatechange
=refetch_callback
;
101 xmlhttp_rpc
.send(null);
107 function updateFeedList(silent
, fetch
) {
109 if (silent
!= true) {
110 notify("Loading feed list...");
113 var query_str
= "backend.php?op=feeds";
115 if (fetch
) query_str
= query_str
+ "&fetch=yes";
117 if (xmlhttp_ready(xmlhttp
)) {
118 xmlhttp
.open("GET", query_str
, true);
119 xmlhttp
.onreadystatechange
=feedlist_callback
;
127 function catchupPage(feed) {
129 if (!xmlhttp_ready(xmlhttp)) {
134 var content = document.getElementById("headlinesList");
136 var rows = new Array();
138 for (i = 0; i < content.rows.length; i++) {
139 var row_id = content.rows[i].id.replace("RROW-", "");
140 if (row_id.length > 0) {
141 if (content.rows[i].className.match("Unread")) {
143 content.rows[i].className = content.rows[i].className.replace("Unread", "");
146 var upd_img_pic = document.getElementById("FUPDPIC-" + row_id);
148 upd_img_pic.innerHTML = "";
153 if (rows.length > 0) {
155 var feedr = document.getElementById("FEEDR-" + feed);
156 var feedu = document.getElementById("FEEDU-" + feed);
158 feedu.innerHTML = feedu.innerHTML - rows.length;
160 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
161 feedr.className = feedr.className + "Unread";
162 } else if (feedu.innerHTML <= 0) {
163 feedr.className = feedr.className.replace("Unread", "");
166 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
167 param_escape(rows.toString());
169 notify("Marking this page as read...");
171 var button = document.getElementById("btnCatchupPage");
174 button.className = "disabledButton";
178 xmlhttp.open("GET", query_str, true);
179 xmlhttp.onreadystatechange=notify_callback;
183 notify("No unread items on this page.");
188 function catchupAllFeeds() {
190 if (!xmlhttp_ready(xmlhttp
)) {
194 var query_str
= "backend.php?op=feeds&subop=catchupAll";
196 notify("Marking all feeds as read...");
198 xmlhttp
.open("GET", query_str
, true);
199 xmlhttp
.onreadystatechange
=feedlist_callback
;
204 function viewCurrentFeed(skip
, subop
) {
205 if (active_feed_id
) {
206 viewfeed(active_feed_id
, 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 viewbox
= document
.getElementById("viewbox");
229 view_mode
= viewbox
.value
;
231 view_mode
= "All Posts";
234 var limitbox
= document
.getElementById("limitbox");
239 limit
= limitbox
.value
;
244 if (skip
< 0 || skip
> total_feed_entries
) {
248 if (!xmlhttp_ready(xmlhttp
)) {
253 if (active_feed_id
!= feed
|| skip
!= active_offset
) {
254 active_post_id
= false;
257 active_feed_id
= feed
;
258 active_offset
= skip
;
260 if (subop
== "MarkAllRead") {
262 var feedr
= document
.getElementById("FEEDR-" + feed
);
263 var feedt
= document
.getElementById("FEEDT-" + feed
);
264 var feedu
= document
.getElementById("FEEDU-" + feed
);
266 feedu
.innerHTML
= "0";
268 if (feedr
.className
.match("Unread")) {
269 feedr
.className
= feedr
.className
.replace("Unread", "");
273 var query
= "backend.php?op=viewfeed&feed=" + param_escape(feed
) +
274 "&skip=" + param_escape(skip
) + "&subop=" + param_escape(subop
) +
275 "&view=" + param_escape(view_mode
) + "&limit=" + limit
;
277 if (search_query
!= "") {
278 query
= query
+ "&search=" + param_escape(search_query
);
281 var headlines_frame
= document
.getElementById("headlines-frame");
283 headlines_frame
.src
= query
+ "&addheader=true";
285 var feedr
= document
.getElementById("FEEDR-" + feed
);
287 cleanSelected("feedsList");
288 feedr
.className
= feedr
.className
+ "Selected";
290 var ftitle_d
= document
.getElementById("headlinesTitle");
291 var ftitle_s
= document
.getElementById("FEEDN-" + feed
);
293 ftitle_d
.innerHTML
= ftitle_s
.innerHTML
;
300 scheduleFeedUpdate(true);
301 setTimeout("timeout()", 1800*1000);
304 function resetSearch() {
305 document
.getElementById("searchbox").value
= "";
306 viewfeed(active_feed_id
, 0, "");
310 if (active_feed_id
) {
311 viewfeed(active_feed_id
, 0, "");
313 notify("Please select some feed first.");
317 function localPiggieFunction(enable
) {
319 var query_str
= "backend.php?op=feeds&subop=piggie";
321 if (xmlhttp_ready(xmlhttp
)) {
323 xmlhttp
.open("GET", query_str
, true);
324 xmlhttp
.onreadystatechange
=feedlist_callback
;
331 function moveToPost(mode) {
333 var rows = getVisibleHeadlineIds();
338 if (active_post_id == false) {
339 next_id = getFirstVisibleHeadlineId();
340 prev_id = getLastVisibleHeadlineId();
342 for (var i = 0; i < rows.length; i++) {
343 if (rows[i] == active_post_id) {
350 if (mode == "next") {
351 if (next_id != undefined) {
352 view(next_id, active_feed_id);
354 _viewfeed_autoselect_first = true;
355 viewfeed(active_feed_id, active_offset+15);
359 if (mode == "prev") {
360 if ( prev_id != undefined) {
361 view(prev_id, active_feed_id);
363 _viewfeed_autoselect_last = true;
364 viewfeed(active_feed_id, active_offset-15);
371 function localHotkeyHandler(keycode
) {
373 /* if (keycode == 78) {
374 return moveToPost('next');
378 return moveToPost('prev');
382 return scheduleFeedUpdate(true);
386 return viewfeed(active_feed_id
, active_offset
, "ForceUpdate");
389 // notify("KC: " + keycode);
397 if (xmlhttp
&& !xmlhttp_rpc
) {
398 xmlhttp_rpc
= xmlhttp
;
399 xmlhttp_view
= xmlhttp
;
402 if (!xmlhttp
|| !xmlhttp_rpc
|| !xmlhttp_view
) {
403 document
.getElementById("headlines").innerHTML
=
404 "<b>Fatal error:</b> This program needs XmlHttpRequest " +
405 "to function properly. Your browser doesn't seem to support it.";
409 updateFeedList(false, false);
410 document
.onkeydown
= hotkey_handler
;
411 setTimeout("timeout()", 1800*1000);
413 var content
= document
.getElementById("content");