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