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