4 var display_tags = false;
5 var global_unread = -1;
6 var active_title_text = "";
7 var current_subtitle = "";
8 var daemon_enabled = false;
9 var daemon_refresh_only = false;
10 var _qfd_deleted_feed = 0;
11 var firsttime_update = true;
13 var cookie_lifetime = 0;
14 var active_feed_id = 0;
15 var active_feed_is_cat = false;
16 var number_of_feeds = 0;
17 var sanity_check_done = false;
19 var xmlhttp = Ajax.getTransport();
20 var xmlhttp_ctr = Ajax.getTransport();
22 var init_params = new Object();
24 //var op_history = new Array();
26 function tagsAreDisplayed() {
30 function toggleTags(show_all) {
32 var p = document.getElementById("dispSwitchPrompt");
34 if (!show_all && !display_tags) {
35 displayDlg("printTagCloud");
36 } else if (show_all) {
39 p.innerHTML = __("display feeds");
40 notify_progress("Loading, please wait...");
42 } else if (display_tags) {
44 p.innerHTML = __("tag cloud");
45 notify_progress("Loading, please wait...");
52 function dlg_frefresh_callback() {
53 if (xmlhttp.readyState == 4) {
54 // notify(xmlhttp.responseText);
56 if (getActiveFeedId() == _qfd_deleted_feed) {
57 var h = document.getElementById("headlines-frame");
59 h.innerHTML = "<div class='whiteBox'>" + __('No feed selected.') + "</div>";
63 setTimeout('updateFeedList(false, false)', 50);
68 function refetch_callback() {
69 if (xmlhttp_ctr.readyState == 4) {
72 var date = new Date();
74 last_refetch = date.getTime() / 1000;
76 parse_counters_reply(xmlhttp_ctr, true);
78 debug("refetch_callback: done");
80 if (!daemon_enabled && !daemon_refresh_only) {
81 notify_info("All feeds updated.");
87 exception_error("refetch_callback", e);
93 function backend_sanity_check_callback() {
95 if (xmlhttp.readyState == 4) {
99 if (sanity_check_done) {
100 fatalError(11, "Sanity check request received twice. This can indicate "+
101 "presence of Firebug or some other disrupting extension. "+
102 "Please disable it and try again.");
106 if (!xmlhttp.responseXML) {
107 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
111 var reply = xmlhttp.responseXML.firstChild.firstChild;
114 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
118 var error_code = reply.getAttribute("error-code");
120 if (error_code && error_code != 0) {
121 return fatalError(error_code, reply.getAttribute("error-msg"));
124 debug("sanity check ok");
126 var params = reply.nextSibling;
129 debug('reading init-params...');
130 var param = params.firstChild;
133 var k = param.getAttribute("key");
134 var v = param.getAttribute("value");
135 debug(k + " => " + v);
137 param = param.nextSibling;
141 sanity_check_done = true;
146 exception_error("backend_sanity_check_callback", e);
151 function scheduleFeedUpdate(force) {
153 if (!daemon_enabled && !daemon_refresh_only) {
154 notify_progress("Updating feeds, please wait.", true);
155 updateTitle("Updating");
158 var query_str = "backend.php?op=rpc&subop=";
161 query_str = query_str + "forceUpdateAllFeeds";
163 query_str = query_str + "updateAllFeeds";
168 if (firsttime_update && !navigator.userAgent.match("Opera")) {
169 firsttime_update = false;
179 query_str = query_str + "&omode=" + omode;
180 query_str = query_str + "&uctr=" + global_unread;
182 debug("in scheduleFeedUpdate");
184 var date = new Date();
186 var timestamp = Math.round(date.getTime() / 1000);
187 query_str = query_str + "&ts=" + timestamp
189 if (!xmlhttp_ready(xmlhttp_ctr) && last_refetch < date.getTime() / 1000 - 60) {
190 debug("<b>xmlhttp seems to be stuck, aborting</b>");
194 debug("REFETCH query: " + query_str);
196 if (xmlhttp_ready(xmlhttp_ctr)) {
197 xmlhttp_ctr.open("GET", query_str, true);
198 xmlhttp_ctr.onreadystatechange=refetch_callback;
199 xmlhttp_ctr.send(null);
201 debug("xmlhttp_ctr busy");
202 //printLockingError();
206 function updateFeedList(silent, fetch) {
208 // if (silent != true) {
209 // notify("Loading feed list...");
212 debug("<b>updateFeedList</b>");
214 var query_str = "backend.php?op=feeds";
217 query_str = query_str + "&tags=1";
220 if (getActiveFeedId() && !activeFeedIsCat()) {
221 query_str = query_str + "&actid=" + getActiveFeedId();
224 var date = new Date();
225 var timestamp = Math.round(date.getTime() / 1000);
226 query_str = query_str + "&ts=" + timestamp
228 if (fetch) query_str = query_str + "&fetch=yes";
230 // var feeds_frame = document.getElementById("feeds-frame");
231 // feeds_frame.src = query_str;
233 debug("updateFeedList Q=" + query_str);
235 if (xmlhttp_ready(xmlhttp)) {
236 xmlhttp.open("GET", query_str, true);
237 xmlhttp.onreadystatechange=feedlist_callback;
240 debug("xmlhttp busy");
241 //printLockingError();
246 function catchupAllFeeds() {
248 var query_str = "backend.php?op=feeds&subop=catchupAll";
250 notify_progress("Marking all feeds as read...");
252 debug("catchupAllFeeds Q=" + query_str);
254 if (xmlhttp_ready(xmlhttp)) {
255 xmlhttp.open("GET", query_str, true);
256 xmlhttp.onreadystatechange=feedlist_callback;
259 debug("xmlhttp busy");
260 //printLockingError();
268 function viewCurrentFeed(subop) {
270 // if (getActiveFeedId()) {
271 if (getActiveFeedId() != undefined) {
272 viewfeed(getActiveFeedId(), subop);
274 disableContainerChildren("headlinesToolbar", false, document);
275 // viewfeed(-1, subop); // FIXME
277 return false; // block unneeded form submits
280 function viewfeed(feed, subop) {
281 var f = window.frames["feeds-frame"];
282 f.viewfeed(feed, subop);
286 scheduleFeedUpdate(false);
288 var refresh_time = getInitParam("feeds_frame_refresh");
290 if (!refresh_time) refresh_time = 600;
292 setTimeout("timeout()", refresh_time*1000);
295 function resetSearch() {
296 var searchbox = document.getElementById("searchbox")
298 if (searchbox.value != "" && getActiveFeedId()) {
299 searchbox.value = "";
300 viewfeed(getActiveFeedId(), "");
304 function searchCancel() {
310 viewCurrentFeed(0, "");
313 function localPiggieFunction(enable) {
315 var query_str = "backend.php?op=feeds&subop=piggie";
317 if (xmlhttp_ready(xmlhttp)) {
319 xmlhttp.open("GET", query_str, true);
320 xmlhttp.onreadystatechange=feedlist_callback;
326 // if argument is undefined, current subtitle is not updated
327 // use blank string to clear subtitle
328 function updateTitle(s) {
329 var tmp = "Tiny Tiny RSS";
331 if (s != undefined) {
332 current_subtitle = s;
335 if (global_unread > 0) {
336 tmp = tmp + " (" + global_unread + ")";
339 if (current_subtitle) {
340 tmp = tmp + " - " + current_subtitle;
343 if (active_title_text.length > 0) {
344 tmp = tmp + " > " + active_title_text;
347 document.title = tmp;
350 function genericSanityCheck() {
352 if (!xmlhttp) fatalError(1);
354 setCookie("ttrss_vf_test", "TEST");
356 if (getCookie("ttrss_vf_test") != "TEST") {
367 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
369 if (arguments.callee.done) return;
370 arguments.callee.done = true;
372 disableContainerChildren("headlinesToolbar", true);
374 Form.disable("main_toolbar_form");
376 if (!genericSanityCheck())
379 if (getURLParam('debug')) {
380 document.getElementById('debug_output').style.display = 'block';
381 debug('debug mode activated');
384 var params = "&ua=" + param_escape(navigator.userAgent);
386 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params, true);
387 xmlhttp.onreadystatechange=backend_sanity_check_callback;
391 exception_error("init", e);
395 function resize_headlines() {
397 var h_frame = document.getElementById("headlines-frame");
398 var c_frame = document.getElementById("content-frame");
399 var f_frame = document.getElementById("footer");
401 if (!c_frame || !h_frame) return;
403 debug("resize_headlines");
406 h_frame.style.height = 30 + "%";
407 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
408 h_frame.style.height = h_frame.offsetHeight + "px";
410 h_frame.style.height = document.documentElement.clientHeight * 0.3 + "px";
411 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
413 var c_bottom = document.documentElement.clientHeight;
416 c_bottom = f_frame.offsetTop;
419 c_frame.style.height = c_bottom - (h_frame.offsetTop +
420 h_frame.offsetHeight + 1) + "px";
421 h_frame.style.height = h_frame.offsetHeight + "px";
426 function init_second_stage() {
430 cookie_lifetime = getCookie("ttrss_cltime");
432 delCookie("ttrss_vf_test");
434 // document.onresize = resize_headlines;
437 var toolbar = document.forms["main_toolbar_form"];
439 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
440 dropboxSelect(toolbar.limit, getInitParam("default_view_limit"));
442 daemon_enabled = getInitParam("daemon_enabled") == 1;
443 daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
445 setTimeout('updateFeedList(false, false)', 50);
447 debug("second stage ok");
450 exception_error("init_second_stage", e);
454 function quickMenuChange() {
455 var chooser = document.getElementById("quickMenuChooser");
456 var opid = chooser[chooser.selectedIndex].value;
458 chooser.selectedIndex = 0;
462 function quickMenuGo(opid) {
465 if (opid == "qmcPrefs") {
469 if (opid == "qmcSearch") {
470 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
474 if (opid == "qmcAddFeed") {
475 displayDlg("quickAddFeed");
479 if (opid == "qmcEditFeed") {
480 editFeedDlg(getActiveFeedId());
483 if (opid == "qmcRemoveFeed") {
484 var actid = getActiveFeedId();
486 if (activeFeedIsCat()) {
487 alert("You can't unsubscribe from the category.");
492 alert("Please select some feed first.");
496 var fn = getFeedName(actid);
498 if (confirm("Unsubscribe from " + fn + "?")) {
505 if (opid == "qmcUpdateFeeds") {
506 scheduleFeedUpdate(true);
510 if (opid == "qmcCatchupAll") {
515 if (opid == "qmcShowOnlyUnread") {
520 if (opid == "qmcAddFilter") {
521 displayDlg("quickAddFilter", getActiveFeedId());
525 exception_error("quickMenuGo", e);
529 function qfdDelete(feed_id) {
531 notify_progress("Removing feed...");
533 if (!xmlhttp_ready(xmlhttp)) {
538 _qfd_deleted_feed = feed_id;
540 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
541 xmlhttp.onreadystatechange=dlg_frefresh_callback;
548 function updateFeedTitle(t) {
549 active_title_text = t;
553 function toggleDispRead() {
556 if (!xmlhttp_ready(xmlhttp)) {
561 var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
563 hide_read_feeds = !hide_read_feeds;
565 debug("toggle_disp_read => " + hide_read_feeds);
567 hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
569 storeInitParam("hide_read_feeds", hide_read_feeds, true);
571 /* var query = "backend.php?op=rpc&subop=setpref" +
572 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
574 new Ajax.Request(query); */
577 exception_error("toggleDispRead", e);
581 function parse_runtime_info(elem) {
583 debug("parse_runtime_info: elem is null, aborting");
587 var param = elem.firstChild;
589 debug("parse_runtime_info: " + param);
592 var k = param.getAttribute("key");
593 var v = param.getAttribute("value");
595 debug("RI: " + k + " => " + v);
597 if (k == "new_version_available") {
598 var icon = document.getElementById("newVersionIcon");
601 icon.style.display = "inline";
603 icon.style.display = "none";
608 if (k == "daemon_is_running" && v != 1) {
609 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not runing.</span>");
612 /* var w = document.getElementById("noDaemonWarning");
615 if (k == "daemon_is_running" && v != 1) {
616 w.style.display = "block";
618 w.style.display = "none";
621 param = param.nextSibling;
625 function catchupCurrentFeed() {
627 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
629 var str = "Mark all articles in " + fn + " as read?";
631 /* if (active_feed_is_cat) {
632 str = "Mark all articles in this category as read?";
635 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
636 return viewCurrentFeed('MarkAllRead')
640 function userSwitch() {
641 var chooser = document.getElementById("userSwitch");
642 var user = chooser[chooser.selectedIndex].value;
643 window.location = "tt-rss.php?swu=" + user;
646 function editFeedDlg(feed) {
651 alert("Please select some feed first.");
655 if (feed <= 0 || activeFeedIsCat() || tagsAreDisplayed()) {
656 alert("You can't edit this kind of feed.");
660 if (xmlhttp_ready(xmlhttp)) {
661 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
662 param_escape(feed), true);
663 xmlhttp.onreadystatechange=infobox_callback;
670 /* this functions duplicate those of prefs.js feed editor, with
671 some differences because there is no feedlist */
673 function feedEditCancel() {
678 function feedEditSave() {
682 if (!xmlhttp_ready(xmlhttp)) {
687 // FIXME: add parameter validation
689 var query = Form.serialize("edit_feed_form");
691 notify_progress("Saving feed...");
693 xmlhttp.open("POST", "backend.php", true);
694 xmlhttp.onreadystatechange=dlg_frefresh_callback;
695 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
703 exception_error("feedEditSave (main)", e);
707 function localHotkeyHandler(e) {
712 keycode = window.event.keyCode;
717 var shift_key = false;
720 shift_key = e.shiftKey;
723 if (keycode == 66 && shift_key) { // shift-B
725 var op = history_pop();
728 var op_s = op.split(":");
731 for (i = 0; i < op_s.length; i++) {
732 if (op_s[i] == 'undefined') {
736 if (op_s[i] == 'false') {
740 if (op_s[i] == 'true') {
746 debug("history split: " + op_s);
748 if (op_s[0] == "ARTICLE") {
749 debug("history: reverting to article " + op_s[1] + "/" + op_s[2]);
750 view(op_s[1], op_s[2], true);
753 if (op_s[0] == "FEED") {
754 viewfeed(op_s[1], op_s[2], op_s[3], op_s[4], true);
758 notify_error("No operation to undo");
765 debug("LKP=" + keycode);
768 function history_push(op) {
769 debug("history_push: " + op);
772 while (op_history.length > 30) {
777 function history_pop() {
778 var op = op_history.pop();
779 debug("history_pop: " + op);
783 function history_clear() {
784 debug("history_clear");