]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | var total_unread = 0; | |
9 | var first_run = true; | |
10 | ||
11 | var search_query = ""; | |
12 | var search_mode = ""; | |
13 | ||
14 | var display_tags = false; | |
15 | ||
16 | var global_unread = 0; | |
17 | ||
18 | /*@cc_on @*/ | |
19 | /*@if (@_jscript_version >= 5) | |
20 | // JScript gives us Conditional compilation, we can cope with old IE versions. | |
21 | // and security blocked creation of the objects. | |
22 | try { | |
23 | xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); | |
24 | } catch (e) { | |
25 | try { | |
26 | xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); | |
27 | } catch (E) { | |
28 | xmlhttp = false; | |
29 | } | |
30 | } | |
31 | @end @*/ | |
32 | ||
33 | if (!xmlhttp && typeof XMLHttpRequest!='undefined') { | |
34 | xmlhttp = new XMLHttpRequest(); | |
35 | } | |
36 | ||
37 | function toggleTags() { | |
38 | display_tags = !display_tags; | |
39 | ||
40 | var p = document.getElementById("dispSwitchPrompt"); | |
41 | ||
42 | if (display_tags) { | |
43 | p.innerHTML = "display feeds"; | |
44 | } else { | |
45 | p.innerHTML = "display tags"; | |
46 | } | |
47 | ||
48 | updateFeedList(); | |
49 | } | |
50 | ||
51 | function dlg_frefresh_callback() { | |
52 | if (xmlhttp.readyState == 4) { | |
53 | updateFeedList(false, false); | |
54 | closeDlg(); | |
55 | } | |
56 | } | |
57 | ||
58 | function dialog_refresh_callback() { | |
59 | if (xmlhttp.readyState == 4) { | |
60 | var dlg = document.getElementById("userDlg"); | |
61 | ||
62 | dlg.innerHTML = xmlhttp.responseText; | |
63 | dlg.style.display = "block"; | |
64 | } | |
65 | } | |
66 | ||
67 | function refetch_callback() { | |
68 | if (xmlhttp.readyState == 4) { | |
69 | ||
70 | // document.title = "Tiny Tiny RSS"; | |
71 | ||
72 | if (!xmlhttp.responseXML) { | |
73 | notify("refetch_callback: backend did not return valid XML"); | |
74 | return; | |
75 | } | |
76 | ||
77 | var reply = xmlhttp.responseXML.firstChild; | |
78 | ||
79 | if (!reply) { | |
80 | notify("refetch_callback: backend did not return expected XML object"); | |
81 | return; | |
82 | } | |
83 | ||
84 | var f_document = window.frames["feeds-frame"].document; | |
85 | ||
86 | for (var l = 0; l < reply.childNodes.length; l++) { | |
87 | var id = reply.childNodes[l].getAttribute("id"); | |
88 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
89 | ||
90 | var feedctr = f_document.getElementById("FEEDCTR-" + id); | |
91 | var feedu = f_document.getElementById("FEEDU-" + id); | |
92 | var feedr = f_document.getElementById("FEEDR-" + id); | |
93 | ||
94 | /* TODO figure out how to update this from viewfeed.js->view() | |
95 | disabled for now... | |
96 | ||
97 | if (id == "global-unread") { | |
98 | global_unread = ctr; | |
99 | } */ | |
100 | ||
101 | if (feedctr && feedu && feedr) { | |
102 | ||
103 | feedu.innerHTML = ctr; | |
104 | ||
105 | if (ctr > 0) { | |
106 | feedctr.className = "odd"; | |
107 | if (!feedr.className.match("Unread")) { | |
108 | feedr.className = feedr.className + "Unread"; | |
109 | } | |
110 | } else { | |
111 | feedctr.className = "invisible"; | |
112 | feedr.className = feedr.className.replace("Unread", ""); | |
113 | } | |
114 | } | |
115 | } | |
116 | ||
117 | updateTitle(""); | |
118 | notify("All feeds updated."); | |
119 | ||
120 | } | |
121 | } | |
122 | ||
123 | function updateFeed(feed_id) { | |
124 | ||
125 | var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id; | |
126 | ||
127 | if (xmlhttp_ready(xmlhttp)) { | |
128 | xmlhttp.open("GET", query_str, true); | |
129 | xmlhttp.onreadystatechange=feed_update_callback; | |
130 | xmlhttp.send(null); | |
131 | } else { | |
132 | printLockingError(); | |
133 | } | |
134 | ||
135 | } | |
136 | ||
137 | function scheduleFeedUpdate(force) { | |
138 | ||
139 | notify("Updating feeds in background..."); | |
140 | ||
141 | // document.title = "Tiny Tiny RSS - Updating..."; | |
142 | ||
143 | updateTitle("Updating..."); | |
144 | ||
145 | var query_str = "backend.php?op=rpc&subop="; | |
146 | ||
147 | if (force) { | |
148 | query_str = query_str + "forceUpdateAllFeeds"; | |
149 | } else { | |
150 | query_str = query_str + "updateAllFeeds"; | |
151 | } | |
152 | ||
153 | var omode; | |
154 | ||
155 | if (display_tags) { | |
156 | omode = "t"; | |
157 | } else { | |
158 | omode = "fl"; | |
159 | } | |
160 | ||
161 | query_str = query_str + "&omode=" + omode; | |
162 | ||
163 | if (xmlhttp_ready(xmlhttp)) { | |
164 | xmlhttp.open("GET", query_str, true); | |
165 | xmlhttp.onreadystatechange=refetch_callback; | |
166 | xmlhttp.send(null); | |
167 | } else { | |
168 | printLockingError(); | |
169 | } | |
170 | } | |
171 | ||
172 | function updateFeedList(silent, fetch) { | |
173 | ||
174 | // if (silent != true) { | |
175 | // notify("Loading feed list..."); | |
176 | // } | |
177 | ||
178 | var query_str = "backend.php?op=feeds"; | |
179 | ||
180 | if (display_tags) { | |
181 | query_str = query_str + "&tags=1"; | |
182 | } | |
183 | ||
184 | if (getActiveFeedId()) { | |
185 | query_str = query_str + "&actid=" + getActiveFeedId(); | |
186 | } | |
187 | ||
188 | if (fetch) query_str = query_str + "&fetch=yes"; | |
189 | ||
190 | var feeds_frame = document.getElementById("feeds-frame"); | |
191 | ||
192 | feeds_frame.src = query_str; | |
193 | } | |
194 | ||
195 | function catchupAllFeeds() { | |
196 | ||
197 | var query_str = "backend.php?op=feeds&subop=catchupAll"; | |
198 | ||
199 | notify("Marking all feeds as read..."); | |
200 | ||
201 | var feeds_frame = document.getElementById("feeds-frame"); | |
202 | ||
203 | feeds_frame.src = query_str; | |
204 | ||
205 | global_unread = 0; | |
206 | updateTitle(); | |
207 | ||
208 | } | |
209 | ||
210 | function viewCurrentFeed(skip, subop) { | |
211 | ||
212 | if (getActiveFeedId()) { | |
213 | viewfeed(getActiveFeedId(), skip, subop); | |
214 | } else { | |
215 | disableContainerChildren("headlinesToolbar", false, document); | |
216 | viewfeed(-1, skip, subop); // FIXME | |
217 | } | |
218 | } | |
219 | ||
220 | function viewfeed(feed, skip, subop) { | |
221 | ||
222 | // notify("Loading headlines..."); | |
223 | ||
224 | enableHotkeys(); | |
225 | ||
226 | var searchbox = document.getElementById("searchbox"); | |
227 | ||
228 | if (searchbox) { | |
229 | search_query = searchbox.value; | |
230 | } else { | |
231 | search_query = ""; | |
232 | } | |
233 | ||
234 | var searchmodebox = document.getElementById("searchmodebox"); | |
235 | ||
236 | if (searchmodebox) { | |
237 | search_mode = searchmodebox.value; | |
238 | } else { | |
239 | search_mode = ""; | |
240 | } | |
241 | ||
242 | setCookie("ttrss_vf_smode", search_mode); | |
243 | ||
244 | var viewbox = document.getElementById("viewbox"); | |
245 | ||
246 | var view_mode; | |
247 | ||
248 | if (viewbox) { | |
249 | view_mode = viewbox[viewbox.selectedIndex].text; | |
250 | } else { | |
251 | view_mode = "All Posts"; | |
252 | } | |
253 | ||
254 | setCookie("ttrss_vf_vmode", view_mode); | |
255 | ||
256 | var limitbox = document.getElementById("limitbox"); | |
257 | ||
258 | var limit; | |
259 | ||
260 | if (limitbox) { | |
261 | limit = limitbox[limitbox.selectedIndex].text; | |
262 | setCookie("ttrss_vf_limit", limit); | |
263 | } else { | |
264 | limit = "All"; | |
265 | } | |
266 | ||
267 | setActiveFeedId(feed); | |
268 | ||
269 | var f_doc = frames["feeds-frame"].document; | |
270 | ||
271 | // f_doc.getElementById("ACTFEEDID").innerHTML = feed; | |
272 | ||
273 | if (subop == "MarkAllRead") { | |
274 | ||
275 | var feedr = f_doc.getElementById("FEEDR-" + feed); | |
276 | var feedctr = f_doc.getElementById("FEEDCTR-" + feed); | |
277 | ||
278 | feedctr.className = "invisible"; | |
279 | ||
280 | if (feedr.className.match("Unread")) { | |
281 | feedr.className = feedr.className.replace("Unread", ""); | |
282 | } | |
283 | } | |
284 | ||
285 | var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) + | |
286 | "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) + | |
287 | "&view=" + param_escape(view_mode) + "&limit=" + limit + | |
288 | "&smode=" + param_escape(search_mode); | |
289 | ||
290 | if (search_query != "") { | |
291 | query = query + "&search=" + param_escape(search_query); | |
292 | } | |
293 | ||
294 | var headlines_frame = parent.frames["headlines-frame"]; | |
295 | ||
296 | headlines_frame.location.href = query + "&addheader=true"; | |
297 | ||
298 | cleanSelected("feedsList"); | |
299 | var feedr = document.getElementById("FEEDR-" + feed); | |
300 | if (feedr) { | |
301 | feedr.className = feedr.className + "Selected"; | |
302 | } | |
303 | ||
304 | disableContainerChildren("headlinesToolbar", false, doc); | |
305 | ||
306 | var btnMarkAsRead = document.getElementById("btnMarkFeedAsRead"); | |
307 | ||
308 | if (btnMarkAsRead && !isNumeric(feed)) { | |
309 | btnMarkAsRead.disabled = true; | |
310 | btnMarkAsRead.className = "disabledButton"; | |
311 | } | |
312 | ||
313 | // notify(""); | |
314 | ||
315 | } | |
316 | ||
317 | ||
318 | function timeout() { | |
319 | scheduleFeedUpdate(true); | |
320 | setTimeout("timeout()", 1800*1000); | |
321 | } | |
322 | ||
323 | function resetSearch() { | |
324 | var searchbox = document.getElementById("searchbox") | |
325 | ||
326 | if (searchbox.value != "" && getActiveFeedId()) { | |
327 | searchbox.value = ""; | |
328 | viewfeed(getActiveFeedId(), 0, ""); | |
329 | } | |
330 | } | |
331 | ||
332 | function search() { | |
333 | viewCurrentFeed(0, ""); | |
334 | } | |
335 | ||
336 | function localPiggieFunction(enable) { | |
337 | if (enable) { | |
338 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
339 | ||
340 | if (xmlhttp_ready(xmlhttp)) { | |
341 | ||
342 | xmlhttp.open("GET", query_str, true); | |
343 | xmlhttp.onreadystatechange=feedlist_callback; | |
344 | xmlhttp.send(null); | |
345 | } | |
346 | } | |
347 | } | |
348 | ||
349 | function localHotkeyHandler(keycode) { | |
350 | ||
351 | /* if (keycode == 78) { | |
352 | return moveToPost('next'); | |
353 | } | |
354 | ||
355 | if (keycode == 80) { | |
356 | return moveToPost('prev'); | |
357 | } */ | |
358 | ||
359 | if (keycode == 82) { | |
360 | return scheduleFeedUpdate(true); | |
361 | } | |
362 | ||
363 | if (keycode == 85) { | |
364 | return viewfeed(getActiveFeedId(), 0, "ForceUpdate"); | |
365 | } | |
366 | ||
367 | // notify("KC: " + keycode); | |
368 | ||
369 | } | |
370 | ||
371 | function updateTitle(s) { | |
372 | var tmp = "Tiny Tiny RSS"; | |
373 | ||
374 | if (global_unread > 0) { | |
375 | tmp = tmp + " (" + global_unread + ")"; | |
376 | } | |
377 | ||
378 | if (s) { | |
379 | tmp = tmp + " - " + s; | |
380 | } | |
381 | document.title = tmp; | |
382 | } | |
383 | ||
384 | function genericSanityCheck() { | |
385 | ||
386 | if (!xmlhttp) { | |
387 | document.getElementById("headlines").innerHTML = | |
388 | "<b>Fatal error:</b> This program requires XmlHttpRequest " + | |
389 | "to function properly. Your browser doesn't seem to support it."; | |
390 | return false; | |
391 | } | |
392 | ||
393 | setCookie("ttrss_vf_test", "TEST"); | |
394 | if (getCookie("ttrss_vf_test") != "TEST") { | |
395 | ||
396 | document.getElementById("headlines").innerHTML = | |
397 | "<b>Fatal error:</b> This program requires cookies " + | |
398 | "to function properly. Your browser doesn't seem to support them."; | |
399 | ||
400 | return false; | |
401 | } | |
402 | ||
403 | return true; | |
404 | } | |
405 | ||
406 | function init() { | |
407 | ||
408 | disableContainerChildren("headlinesToolbar", true); | |
409 | ||
410 | if (!genericSanityCheck()) | |
411 | return; | |
412 | ||
413 | setCookie("ttrss_vf_actfeed", ""); | |
414 | ||
415 | updateFeedList(false, false); | |
416 | document.onkeydown = hotkey_handler; | |
417 | ||
418 | setTimeout("timeout()", 1800*1000); | |
419 | scheduleFeedUpdate(true); | |
420 | ||
421 | var content = document.getElementById("content"); | |
422 | ||
423 | if (getCookie("ttrss_vf_vmode")) { | |
424 | var viewbox = document.getElementById("viewbox"); | |
425 | viewbox.value = getCookie("ttrss_vf_vmode"); | |
426 | } | |
427 | ||
428 | if (getCookie("ttrss_vf_limit")) { | |
429 | var limitbox = document.getElementById("limitbox"); | |
430 | limitbox.value = getCookie("ttrss_vf_limit"); | |
431 | } | |
432 | ||
433 | // if (getCookie("ttrss_vf_actfeed")) { | |
434 | // viewfeed(getCookie("ttrss_vf_actfeed"), 0, ''); | |
435 | // } | |
436 | ||
437 | } | |
438 | ||
439 | function quickMenuGo() { | |
440 | var chooser = document.getElementById("quickMenuChooser"); | |
441 | ||
442 | var opname = chooser[chooser.selectedIndex].text; | |
443 | ||
444 | if (opname == "Preferences") { | |
445 | gotoPreferences(); | |
446 | } | |
447 | ||
448 | if (opname == "Extended search") { | |
449 | displayDlg("search"); | |
450 | return; | |
451 | } | |
452 | ||
453 | if (opname.match("Add new feed")) { | |
454 | displayDlg("quickAddFeed"); | |
455 | return; | |
456 | } | |
457 | ||
458 | if (opname.match("Remove this feed")) { | |
459 | var actid = getActiveFeedId(); | |
460 | ||
461 | if (!actid) { | |
462 | notify("Please select some feed first."); | |
463 | return; | |
464 | } | |
465 | ||
466 | displayDlg("quickDelFeed", actid); | |
467 | return; | |
468 | } | |
469 | } | |
470 | ||
471 | function qafAdd() { | |
472 | ||
473 | if (!xmlhttp_ready(xmlhttp)) { | |
474 | printLockingError(); | |
475 | return | |
476 | } | |
477 | ||
478 | var link = document.getElementById("qafInput"); | |
479 | ||
480 | if (link.value.length == 0) { | |
481 | notify("Missing feed URL."); | |
482 | } else { | |
483 | notify("Adding feed..."); | |
484 | ||
485 | var feeds_doc = window.frames["feeds-frame"].document; | |
486 | ||
487 | feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
488 | ||
489 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=add&link=" + | |
490 | param_escape(link.value), true); | |
491 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
492 | xmlhttp.send(null); | |
493 | ||
494 | link.value = ""; | |
495 | ||
496 | } | |
497 | } | |
498 | ||
499 | function displayDlg(id, param) { | |
500 | ||
501 | notify(""); | |
502 | ||
503 | xmlhttp.open("GET", "backend.php?op=dlg&id=" + | |
504 | param_escape(id) + "¶m=" + param_escape(param), true); | |
505 | xmlhttp.onreadystatechange=dialog_refresh_callback; | |
506 | xmlhttp.send(null); | |
507 | ||
508 | } | |
509 | ||
510 | function closeDlg() { | |
511 | var dlg = document.getElementById("userDlg"); | |
512 | dlg.style.display = "none"; | |
513 | } | |
514 | ||
515 | function qfdDelete(feed_id) { | |
516 | ||
517 | notify("Removing feed..."); | |
518 | ||
519 | var feeds_doc = window.frames["feeds-frame"].document; | |
520 | feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
521 | ||
522 | xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=remove&ids=" + feed_id); | |
523 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
524 | xmlhttp.send(null); | |
525 | } | |
526 |