4 var display_tags = false;
5 var global_unread = -1;
6 var active_title_text = "";
7 var current_subtitle = "";
9 var _qfd_deleted_feed = 0;
12 /*@if (@_jscript_version >= 5)
13 // JScript gives us Conditional compilation, we can cope with old IE versions.
14 // and security blocked creation of the objects.
16 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
19 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
26 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
27 xmlhttp = new XMLHttpRequest();
30 function toggleTags() {
31 display_tags = !display_tags;
33 var p = document.getElementById("dispSwitchPrompt");
36 p.innerHTML = "display feeds";
38 p.innerHTML = "display tags";
44 function dlg_frefresh_callback() {
45 if (xmlhttp.readyState == 4) {
46 notify(xmlhttp.responseText);
47 updateFeedList(false, false);
48 if (_qfd_deleted_feed) {
49 var hframe = document.getElementById("headlines-frame");
51 hframe.src = "backend.php?op=error&msg=No%20feed%20selected.";
58 function dlg_submit_callback() {
59 if (xmlhttp.readyState == 4) {
60 notify(xmlhttp.responseText);
65 function dlg_display_callback() {
66 if (xmlhttp.readyState == 4) {
67 var dlg = document.getElementById("userDlg");
68 var dlg_s = document.getElementById("userDlgShadow");
70 dlg.innerHTML = xmlhttp.responseText;
71 dlg_s.style.display = "block";
75 function hide_unread_callback() {
76 if (xmlhttp.readyState == 4) {
80 var reply = xmlhttp.responseXML.firstChild.firstChild;
81 var value = reply.getAttribute("value");
82 var hide_read_feeds = (value != "false")
83 var feeds_doc = window.frames["feeds-frame"].document;
85 hideOrShowFeeds(feeds_doc, hide_read_feeds);
87 if (hide_read_feeds) {
88 setCookie("ttrss_vf_hreadf", 1);
90 setCookie("ttrss_vf_hreadf", 0);
94 exception_error("hide_unread_callback", e);
100 function refetch_callback() {
101 if (xmlhttp.readyState == 4) {
104 if (!xmlhttp.responseXML) {
105 notify("refetch_callback: backend did not return valid XML");
109 var reply = xmlhttp.responseXML.firstChild;
112 notify("refetch_callback: backend did not return expected XML object");
117 var error_code = reply.getAttribute("error-code");
119 if (error_code && error_code != 0) {
120 return fatalError(error_code);
123 var f_document = window.frames["feeds-frame"].document;
125 parse_counters(reply, f_document, window);
128 notify("All feeds updated.");
130 exception_error("refetch_callback", e);
136 function backend_sanity_check_callback() {
138 if (xmlhttp.readyState == 4) {
142 if (!xmlhttp.responseXML) {
147 var reply = xmlhttp.responseXML.firstChild;
154 var error_code = reply.getAttribute("error-code");
156 if (error_code && error_code != 0) {
157 return fatalError(error_code);
163 exception_error("backend_sanity_check_callback", e);
168 function scheduleFeedUpdate(force) {
170 notify("Updating feeds, please wait.");
172 // document.title = "Tiny Tiny RSS - Updating...";
174 updateTitle("Updating");
176 var query_str = "backend.php?op=rpc&subop=";
179 query_str = query_str + "forceUpdateAllFeeds";
181 query_str = query_str + "updateAllFeeds";
192 query_str = query_str + "&omode=" + omode;
194 if (xmlhttp_ready(xmlhttp)) {
195 xmlhttp.open("GET", query_str, true);
196 xmlhttp.onreadystatechange=refetch_callback;
203 function updateFeedList(silent, fetch) {
205 // if (silent != true) {
206 // notify("Loading feed list...");
209 var query_str = "backend.php?op=feeds";
212 query_str = query_str + "&tags=1";
215 if (getActiveFeedId()) {
216 query_str = query_str + "&actid=" + getActiveFeedId();
219 if (fetch) query_str = query_str + "&fetch=yes";
221 var feeds_frame = document.getElementById("feeds-frame");
223 feeds_frame.src = query_str;
226 function catchupAllFeeds() {
228 var query_str = "backend.php?op=feeds&subop=catchupAll";
230 notify("Marking all feeds as read...");
232 var feeds_frame = document.getElementById("feeds-frame");
234 feeds_frame.src = query_str;
241 function viewCurrentFeed(skip, subop) {
243 if (getActiveFeedId()) {
244 viewfeed(getActiveFeedId(), skip, subop);
246 disableContainerChildren("headlinesToolbar", false, document);
247 viewfeed(-1, skip, subop); // FIXME
251 function viewfeed(feed, skip, subop) {
252 var f = window.frames["feeds-frame"];
253 f.viewfeed(feed, skip, subop);
257 scheduleFeedUpdate(false);
259 var refresh_time = getCookie('ttrss_vf_refresh');
261 if (!refresh_time) refresh_time = 600;
263 setTimeout("timeout()", refresh_time*1000);
266 function resetSearch() {
267 var searchbox = document.getElementById("searchbox")
269 if (searchbox.value != "" && getActiveFeedId()) {
270 searchbox.value = "";
271 viewfeed(getActiveFeedId(), 0, "");
277 viewCurrentFeed(0, "");
280 function localPiggieFunction(enable) {
282 var query_str = "backend.php?op=feeds&subop=piggie";
284 if (xmlhttp_ready(xmlhttp)) {
286 xmlhttp.open("GET", query_str, true);
287 xmlhttp.onreadystatechange=feedlist_callback;
293 function localHotkeyHandler(keycode) {
295 /* if (keycode == 78) {
296 return moveToPost('next');
300 return moveToPost('prev');
303 if (keycode == 82) { // r
304 return scheduleFeedUpdate(true);
307 if (keycode == 85) { // u
308 if (getActiveFeedId()) {
309 return viewfeed(getActiveFeedId(), 0, "ForceUpdate");
313 if (keycode == 65) { // a
314 return toggleDispRead();
317 var f_doc = window.frames["feeds-frame"].document;
318 var feedlist = f_doc.getElementById('feedList');
320 if (keycode == 74) { // j
321 var feed = getActiveFeedId();
322 var new_feed = getRelativeFeedId(feedlist, feed, 'prev');
323 if (new_feed) viewfeed(new_feed, 0, '');
326 if (keycode == 75) { // k
327 var feed = getActiveFeedId();
328 var new_feed = getRelativeFeedId(feedlist, feed, 'next');
329 if (new_feed) viewfeed(new_feed, 0, '');
332 // notify("KC: " + keycode);
336 // if argument is undefined, current subtitle is not updated
337 // use blank string to clear subtitle
338 function updateTitle(s) {
339 var tmp = "Tiny Tiny RSS";
341 if (s && s.length > 0) {
342 current_subtitle = s;
345 if (global_unread > 0) {
346 tmp = tmp + " (" + global_unread + ")";
350 tmp = tmp + " - " + current_subtitle;
353 if (active_title_text.length > 0) {
354 tmp = tmp + " > " + active_title_text;
357 document.title = tmp;
360 function genericSanityCheck() {
362 if (!xmlhttp) fatalError(1);
364 setCookie("ttrss_vf_test", "TEST");
366 if (getCookie("ttrss_vf_test") != "TEST") {
377 disableContainerChildren("headlinesToolbar", true);
379 if (!genericSanityCheck())
382 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck", true);
383 xmlhttp.onreadystatechange=backend_sanity_check_callback;
387 exception_error("init", e);
391 function init_second_stage() {
395 setCookie("ttrss_vf_actfeed", "");
397 updateFeedList(false, false);
398 document.onkeydown = hotkey_handler;
400 var viewbox = document.getElementById("viewbox");
401 var limitbox = document.getElementById("limitbox");
403 dropboxSelect(viewbox, getCookie("ttrss_vf_vmode"));
404 dropboxSelect(limitbox, getCookie("ttrss_vf_limit"));
407 exception_error("init_second_stage", e);
411 function quickMenuChange() {
412 var chooser = document.getElementById("quickMenuChooser");
413 var opid = chooser[chooser.selectedIndex].id;
415 chooser.selectedIndex = 0;
419 function quickMenuGo(opid) {
422 if (opid == "qmcPrefs") {
426 if (opid == "qmcSearch") {
427 displayDlg("search", getActiveFeedId());
431 if (opid == "qmcAddFeed") {
432 displayDlg("quickAddFeed");
436 if (opid == "qmcRemoveFeed") {
437 var actid = getActiveFeedId();
440 notify("Please select some feed first.");
444 if (confirm("Remove current feed?")) {
451 if (opid == "qmcUpdateFeeds") {
452 scheduleFeedUpdate(true);
456 if (opid == "qmcCatchupAll") {
461 if (opid == "qmcShowOnlyUnread") {
466 if (opid == "qmcAddFilter") {
467 displayDlg("quickAddFilter", getActiveFeedId());
474 if (!xmlhttp_ready(xmlhttp)) {
479 var link = document.getElementById("qafInput");
481 if (link.value.length == 0) {
482 notify("Missing feed URL.");
484 notify("Adding feed...");
486 var cat = document.getElementById("qafCat");
490 cat_id = cat[cat.selectedIndex].id;
495 var feeds_doc = window.frames["feeds-frame"].document;
497 feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
499 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" +
500 param_escape(link.value) + "&cid=" + param_escape(cat_id), true);
501 xmlhttp.onreadystatechange=dlg_frefresh_callback;
509 function qaddFilter() {
511 if (!xmlhttp_ready(xmlhttp)) {
516 var regexp = document.getElementById("fadd_regexp");
517 var match = document.getElementById("fadd_match");
518 var feed = document.getElementById("fadd_feed");
519 var action = document.getElementById("fadd_action");
521 if (regexp.value.length == 0) {
522 notify("Missing filter expression.");
524 notify("Adding filter...");
526 var v_match = match[match.selectedIndex].text;
527 var feed_id = feed[feed.selectedIndex].id;
528 var action_id = action[action.selectedIndex].id;
530 xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" +
531 param_escape(regexp.value) + "&match=" + v_match +
532 "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true);
534 xmlhttp.onreadystatechange=dlg_submit_callback;
543 function displayDlg(id, param) {
545 if (!xmlhttp_ready(xmlhttp)) {
552 xmlhttp.open("GET", "backend.php?op=dlg&id=" +
553 param_escape(id) + "¶m=" + param_escape(param), true);
554 xmlhttp.onreadystatechange=dlg_display_callback;
560 function closeDlg() {
561 var dlg = document.getElementById("userDlgShadow");
562 dlg.style.display = "none";
566 function qfdDelete(feed_id) {
568 notify("Removing feed...");
570 if (!xmlhttp_ready(xmlhttp)) {
575 // var feeds_doc = window.frames["feeds-frame"].document;
576 // feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait...";
578 _qfd_deleted_feed = feed_id;
580 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
581 xmlhttp.onreadystatechange=dlg_frefresh_callback;
586 function allFeedsMenuChange() {
587 var chooser = document.getElementById("allFeedsChooser");
589 var opname = chooser[chooser.selectedIndex].text;
591 chooser.selectedIndex = 0;
593 if (opname == "Update") {
594 scheduleFeedUpdate(true);
598 if (opname == "Mark as read") {
603 if (opname == "Show only unread") {
610 function updateFeedTitle(t) {
611 active_title_text = t;
615 function toggleDispRead() {
618 if (!xmlhttp_ready(xmlhttp)) {
623 var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1);
625 hide_read_feeds = !hide_read_feeds;
627 var query = "backend.php?op=rpc&subop=setpref" +
628 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
630 xmlhttp.open("GET", query);
631 xmlhttp.onreadystatechange=hide_unread_callback;
635 exception_error("toggleDispRead", e);