]> git.wh0rd.org - tt-rss.git/blob - tt-rss.js
1ef840529f57d039465f994906493327bf69af60
[tt-rss.git] / tt-rss.js
1 /*
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.
4 */
5
6 var xmlhttp = false;
7 var xmlhttp_rpc = false;
8
9 var total_unread = 0;
10 var first_run = true;
11
12 /*@cc_on @*/
13 /*@if (@_jscript_version >= 5)
14 // JScript gives us Conditional compilation, we can cope with old IE versions.
15 // and security blocked creation of the objects.
16 try {
17 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
18 } catch (e) {
19 try {
20 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
21 } catch (E) {
22 xmlhttp = false;
23 }
24 }
25 @end @*/
26
27 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
28 xmlhttp = new XMLHttpRequest();
29 xmlhttp_rpc = new XMLHttpRequest();
30
31 }
32
33 function printLockingError() {
34 notify("Please wait until operation finishes");
35 }
36
37 function notify_callback() {
38 var container = document.getElementById('notify');
39 if (xmlhttp.readyState == 4) {
40 container.innerHTML=xmlhttp.responseText;
41 }
42 }
43
44 function feedlist_callback() {
45 var container = document.getElementById('feeds');
46 if (xmlhttp.readyState == 4) {
47 container.innerHTML=xmlhttp.responseText;
48
49 // var feedtu = document.getElementById("FEEDTU");
50 // if (feedtu) {
51 // total_unread = feedtu.innerHTML;
52 // update_title();
53 // }
54
55 if (first_run) {
56 scheduleFeedUpdate(false);
57 first_run = false;
58 } else {
59 notify("");
60 }
61 }
62 }
63
64 function viewfeed_callback() {
65 var container = document.getElementById('headlines');
66 if (xmlhttp.readyState == 4) {
67 container.innerHTML = xmlhttp.responseText;
68
69 var factive = document.getElementById("FACTIVE");
70 var funread = document.getElementById("FUNREAD");
71 var ftotal = document.getElementById("FTOTAL");
72
73 if (ftotal && factive && funread) {
74 var feed_id = factive.innerHTML;
75
76 var feedr = document.getElementById("FEEDR-" + feed_id);
77 var feedt = document.getElementById("FEEDT-" + feed_id);
78 var feedu = document.getElementById("FEEDU-" + feed_id);
79
80 feedt.innerHTML = ftotal.innerHTML;
81 feedu.innerHTML = funread.innerHTML;
82
83 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
84 feedr.className = feedr.className + "Unread";
85 } else if (feedu.innerHTML <= 0) {
86 feedr.className = feedr.className.replace("Unread", "");
87 }
88
89 }
90
91 notify("");
92
93 }
94 }
95
96 function view_callback() {
97 var container = document.getElementById('content');
98 if (xmlhttp.readyState == 4) {
99 container.innerHTML=xmlhttp.responseText;
100 }
101 }
102
103 function refetch_callback() {
104 if (xmlhttp_rpc.readyState == 4) {
105 notify("All feeds updated");
106
107 var container = document.getElementById('feeds');
108
109 container.innerHTML = xmlhttp_rpc.responseText;
110
111 //updateFeedList(true, false);
112 }
113 }
114
115 function scheduleFeedUpdate(force) {
116
117 notify("Updating feeds in background...");
118
119 var query_str = "backend.php?op=rpc&subop=";
120
121 if (force) {
122 query_str = query_str + "forceUpdateAllFeeds";
123 } else {
124 query_str = query_str + "updateAllFeeds";
125 }
126
127 if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) {
128 xmlhttp_rpc.open("GET", query_str, true);
129 xmlhttp_rpc.onreadystatechange=refetch_callback;
130 xmlhttp_rpc.send(null);
131 } else {
132 printLockingError();
133 }
134 }
135
136 function updateFeedList(silent, fetch) {
137
138 if (silent != true) {
139 notify("Loading feed list...");
140 }
141
142 var query_str = "backend.php?op=feeds";
143
144 if (fetch) query_str = query_str + "&fetch=yes";
145
146 if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
147 xmlhttp.open("GET", query_str, true);
148 xmlhttp.onreadystatechange=feedlist_callback;
149 xmlhttp.send(null);
150 } else {
151 printLockingError();
152 }
153 }
154
155 function catchupPage(feed) {
156
157 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
158 printLockingError();
159 return
160 }
161
162 var content = document.getElementById("headlinesList");
163
164 var rows = new Array();
165
166 for (i = 0; i < content.rows.length; i++) {
167 var row_id = content.rows[i].id.replace("RROW-", "");
168 if (row_id.length > 0) {
169 if (content.rows[i].className.match("Unread")) {
170 rows.push(row_id);
171 content.rows[i].className = content.rows[i].className.replace("Unread", "");
172 }
173 }
174 }
175
176 if (rows.length > 0) {
177
178 var feedr = document.getElementById("FEEDR-" + feed);
179 var feedu = document.getElementById("FEEDU-" + feed);
180
181 feedu.innerHTML = feedu.innerHTML - rows.length;
182
183 if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) {
184 feedr.className = feedr.className + "Unread";
185 } else if (feedu.innerHTML <= 0) {
186 feedr.className = feedr.className.replace("Unread", "");
187 }
188
189 var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" +
190 param_escape(rows.toString());
191
192 notify("Marking this page as read...");
193
194 xmlhttp.open("GET", query_str, true);
195 xmlhttp.onreadystatechange=notify_callback;
196 xmlhttp.send(null);
197
198 } else {
199 notify("No unread items on this page.");
200
201 }
202 }
203
204 function catchupAllFeeds() {
205
206 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
207 printLockingError();
208 return
209 }
210 var query_str = "backend.php?op=feeds&subop=catchupAll";
211
212 notify("Marking all feeds as read...");
213
214 xmlhttp.open("GET", query_str, true);
215 xmlhttp.onreadystatechange=feedlist_callback;
216 xmlhttp.send(null);
217
218 }
219
220 function viewfeed(feed, skip, subop) {
221
222 // document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
223 // document.getElementById('content').innerHTML='&nbsp;';
224
225 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
226 printLockingError();
227 return
228 }
229
230 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
231 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
232 xmlhttp.onreadystatechange=viewfeed_callback;
233 xmlhttp.send(null);
234
235 notify("Loading headlines...");
236
237 }
238
239 function view(id,feed_id) {
240
241 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
242 printLockingError();
243 return
244 }
245
246 var crow = document.getElementById("RROW-" + id);
247
248 if (crow.className.match("Unread")) {
249 var umark = document.getElementById("FEEDU-" + feed_id);
250 umark.innerHTML = umark.innerHTML - 1;
251 crow.className = crow.className.replace("Unread", "");
252
253 if (umark.innerHTML == "0") {
254 var feedr = document.getElementById("FEEDR-" + feed_id);
255 feedr.className = feedr.className.replace("Unread", "");
256 }
257
258 total_unread--;
259
260 update_title();
261 }
262
263 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
264
265 if (upd_img_pic) {
266 upd_img_pic.innerHTML = "";
267 }
268
269 document.getElementById('content').innerHTML='Loading, please wait...';
270
271 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
272 xmlhttp.onreadystatechange=view_callback;
273 xmlhttp.send(null);
274
275 }
276
277 function timeout() {
278
279 scheduleFeedUpdate(true);
280
281 setTimeout("timeout()", 1800*1000);
282
283 }
284
285 function search(feed, sender) {
286
287 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
288 printLockingError();
289 return
290 }
291
292 notify("Search: " + feed + ", " + sender.value)
293
294 document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
295 document.getElementById('content').innerHTML='&nbsp;';
296
297 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
298 "&search=" + param_escape(sender.value) + "&ext=SEARCH", true);
299 xmlhttp.onreadystatechange=viewfeed_callback;
300 xmlhttp.send(null);
301
302 }
303
304 function update_title() {
305 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
306 }
307
308 function init() {
309 updateFeedList(false, false);
310 setTimeout("timeout()", 1800*1000);
311 }