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