]>
Commit | Line | Data |
---|---|---|
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 | ||
6 | var xmlhttp = false; | |
525116d4 | 7 | var xmlhttp_rpc = false; |
c3a8d71a | 8 | var xmlhttp_view = false; |
1cd17194 | 9 | |
76798ff3 | 10 | var total_unread = 0; |
525116d4 | 11 | var first_run = true; |
76798ff3 | 12 | |
9cfc649a AD |
13 | var active_post_id = false; |
14 | var active_feed_id = false; | |
c3a8d71a AD |
15 | var active_offset = false; |
16 | ||
17 | var total_feed_entries = false; | |
18 | ||
19 | var _viewfeed_autoselect_first = false; | |
20 | var _viewfeed_autoselect_last = false; | |
9cfc649a | 21 | |
c374a3fe AD |
22 | var search_query = ""; |
23 | ||
1cd17194 AD |
24 | /*@cc_on @*/ |
25 | /*@if (@_jscript_version >= 5) | |
26 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
27 | // and security blocked creation of the objects. | |
28 | try { | |
29 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
30 | } catch (e) { | |
31 | try { | |
32 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
508a81e1 | 33 | xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); |
c3a8d71a | 34 | xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP"); |
1cd17194 AD |
35 | } catch (E) { |
36 | xmlhttp = false; | |
508a81e1 | 37 | xmlhttp_rpc = false; |
c3a8d71a | 38 | xmlhttp_view = false; |
1cd17194 AD |
39 | } |
40 | } | |
41 | @end @*/ | |
42 | ||
43 | if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
44 | xmlhttp = new XMLHttpRequest(); | |
525116d4 | 45 | xmlhttp_rpc = new XMLHttpRequest(); |
c3a8d71a | 46 | xmlhttp_view = new XMLHttpRequest(); |
1cd17194 AD |
47 | } |
48 | ||
1cd17194 | 49 | function feedlist_callback() { |
d76a3b03 | 50 | var container = document.getElementById('feeds'); |
1cd17194 | 51 | if (xmlhttp.readyState == 4) { |
d76a3b03 | 52 | container.innerHTML=xmlhttp.responseText; |
76798ff3 | 53 | |
525116d4 | 54 | if (first_run) { |
cb246176 | 55 | scheduleFeedUpdate(false); |
525116d4 AD |
56 | first_run = false; |
57 | } else { | |
58 | notify(""); | |
c0e5a40e AD |
59 | } |
60 | } | |
1cd17194 AD |
61 | } |
62 | ||
63 | function viewfeed_callback() { | |
d76a3b03 | 64 | var container = document.getElementById('headlines'); |
1cd17194 | 65 | if (xmlhttp.readyState == 4) { |
d76a3b03 | 66 | container.innerHTML = xmlhttp.responseText; |
a1a8a2be AD |
67 | |
68 | var factive = document.getElementById("FACTIVE"); | |
69 | var funread = document.getElementById("FUNREAD"); | |
70 | var ftotal = document.getElementById("FTOTAL"); | |
71 | ||
c3a8d71a AD |
72 | if (_viewfeed_autoselect_first == true) { |
73 | _viewfeed_autoselect_first = false; | |
74 | view(getFirstVisibleHeadlineId(), active_feed_id); | |
75 | } | |
76 | ||
77 | if (_viewfeed_autoselect_last == true) { | |
78 | _viewfeed_autoselect_last = false; | |
79 | view(getLastVisibleHeadlineId(), active_feed_id); | |
80 | } | |
81 | ||
a1a8a2be AD |
82 | if (ftotal && factive && funread) { |
83 | var feed_id = factive.innerHTML; | |
84 | ||
85 | var feedr = document.getElementById("FEEDR-" + feed_id); | |
86 | var feedt = document.getElementById("FEEDT-" + feed_id); | |
87 | var feedu = document.getElementById("FEEDU-" + feed_id); | |
88 | ||
89 | feedt.innerHTML = ftotal.innerHTML; | |
90 | feedu.innerHTML = funread.innerHTML; | |
91 | ||
c3a8d71a AD |
92 | total_feed_entries = ftotal.innerHTML; |
93 | ||
a1a8a2be AD |
94 | if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { |
95 | feedr.className = feedr.className + "Unread"; | |
96 | } else if (feedu.innerHTML <= 0) { | |
97 | feedr.className = feedr.className.replace("Unread", ""); | |
98 | } | |
99 | ||
a3ee2a38 AD |
100 | cleanSelected("feedsList"); |
101 | ||
102 | feedr.className = feedr.className + "Selected"; | |
a1a8a2be | 103 | } |
1c37c607 | 104 | |
c374a3fe | 105 | var searchbox = document.getElementById("searchbox"); |
c374a3fe AD |
106 | searchbox.value = search_query; |
107 | ||
b5daec98 AD |
108 | markHeadline(active_post_id); |
109 | ||
1c37c607 AD |
110 | notify(""); |
111 | ||
112 | } | |
1cd17194 AD |
113 | } |
114 | ||
115 | function view_callback() { | |
d76a3b03 | 116 | var container = document.getElementById('content'); |
c3a8d71a AD |
117 | if (xmlhttp_view.readyState == 4) { |
118 | container.innerHTML=xmlhttp_view.responseText; | |
b10e1550 | 119 | markHeadline(active_post_id); |
1cd17194 AD |
120 | } |
121 | } | |
122 | ||
525116d4 | 123 | function refetch_callback() { |
c0e5a40e | 124 | |
525116d4 | 125 | if (xmlhttp_rpc.readyState == 4) { |
c3b81db0 | 126 | notify("All feeds updated"); |
c3b81db0 | 127 | var container = document.getElementById('feeds'); |
c3b81db0 | 128 | container.innerHTML = xmlhttp_rpc.responseText; |
55193822 | 129 | document.title = "Tiny Tiny RSS"; |
c0e5a40e | 130 | } |
525116d4 AD |
131 | } |
132 | ||
cb246176 | 133 | function scheduleFeedUpdate(force) { |
525116d4 AD |
134 | |
135 | notify("Updating feeds in background..."); | |
136 | ||
55193822 AD |
137 | document.title = "Tiny Tiny RSS - Updating..."; |
138 | ||
cb246176 AD |
139 | var query_str = "backend.php?op=rpc&subop="; |
140 | ||
141 | if (force) { | |
c3b81db0 | 142 | query_str = query_str + "forceUpdateAllFeeds"; |
cb246176 | 143 | } else { |
c3b81db0 | 144 | query_str = query_str + "updateAllFeeds"; |
cb246176 | 145 | } |
525116d4 | 146 | |
c0e5a40e | 147 | if (xmlhttp_ready(xmlhttp_rpc)) { |
525116d4 AD |
148 | xmlhttp_rpc.open("GET", query_str, true); |
149 | xmlhttp_rpc.onreadystatechange=refetch_callback; | |
150 | xmlhttp_rpc.send(null); | |
151 | } else { | |
152 | printLockingError(); | |
c0e5a40e | 153 | } |
525116d4 | 154 | } |
1cd17194 | 155 | |
525116d4 | 156 | function updateFeedList(silent, fetch) { |
c0e5a40e | 157 | |
525116d4 | 158 | if (silent != true) { |
11c2f3fa | 159 | notify("Loading feed list..."); |
40d13c28 | 160 | } |
82baad4a | 161 | |
331900c6 AD |
162 | var query_str = "backend.php?op=feeds"; |
163 | ||
164 | if (fetch) query_str = query_str + "&fetch=yes"; | |
165 | ||
c0e5a40e | 166 | if (xmlhttp_ready(xmlhttp)) { |
076682aa AD |
167 | xmlhttp.open("GET", query_str, true); |
168 | xmlhttp.onreadystatechange=feedlist_callback; | |
169 | xmlhttp.send(null); | |
170 | } else { | |
a234aee5 | 171 | printLockingError(); |
076682aa | 172 | } |
1cd17194 AD |
173 | } |
174 | ||
175847de AD |
175 | function catchupPage(feed) { |
176 | ||
c0e5a40e | 177 | if (!xmlhttp_ready(xmlhttp)) { |
a234aee5 | 178 | printLockingError(); |
076682aa AD |
179 | return |
180 | } | |
181 | ||
175847de AD |
182 | var content = document.getElementById("headlinesList"); |
183 | ||
184 | var rows = new Array(); | |
185 | ||
186 | for (i = 0; i < content.rows.length; i++) { | |
187 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
188 | if (row_id.length > 0) { | |
cb0bd8bd AD |
189 | if (content.rows[i].className.match("Unread")) { |
190 | rows.push(row_id); | |
191 | content.rows[i].className = content.rows[i].className.replace("Unread", ""); | |
192 | } | |
175847de AD |
193 | } |
194 | } | |
195 | ||
cb0bd8bd | 196 | if (rows.length > 0) { |
175847de | 197 | |
cb0bd8bd AD |
198 | var feedr = document.getElementById("FEEDR-" + feed); |
199 | var feedu = document.getElementById("FEEDU-" + feed); | |
200 | ||
201 | feedu.innerHTML = feedu.innerHTML - rows.length; | |
202 | ||
203 | if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { | |
204 | feedr.className = feedr.className + "Unread"; | |
205 | } else if (feedu.innerHTML <= 0) { | |
206 | feedr.className = feedr.className.replace("Unread", ""); | |
207 | } | |
208 | ||
209 | var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + | |
210 | param_escape(rows.toString()); | |
211 | ||
212 | notify("Marking this page as read..."); | |
e1123aee AD |
213 | |
214 | var button = document.getElementById("btnCatchupPage"); | |
215 | ||
216 | button.className = "disabledButton"; | |
217 | button.href = ""; | |
cb0bd8bd AD |
218 | |
219 | xmlhttp.open("GET", query_str, true); | |
220 | xmlhttp.onreadystatechange=notify_callback; | |
221 | xmlhttp.send(null); | |
175847de | 222 | |
cb0bd8bd AD |
223 | } else { |
224 | notify("No unread items on this page."); | |
175847de | 225 | |
cb0bd8bd | 226 | } |
175847de AD |
227 | } |
228 | ||
476cac42 | 229 | function catchupAllFeeds() { |
076682aa | 230 | |
c0e5a40e | 231 | if (!xmlhttp_ready(xmlhttp)) { |
a234aee5 | 232 | printLockingError(); |
076682aa AD |
233 | return |
234 | } | |
476cac42 AD |
235 | var query_str = "backend.php?op=feeds&subop=catchupAll"; |
236 | ||
237 | notify("Marking all feeds as read..."); | |
238 | ||
239 | xmlhttp.open("GET", query_str, true); | |
240 | xmlhttp.onreadystatechange=feedlist_callback; | |
241 | xmlhttp.send(null); | |
242 | ||
243 | } | |
1cd17194 | 244 | |
476cac42 | 245 | function viewfeed(feed, skip, subop) { |
1cd17194 | 246 | |
36bf7496 AD |
247 | enableHotkeys(); |
248 | ||
c374a3fe AD |
249 | var searchbox = document.getElementById("searchbox"); |
250 | ||
251 | if (searchbox) { | |
252 | search_query = searchbox.value; | |
253 | } else { | |
254 | search_query = ""; | |
255 | } | |
256 | ||
257 | /* if (active_feed_id == feed && subop != "ForceUpdate") { | |
258 | notify("This feed is currently selected."); | |
259 | return; | |
260 | } */ | |
d76a3b03 | 261 | |
c3a8d71a AD |
262 | if (skip < 0 || skip > total_feed_entries) { |
263 | return; | |
264 | } | |
265 | ||
c0e5a40e | 266 | if (!xmlhttp_ready(xmlhttp)) { |
a234aee5 | 267 | printLockingError(); |
076682aa AD |
268 | return |
269 | } | |
c3a8d71a | 270 | |
431ade55 | 271 | if (active_feed_id != feed || skip != active_offset) { |
b5daec98 | 272 | active_post_id = false; |
431ade55 | 273 | } |
b5daec98 | 274 | |
9cfc649a | 275 | active_feed_id = feed; |
c3a8d71a | 276 | active_offset = skip; |
076682aa | 277 | |
c374a3fe AD |
278 | var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) + |
279 | "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop); | |
280 | ||
281 | if (search_query != "") { | |
282 | query = query + "&search=" + param_escape(search_query); | |
283 | } | |
284 | ||
285 | xmlhttp.open("GET", query, true); | |
1cd17194 AD |
286 | xmlhttp.onreadystatechange=viewfeed_callback; |
287 | xmlhttp.send(null); | |
288 | ||
1c37c607 AD |
289 | notify("Loading headlines..."); |
290 | ||
1cd17194 AD |
291 | } |
292 | ||
b5daec98 AD |
293 | function markHeadline(id) { |
294 | var row = document.getElementById("RROW-" + id); | |
295 | if (row) { | |
296 | row.className = row.className + "Selected"; | |
297 | } | |
298 | } | |
299 | ||
a3ee2a38 AD |
300 | function cleanSelected(element) { |
301 | var content = document.getElementById(element); | |
9cfc649a AD |
302 | |
303 | var rows = new Array(); | |
304 | ||
305 | for (i = 0; i < content.rows.length; i++) { | |
306 | content.rows[i].className = content.rows[i].className.replace("Selected", ""); | |
307 | } | |
308 | ||
309 | } | |
310 | ||
a1a8a2be | 311 | function view(id,feed_id) { |
d76a3b03 | 312 | |
36bf7496 AD |
313 | enableHotkeys(); |
314 | ||
c0e5a40e | 315 | if (!xmlhttp_ready(xmlhttp_view)) { |
a234aee5 | 316 | printLockingError(); |
076682aa AD |
317 | return |
318 | } | |
319 | ||
d76a3b03 AD |
320 | var crow = document.getElementById("RROW-" + id); |
321 | ||
a1a8a2be AD |
322 | if (crow.className.match("Unread")) { |
323 | var umark = document.getElementById("FEEDU-" + feed_id); | |
324 | umark.innerHTML = umark.innerHTML - 1; | |
d76a3b03 | 325 | crow.className = crow.className.replace("Unread", ""); |
d76a3b03 | 326 | |
a1a8a2be AD |
327 | if (umark.innerHTML == "0") { |
328 | var feedr = document.getElementById("FEEDR-" + feed_id); | |
329 | feedr.className = feedr.className.replace("Unread", ""); | |
330 | } | |
9cfc649a | 331 | |
76798ff3 | 332 | total_unread--; |
76798ff3 | 333 | } |
1cd17194 | 334 | |
a3ee2a38 | 335 | cleanSelected("headlinesList"); |
b10e1550 | 336 | // crow.className = crow.className + "Selected"; |
9cfc649a | 337 | |
b197f117 AD |
338 | var upd_img_pic = document.getElementById("FUPDPIC-" + id); |
339 | ||
340 | if (upd_img_pic) { | |
341 | upd_img_pic.innerHTML = ""; | |
342 | } | |
343 | ||
c33c296c | 344 | // document.getElementById('content').innerHTML='Loading, please wait...'; |
1cd17194 | 345 | |
9cfc649a AD |
346 | active_post_id = id; |
347 | ||
c3a8d71a AD |
348 | xmlhttp_view.open("GET", "backend.php?op=view&id=" + param_escape(id), true); |
349 | xmlhttp_view.onreadystatechange=view_callback; | |
350 | xmlhttp_view.send(null); | |
1cd17194 | 351 | |
c0e5a40e | 352 | |
1cd17194 AD |
353 | } |
354 | ||
40d13c28 | 355 | function timeout() { |
cb246176 | 356 | scheduleFeedUpdate(true); |
ac53063a | 357 | setTimeout("timeout()", 1800*1000); |
ac53063a AD |
358 | } |
359 | ||
c374a3fe AD |
360 | function resetSearch() { |
361 | document.getElementById("searchbox").value = ""; | |
362 | viewfeed(active_feed_id, 0, ""); | |
363 | } | |
ac53063a | 364 | |
c374a3fe | 365 | function search(feed) { |
c374a3fe | 366 | viewfeed(feed, 0, ""); |
76798ff3 | 367 | } |
1cd17194 | 368 | |
13ad9102 AD |
369 | function localPiggieFunction(enable) { |
370 | if (enable) { | |
371 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
372 | ||
c0e5a40e | 373 | if (xmlhttp_ready(xmlhttp)) { |
13ad9102 AD |
374 | |
375 | xmlhttp.open("GET", query_str, true); | |
376 | xmlhttp.onreadystatechange=feedlist_callback; | |
377 | xmlhttp.send(null); | |
378 | } | |
379 | } | |
380 | } | |
381 | ||
9cfc649a AD |
382 | function relativeid_callback() { |
383 | ||
384 | if (xmlhttp_rpc.readyState == 4) { | |
385 | notify(xmlhttp_rpc.responseText); | |
386 | } | |
387 | ||
388 | } | |
389 | ||
390 | function getVisibleHeadlineIds() { | |
391 | ||
392 | var content = document.getElementById("headlinesList"); | |
393 | ||
394 | var rows = new Array(); | |
395 | ||
396 | for (i = 0; i < content.rows.length; i++) { | |
397 | var row_id = content.rows[i].id.replace("RROW-", ""); | |
398 | if (row_id.length > 0) { | |
399 | rows.push(row_id); | |
400 | } | |
401 | } | |
9cfc649a | 402 | return rows; |
9cfc649a AD |
403 | } |
404 | ||
c3a8d71a AD |
405 | function getFirstVisibleHeadlineId() { |
406 | var rows = getVisibleHeadlineIds(); | |
407 | return rows[0]; | |
408 | } | |
9cfc649a | 409 | |
c3a8d71a AD |
410 | function getLastVisibleHeadlineId() { |
411 | var rows = getVisibleHeadlineIds(); | |
412 | return rows[rows.length-1]; | |
413 | } | |
9cfc649a | 414 | |
c3a8d71a | 415 | function moveToPost(mode) { |
9cfc649a AD |
416 | |
417 | var rows = getVisibleHeadlineIds(); | |
418 | ||
419 | var prev_id; | |
420 | var next_id; | |
421 | ||
c3a8d71a AD |
422 | if (active_post_id == false) { |
423 | next_id = getFirstVisibleHeadlineId(); | |
424 | prev_id = getLastVisibleHeadlineId(); | |
425 | } else { | |
426 | for (var i = 0; i < rows.length; i++) { | |
427 | if (rows[i] == active_post_id) { | |
428 | prev_id = rows[i-1]; | |
429 | next_id = rows[i+1]; | |
430 | } | |
9cfc649a AD |
431 | } |
432 | } | |
433 | ||
c3a8d71a AD |
434 | if (mode == "next") { |
435 | if (next_id != undefined) { | |
436 | view(next_id, active_feed_id); | |
437 | } else { | |
438 | _viewfeed_autoselect_first = true; | |
439 | viewfeed(active_feed_id, active_offset+15); | |
440 | } | |
9cfc649a AD |
441 | } |
442 | ||
c3a8d71a AD |
443 | if (mode == "prev") { |
444 | if ( prev_id != undefined) { | |
445 | view(prev_id, active_feed_id); | |
446 | } else { | |
447 | _viewfeed_autoselect_last = true; | |
448 | viewfeed(active_feed_id, active_offset-15); | |
449 | } | |
9cfc649a AD |
450 | } |
451 | ||
452 | } | |
453 | ||
454 | function localHotkeyHandler(keycode) { | |
455 | ||
9cfc649a | 456 | if (keycode == 78) { |
c3a8d71a | 457 | return moveToPost('next'); |
9cfc649a AD |
458 | } |
459 | ||
460 | if (keycode == 80) { | |
c3a8d71a | 461 | return moveToPost('prev'); |
9cfc649a | 462 | } |
c3a8d71a AD |
463 | |
464 | if (keycode == 82) { | |
465 | return scheduleFeedUpdate(true); | |
466 | } | |
467 | ||
468 | if (keycode == 85) { | |
469 | return viewfeed(active_feed_id, active_offset, "ForceUpdate"); | |
470 | } | |
471 | ||
472 | // notify("KC: " + keycode); | |
473 | ||
9cfc649a AD |
474 | } |
475 | ||
13ad9102 | 476 | |
76798ff3 | 477 | function init() { |
c0e5a40e AD |
478 | |
479 | // IE kludge | |
480 | ||
481 | if (xmlhttp && !xmlhttp_rpc) { | |
482 | xmlhttp_rpc = xmlhttp; | |
483 | xmlhttp_view = xmlhttp; | |
484 | } | |
485 | ||
486 | if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) { | |
c3a8d71a AD |
487 | document.getElementById("headlines").innerHTML = |
488 | "<b>Fatal error:</b> This program needs XmlHttpRequest " + | |
489 | "to function properly. Your browser doesn't seem to support it."; | |
490 | return; | |
491 | } | |
492 | ||
476cac42 | 493 | updateFeedList(false, false); |
13ad9102 | 494 | document.onkeydown = hotkey_handler; |
ac53063a | 495 | setTimeout("timeout()", 1800*1000); |
1cd17194 | 496 | } |