]>
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 = -1; | |
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 | notify(xmlhttp.responseText); | |
50 | updateFeedList(false, false); | |
51 | closeDlg(); | |
52 | } | |
53 | } | |
54 | ||
55 | function dlg_submit_callback() { | |
56 | if (xmlhttp.readyState == 4) { | |
57 | notify(xmlhttp.responseText); | |
58 | closeDlg(); | |
59 | } | |
60 | } | |
61 | ||
62 | function dlg_display_callback() { | |
63 | if (xmlhttp.readyState == 4) { | |
64 | var dlg = document.getElementById("userDlg"); | |
65 | var dlg_s = document.getElementById("userDlgShadow"); | |
66 | ||
67 | dlg.innerHTML = xmlhttp.responseText; | |
68 | dlg_s.style.display = "block"; | |
69 | } | |
70 | } | |
71 | ||
72 | function refetch_callback() { | |
73 | if (xmlhttp.readyState == 4) { | |
74 | try { | |
75 | ||
76 | if (!xmlhttp.responseXML) { | |
77 | notify("refetch_callback: backend did not return valid XML"); | |
78 | return; | |
79 | } | |
80 | ||
81 | var reply = xmlhttp.responseXML.firstChild; | |
82 | ||
83 | if (!reply) { | |
84 | notify("refetch_callback: backend did not return expected XML object"); | |
85 | return; | |
86 | } | |
87 | ||
88 | var error_code = reply.getAttribute("error-code"); | |
89 | ||
90 | if (error_code && error_code != 0) { | |
91 | return fatalError(error_code); | |
92 | } | |
93 | ||
94 | var f_document = window.frames["feeds-frame"].document; | |
95 | ||
96 | for (var l = 0; l < reply.childNodes.length; l++) { | |
97 | var id = reply.childNodes[l].getAttribute("id"); | |
98 | var ctr = reply.childNodes[l].getAttribute("counter"); | |
99 | ||
100 | var feedctr = f_document.getElementById("FEEDCTR-" + id); | |
101 | var feedu = f_document.getElementById("FEEDU-" + id); | |
102 | var feedr = f_document.getElementById("FEEDR-" + id); | |
103 | ||
104 | if (id == "global-unread") { | |
105 | global_unread = ctr; | |
106 | continue; | |
107 | } | |
108 | ||
109 | if (feedctr && feedu && feedr) { | |
110 | ||
111 | feedu.innerHTML = ctr; | |
112 | ||
113 | if (ctr > 0) { | |
114 | feedctr.className = "odd"; | |
115 | if (!feedr.className.match("Unread")) { | |
116 | feedr.className = feedr.className + "Unread"; | |
117 | } | |
118 | } else { | |
119 | feedctr.className = "invisible"; | |
120 | feedr.className = feedr.className.replace("Unread", ""); | |
121 | } | |
122 | } | |
123 | } | |
124 | ||
125 | updateTitle(""); | |
126 | notify("All feeds updated."); | |
127 | } catch (e) { | |
128 | exception_error("refetch_callback", e); | |
129 | } | |
130 | } | |
131 | } | |
132 | ||
133 | function backend_sanity_check_callback() { | |
134 | ||
135 | if (xmlhttp.readyState == 4) { | |
136 | ||
137 | try { | |
138 | ||
139 | if (!xmlhttp.responseXML) { | |
140 | fatalError(3); | |
141 | return; | |
142 | } | |
143 | ||
144 | var reply = xmlhttp.responseXML.firstChild; | |
145 | ||
146 | if (!reply) { | |
147 | fatalError(3); | |
148 | return; | |
149 | } | |
150 | ||
151 | var error_code = reply.getAttribute("error-code"); | |
152 | ||
153 | if (error_code && error_code != 0) { | |
154 | return fatalError(error_code); | |
155 | } | |
156 | ||
157 | init_second_stage(); | |
158 | ||
159 | } catch (e) { | |
160 | exception_error("backend_sanity_check_callback", e); | |
161 | } | |
162 | } | |
163 | } | |
164 | ||
165 | function scheduleFeedUpdate(force) { | |
166 | ||
167 | notify("Updating feeds in background..."); | |
168 | ||
169 | // document.title = "Tiny Tiny RSS - Updating..."; | |
170 | ||
171 | updateTitle("Updating"); | |
172 | ||
173 | var query_str = "backend.php?op=rpc&subop="; | |
174 | ||
175 | if (force) { | |
176 | query_str = query_str + "forceUpdateAllFeeds"; | |
177 | } else { | |
178 | query_str = query_str + "updateAllFeeds"; | |
179 | } | |
180 | ||
181 | var omode; | |
182 | ||
183 | if (display_tags) { | |
184 | omode = "t"; | |
185 | } else { | |
186 | omode = "fl"; | |
187 | } | |
188 | ||
189 | query_str = query_str + "&omode=" + omode; | |
190 | ||
191 | if (xmlhttp_ready(xmlhttp)) { | |
192 | xmlhttp.open("GET", query_str, true); | |
193 | xmlhttp.onreadystatechange=refetch_callback; | |
194 | xmlhttp.send(null); | |
195 | } else { | |
196 | printLockingError(); | |
197 | } | |
198 | } | |
199 | ||
200 | function updateFeedList(silent, fetch) { | |
201 | ||
202 | // if (silent != true) { | |
203 | // notify("Loading feed list..."); | |
204 | // } | |
205 | ||
206 | var query_str = "backend.php?op=feeds"; | |
207 | ||
208 | if (display_tags) { | |
209 | query_str = query_str + "&tags=1"; | |
210 | } | |
211 | ||
212 | if (getActiveFeedId()) { | |
213 | query_str = query_str + "&actid=" + getActiveFeedId(); | |
214 | } | |
215 | ||
216 | if (fetch) query_str = query_str + "&fetch=yes"; | |
217 | ||
218 | var feeds_frame = document.getElementById("feeds-frame"); | |
219 | ||
220 | feeds_frame.src = query_str; | |
221 | } | |
222 | ||
223 | function catchupAllFeeds() { | |
224 | ||
225 | var query_str = "backend.php?op=feeds&subop=catchupAll"; | |
226 | ||
227 | notify("Marking all feeds as read..."); | |
228 | ||
229 | var feeds_frame = document.getElementById("feeds-frame"); | |
230 | ||
231 | feeds_frame.src = query_str; | |
232 | ||
233 | global_unread = 0; | |
234 | updateTitle(""); | |
235 | ||
236 | } | |
237 | ||
238 | function viewCurrentFeed(skip, subop) { | |
239 | ||
240 | if (getActiveFeedId()) { | |
241 | viewfeed(getActiveFeedId(), skip, subop); | |
242 | } else { | |
243 | disableContainerChildren("headlinesToolbar", false, document); | |
244 | viewfeed(-1, skip, subop); // FIXME | |
245 | } | |
246 | } | |
247 | ||
248 | function viewfeed(feed, skip, subop) { | |
249 | var f = window.frames["feeds-frame"]; | |
250 | f.viewfeed(feed, skip, subop); | |
251 | } | |
252 | ||
253 | function timeout() { | |
254 | scheduleFeedUpdate(false); | |
255 | setTimeout("timeout()", 1800*1000); | |
256 | } | |
257 | ||
258 | function resetSearch() { | |
259 | var searchbox = document.getElementById("searchbox") | |
260 | ||
261 | if (searchbox.value != "" && getActiveFeedId()) { | |
262 | searchbox.value = ""; | |
263 | viewfeed(getActiveFeedId(), 0, ""); | |
264 | } | |
265 | } | |
266 | ||
267 | function search() { | |
268 | viewCurrentFeed(0, ""); | |
269 | } | |
270 | ||
271 | function localPiggieFunction(enable) { | |
272 | if (enable) { | |
273 | var query_str = "backend.php?op=feeds&subop=piggie"; | |
274 | ||
275 | if (xmlhttp_ready(xmlhttp)) { | |
276 | ||
277 | xmlhttp.open("GET", query_str, true); | |
278 | xmlhttp.onreadystatechange=feedlist_callback; | |
279 | xmlhttp.send(null); | |
280 | } | |
281 | } | |
282 | } | |
283 | ||
284 | function localHotkeyHandler(keycode) { | |
285 | ||
286 | /* if (keycode == 78) { | |
287 | return moveToPost('next'); | |
288 | } | |
289 | ||
290 | if (keycode == 80) { | |
291 | return moveToPost('prev'); | |
292 | } */ | |
293 | ||
294 | if (keycode == 82) { // r | |
295 | return scheduleFeedUpdate(true); | |
296 | } | |
297 | ||
298 | if (keycode == 85) { // u | |
299 | if (getActiveFeedId()) { | |
300 | return viewfeed(getActiveFeedId(), 0, "ForceUpdate"); | |
301 | } | |
302 | } | |
303 | ||
304 | if (keycode == 65) { // a | |
305 | return toggleDispRead(); | |
306 | } | |
307 | ||
308 | var f_doc = window.frames["feeds-frame"].document; | |
309 | var feedlist = f_doc.getElementById('feedList'); | |
310 | ||
311 | if (keycode == 74) { // j | |
312 | var feed = getActiveFeedId(); | |
313 | var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); | |
314 | if (new_feed) viewfeed(new_feed, 0, ''); | |
315 | } | |
316 | ||
317 | if (keycode == 75) { // k | |
318 | var feed = getActiveFeedId(); | |
319 | var new_feed = getRelativeFeedId(feedlist, feed, 'next'); | |
320 | if (new_feed) viewfeed(new_feed, 0, ''); | |
321 | } | |
322 | ||
323 | // notify("KC: " + keycode); | |
324 | ||
325 | } | |
326 | ||
327 | // if argument is undefined, current subtitle is not updated | |
328 | // use blank string to clear subtitle | |
329 | function updateTitle(s) { | |
330 | var tmp = "Tiny Tiny RSS"; | |
331 | ||
332 | if (s && s.length > 0) { | |
333 | current_subtitle = s; | |
334 | } | |
335 | ||
336 | if (global_unread > 0) { | |
337 | tmp = tmp + " (" + global_unread + ")"; | |
338 | } | |
339 | ||
340 | if (s) { | |
341 | tmp = tmp + " - " + current_subtitle; | |
342 | } | |
343 | ||
344 | if (active_title_text.length > 0) { | |
345 | tmp = tmp + " > " + active_title_text; | |
346 | } | |
347 | ||
348 | document.title = tmp; | |
349 | } | |
350 | ||
351 | function genericSanityCheck() { | |
352 | ||
353 | if (!xmlhttp) fatalError(1); | |
354 | ||
355 | setCookie("ttrss_vf_test", "TEST"); | |
356 | ||
357 | if (getCookie("ttrss_vf_test") != "TEST") { | |
358 | fatalError(2); | |
359 | } | |
360 | ||
361 | return true; | |
362 | } | |
363 | ||
364 | function init() { | |
365 | ||
366 | try { | |
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 | } catch (e) { | |
378 | exception_error("init", e); | |
379 | } | |
380 | } | |
381 | ||
382 | function init_second_stage() { | |
383 | ||
384 | try { | |
385 | ||
386 | setCookie("ttrss_vf_actfeed", ""); | |
387 | ||
388 | updateFeedList(false, false); | |
389 | document.onkeydown = hotkey_handler; | |
390 | ||
391 | var content = document.getElementById("content"); | |
392 | ||
393 | if (getCookie("ttrss_vf_vmode")) { | |
394 | var viewbox = document.getElementById("viewbox"); | |
395 | viewbox.value = getCookie("ttrss_vf_vmode"); | |
396 | } | |
397 | ||
398 | if (getCookie("ttrss_vf_limit")) { | |
399 | var limitbox = document.getElementById("limitbox"); | |
400 | limitbox.value = getCookie("ttrss_vf_limit"); | |
401 | } | |
402 | ||
403 | // if (getCookie("ttrss_vf_actfeed")) { | |
404 | // viewfeed(getCookie("ttrss_vf_actfeed"), 0, ''); | |
405 | // } | |
406 | ||
407 | // setTimeout("timeout()", 2*1000); | |
408 | // scheduleFeedUpdate(true); | |
409 | ||
410 | } catch (e) { | |
411 | exception_error("init_second_stage", e); | |
412 | } | |
413 | } | |
414 | ||
415 | function quickMenuGo() { | |
416 | ||
417 | var chooser = document.getElementById("quickMenuChooser"); | |
418 | var opid = chooser[chooser.selectedIndex].id; | |
419 | ||
420 | if (opid == "qmcPrefs") { | |
421 | gotoPreferences(); | |
422 | } | |
423 | ||
424 | if (opid == "qmcAdvSearch") { | |
425 | displayDlg("search"); | |
426 | return; | |
427 | } | |
428 | ||
429 | if (opid == "qmcAddFeed") { | |
430 | displayDlg("quickAddFeed"); | |
431 | return; | |
432 | } | |
433 | ||
434 | if (opid == "qmcRemoveFeed") { | |
435 | var actid = getActiveFeedId(); | |
436 | ||
437 | if (!actid) { | |
438 | notify("Please select some feed first."); | |
439 | return; | |
440 | } | |
441 | ||
442 | if (confirm("Remove current feed?")) { | |
443 | qfdDelete(actid); | |
444 | } | |
445 | ||
446 | return; | |
447 | } | |
448 | ||
449 | if (opid == "qmcUpdateFeeds") { | |
450 | scheduleFeedUpdate(true); | |
451 | return; | |
452 | } | |
453 | ||
454 | if (opid == "qmcCatchupAll") { | |
455 | catchupAllFeeds(); | |
456 | return; | |
457 | } | |
458 | ||
459 | if (opid == "qmcShowOnlyUnread") { | |
460 | toggleDispRead(); | |
461 | return; | |
462 | } | |
463 | ||
464 | if (opid == "qmcAddFilter") { | |
465 | displayDlg("quickAddFilter", getActiveFeedId()); | |
466 | } | |
467 | ||
468 | } | |
469 | ||
470 | function qafAdd() { | |
471 | ||
472 | if (!xmlhttp_ready(xmlhttp)) { | |
473 | printLockingError(); | |
474 | return | |
475 | } | |
476 | ||
477 | var link = document.getElementById("qafInput"); | |
478 | ||
479 | if (link.value.length == 0) { | |
480 | notify("Missing feed URL."); | |
481 | } else { | |
482 | notify("Adding feed..."); | |
483 | ||
484 | var feeds_doc = window.frames["feeds-frame"].document; | |
485 | ||
486 | feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
487 | ||
488 | xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" + | |
489 | param_escape(link.value), true); | |
490 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
491 | xmlhttp.send(null); | |
492 | ||
493 | link.value = ""; | |
494 | ||
495 | } | |
496 | } | |
497 | ||
498 | function qaddFilter() { | |
499 | ||
500 | if (!xmlhttp_ready(xmlhttp)) { | |
501 | printLockingError(); | |
502 | return | |
503 | } | |
504 | ||
505 | var regexp = document.getElementById("fadd_regexp"); | |
506 | var match = document.getElementById("fadd_match"); | |
507 | var feed = document.getElementById("fadd_feed"); | |
508 | var action = document.getElementById("fadd_action"); | |
509 | ||
510 | if (regexp.value.length == 0) { | |
511 | notify("Missing filter expression."); | |
512 | } else { | |
513 | notify("Adding filter..."); | |
514 | ||
515 | var v_match = match[match.selectedIndex].text; | |
516 | var feed_id = feed[feed.selectedIndex].id; | |
517 | var action_id = action[action.selectedIndex].id; | |
518 | ||
519 | xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" + | |
520 | param_escape(regexp.value) + "&match=" + v_match + | |
521 | "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true); | |
522 | ||
523 | xmlhttp.onreadystatechange=dlg_submit_callback; | |
524 | xmlhttp.send(null); | |
525 | ||
526 | regexp.value = ""; | |
527 | } | |
528 | ||
529 | } | |
530 | ||
531 | ||
532 | function displayDlg(id, param) { | |
533 | ||
534 | notify(""); | |
535 | ||
536 | xmlhttp.open("GET", "backend.php?op=dlg&id=" + | |
537 | param_escape(id) + "¶m=" + param_escape(param), true); | |
538 | xmlhttp.onreadystatechange=dlg_display_callback; | |
539 | xmlhttp.send(null); | |
540 | ||
541 | } | |
542 | ||
543 | function closeDlg() { | |
544 | var dlg = document.getElementById("userDlgShadow"); | |
545 | dlg.style.display = "none"; | |
546 | } | |
547 | ||
548 | function qfdDelete(feed_id) { | |
549 | ||
550 | notify("Removing feed..."); | |
551 | ||
552 | // var feeds_doc = window.frames["feeds-frame"].document; | |
553 | // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; | |
554 | ||
555 | xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id); | |
556 | xmlhttp.onreadystatechange=dlg_frefresh_callback; | |
557 | xmlhttp.send(null); | |
558 | } | |
559 | ||
560 | ||
561 | function allFeedsMenuGo() { | |
562 | var chooser = document.getElementById("allFeedsChooser"); | |
563 | ||
564 | var opname = chooser[chooser.selectedIndex].text; | |
565 | ||
566 | if (opname == "Update") { | |
567 | scheduleFeedUpdate(true); | |
568 | return; | |
569 | } | |
570 | ||
571 | if (opname == "Mark as read") { | |
572 | catchupAllFeeds(); | |
573 | return; | |
574 | } | |
575 | ||
576 | if (opname == "Show only unread") { | |
577 | toggleDispRead(); | |
578 | return; | |
579 | } | |
580 | ||
581 | } | |
582 | ||
583 | function updateFeedTitle(t) { | |
584 | active_title_text = t; | |
585 | updateTitle(); | |
586 | } | |
587 | ||
588 | function toggleDispRead() { | |
589 | var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1); | |
590 | ||
591 | hide_read_feeds = !hide_read_feeds; | |
592 | ||
593 | var feeds_doc = window.frames["feeds-frame"].document; | |
594 | ||
595 | hideOrShowFeeds(feeds_doc, hide_read_feeds); | |
596 | ||
597 | if (hide_read_feeds) { | |
598 | setCookie("ttrss_vf_hreadf", 1); | |
599 | } else { | |
600 | setCookie("ttrss_vf_hreadf", 0); | |
601 | } | |
602 | ||
603 | } | |
604 |