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