]> git.wh0rd.org - tt-rss.git/blame - tt-rss.js
TAG 20050823-1
[tt-rss.git] / tt-rss.js
CommitLineData
1cd17194
AD
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
6var xmlhttp = false;
525116d4 7var xmlhttp_rpc = false;
1cd17194 8
76798ff3 9var total_unread = 0;
525116d4 10var first_run = true;
76798ff3 11
1cd17194
AD
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.
16try {
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
27if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
28 xmlhttp = new XMLHttpRequest();
525116d4
AD
29 xmlhttp_rpc = new XMLHttpRequest();
30
1cd17194
AD
31}
32
a234aee5
AD
33function printLockingError() {
34 notify("Please wait until operation finishes");
35}
36
175847de
AD
37function notify_callback() {
38 var container = document.getElementById('notify');
39 if (xmlhttp.readyState == 4) {
40 container.innerHTML=xmlhttp.responseText;
41 }
42}
43
1cd17194 44function feedlist_callback() {
d76a3b03 45 var container = document.getElementById('feeds');
1cd17194 46 if (xmlhttp.readyState == 4) {
d76a3b03 47 container.innerHTML=xmlhttp.responseText;
76798ff3 48
c3b81db0
AD
49// var feedtu = document.getElementById("FEEDTU");
50// if (feedtu) {
51// total_unread = feedtu.innerHTML;
52// update_title();
53// }
476cac42 54
525116d4 55 if (first_run) {
cb246176 56 scheduleFeedUpdate(false);
525116d4
AD
57 first_run = false;
58 } else {
59 notify("");
60 }
1cd17194
AD
61 }
62}
63
64function viewfeed_callback() {
d76a3b03 65 var container = document.getElementById('headlines');
1cd17194 66 if (xmlhttp.readyState == 4) {
d76a3b03 67 container.innerHTML = xmlhttp.responseText;
a1a8a2be
AD
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 }
1c37c607
AD
90
91 notify("");
92
93 }
1cd17194
AD
94}
95
96function view_callback() {
d76a3b03 97 var container = document.getElementById('content');
1cd17194 98 if (xmlhttp.readyState == 4) {
d76a3b03 99 container.innerHTML=xmlhttp.responseText;
1cd17194
AD
100 }
101}
102
525116d4
AD
103function refetch_callback() {
104 if (xmlhttp_rpc.readyState == 4) {
c3b81db0
AD
105 notify("All feeds updated");
106
107 var container = document.getElementById('feeds');
108
109 container.innerHTML = xmlhttp_rpc.responseText;
110
111 //updateFeedList(true, false);
525116d4
AD
112 }
113}
114
cb246176 115function scheduleFeedUpdate(force) {
525116d4
AD
116
117 notify("Updating feeds in background...");
118
cb246176
AD
119 var query_str = "backend.php?op=rpc&subop=";
120
121 if (force) {
c3b81db0 122 query_str = query_str + "forceUpdateAllFeeds";
cb246176 123 } else {
c3b81db0 124 query_str = query_str + "updateAllFeeds";
cb246176 125 }
525116d4
AD
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}
1cd17194 135
525116d4 136function updateFeedList(silent, fetch) {
076682aa 137
525116d4 138 if (silent != true) {
11c2f3fa 139 notify("Loading feed list...");
40d13c28 140 }
82baad4a 141
331900c6
AD
142 var query_str = "backend.php?op=feeds";
143
144 if (fetch) query_str = query_str + "&fetch=yes";
145
076682aa
AD
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 {
a234aee5 151 printLockingError();
076682aa 152 }
1cd17194
AD
153}
154
175847de
AD
155function catchupPage(feed) {
156
076682aa 157 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 158 printLockingError();
076682aa
AD
159 return
160 }
161
175847de
AD
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) {
cb0bd8bd
AD
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 }
175847de
AD
173 }
174 }
175
cb0bd8bd 176 if (rows.length > 0) {
175847de 177
cb0bd8bd
AD
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);
175847de 197
cb0bd8bd
AD
198 } else {
199 notify("No unread items on this page.");
175847de 200
cb0bd8bd 201 }
175847de
AD
202}
203
476cac42 204function catchupAllFeeds() {
076682aa
AD
205
206 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 207 printLockingError();
076682aa
AD
208 return
209 }
476cac42
AD
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}
1cd17194 219
476cac42 220function viewfeed(feed, skip, subop) {
1cd17194 221
1c37c607
AD
222// document.getElementById('headlines').innerHTML='Loading headlines, please wait...';
223// document.getElementById('content').innerHTML='&nbsp;';
d76a3b03 224
076682aa 225 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 226 printLockingError();
076682aa
AD
227 return
228 }
229
d76a3b03 230 xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) +
476cac42 231 "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true);
1cd17194
AD
232 xmlhttp.onreadystatechange=viewfeed_callback;
233 xmlhttp.send(null);
234
1c37c607
AD
235 notify("Loading headlines...");
236
1cd17194
AD
237}
238
a1a8a2be 239function view(id,feed_id) {
d76a3b03 240
076682aa 241 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 242 printLockingError();
076682aa
AD
243 return
244 }
245
d76a3b03
AD
246 var crow = document.getElementById("RROW-" + id);
247
a1a8a2be
AD
248 if (crow.className.match("Unread")) {
249 var umark = document.getElementById("FEEDU-" + feed_id);
250 umark.innerHTML = umark.innerHTML - 1;
d76a3b03 251 crow.className = crow.className.replace("Unread", "");
d76a3b03 252
a1a8a2be
AD
253 if (umark.innerHTML == "0") {
254 var feedr = document.getElementById("FEEDR-" + feed_id);
255 feedr.className = feedr.className.replace("Unread", "");
256 }
b197f117 257
76798ff3
AD
258 total_unread--;
259
b197f117 260 update_title();
76798ff3 261 }
1cd17194 262
b197f117
AD
263 var upd_img_pic = document.getElementById("FUPDPIC-" + id);
264
265 if (upd_img_pic) {
266 upd_img_pic.innerHTML = "";
267 }
268
d76a3b03 269 document.getElementById('content').innerHTML='Loading, please wait...';
1cd17194 270
d76a3b03 271 xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true);
1cd17194
AD
272 xmlhttp.onreadystatechange=view_callback;
273 xmlhttp.send(null);
274
275}
276
40d13c28
AD
277function timeout() {
278
cb246176 279 scheduleFeedUpdate(true);
40d13c28 280
ac53063a
AD
281 setTimeout("timeout()", 1800*1000);
282
283}
284
285function search(feed, sender) {
286
076682aa 287 if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) {
a234aee5 288 printLockingError();
076682aa
AD
289 return
290 }
291
ac53063a
AD
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);
40d13c28
AD
301
302}
303
76798ff3
AD
304function update_title() {
305 //document.title = "Tiny Tiny RSS (" + total_unread + " unread)";
306}
1cd17194 307
76798ff3 308function init() {
476cac42 309 updateFeedList(false, false);
ac53063a 310 setTimeout("timeout()", 1800*1000);
1cd17194 311}