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() {
31 display_tags = !display_tags;
33 var p = document.getElementById("dispSwitchPrompt");
36 p.innerHTML = __("display feeds");
38 p.innerHTML = __("display tags");
41 notify_progress("Loading, please wait...");
46 function dlg_frefresh_callback() {
47 if (xmlhttp.readyState == 4) {
48 // notify(xmlhttp.responseText);
50 if (getActiveFeedId() == _qfd_deleted_feed) {
51 var h = document.getElementById("headlines-frame");
53 h.innerHTML = "<div class='whiteBox'>No feed selected.</div>";
57 setTimeout('updateFeedList(false, false)', 50);
62 function refetch_callback() {
63 if (xmlhttp_ctr.readyState == 4) {
66 var date = new Date();
68 last_refetch = date.getTime() / 1000;
70 parse_counters_reply(xmlhttp_ctr, true);
72 debug("refetch_callback: done");
74 if (!daemon_enabled && !daemon_refresh_only) {
75 notify_info("All feeds updated.");
81 exception_error("refetch_callback", e);
87 function backend_sanity_check_callback() {
89 if (xmlhttp.readyState == 4) {
93 if (sanity_check_done) {
94 fatalError(11, "Sanity check request received twice. This can indicate "+
95 "presence of Firebug or some other disrupting extension. "+
96 "Please disable it and try again.");
100 if (!xmlhttp.responseXML) {
101 fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText);
105 var reply = xmlhttp.responseXML.firstChild.firstChild;
108 fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText);
112 var error_code = reply.getAttribute("error-code");
114 if (error_code && error_code != 0) {
115 return fatalError(error_code, reply.getAttribute("error-msg"));
118 debug("sanity check ok");
120 var params = reply.nextSibling;
123 debug('reading init-params...');
124 var param = params.firstChild;
127 var k = param.getAttribute("key");
128 var v = param.getAttribute("value");
129 debug(k + " => " + v);
131 param = param.nextSibling;
135 sanity_check_done = true;
140 exception_error("backend_sanity_check_callback", e);
145 function scheduleFeedUpdate(force) {
147 if (!daemon_enabled && !daemon_refresh_only) {
148 notify_progress("Updating feeds, please wait.", true);
149 updateTitle("Updating");
152 var query_str = "backend.php?op=rpc&subop=";
155 query_str = query_str + "forceUpdateAllFeeds";
157 query_str = query_str + "updateAllFeeds";
162 if (firsttime_update && !navigator.userAgent.match("Opera")) {
163 firsttime_update = false;
173 query_str = query_str + "&omode=" + omode;
174 query_str = query_str + "&uctr=" + global_unread;
176 debug("in scheduleFeedUpdate");
178 var date = new Date();
180 var timestamp = Math.round(date.getTime() / 1000);
181 query_str = query_str + "&ts=" + timestamp
183 if (!xmlhttp_ready(xmlhttp_ctr) && last_refetch < date.getTime() / 1000 - 60) {
184 debug("<b>xmlhttp seems to be stuck, aborting</b>");
188 debug("REFETCH query: " + query_str);
190 if (xmlhttp_ready(xmlhttp_ctr)) {
191 xmlhttp_ctr.open("GET", query_str, true);
192 xmlhttp_ctr.onreadystatechange=refetch_callback;
193 xmlhttp_ctr.send(null);
195 debug("xmlhttp_ctr busy");
196 //printLockingError();
200 function updateFeedList(silent, fetch) {
202 // if (silent != true) {
203 // notify("Loading feed list...");
206 debug("<b>updateFeedList</b>");
208 var query_str = "backend.php?op=feeds";
211 query_str = query_str + "&tags=1";
214 if (getActiveFeedId() && !activeFeedIsCat()) {
215 query_str = query_str + "&actid=" + getActiveFeedId();
218 var date = new Date();
219 var timestamp = Math.round(date.getTime() / 1000);
220 query_str = query_str + "&ts=" + timestamp
222 if (fetch) query_str = query_str + "&fetch=yes";
224 // var feeds_frame = document.getElementById("feeds-frame");
225 // feeds_frame.src = query_str;
227 debug("updateFeedList Q=" + query_str);
229 if (xmlhttp_ready(xmlhttp)) {
230 xmlhttp.open("GET", query_str, true);
231 xmlhttp.onreadystatechange=feedlist_callback;
234 debug("xmlhttp busy");
235 //printLockingError();
240 function catchupAllFeeds() {
242 var query_str = "backend.php?op=feeds&subop=catchupAll";
244 notify_progress("Marking all feeds as read...");
246 debug("catchupAllFeeds Q=" + query_str);
248 if (xmlhttp_ready(xmlhttp)) {
249 xmlhttp.open("GET", query_str, true);
250 xmlhttp.onreadystatechange=feedlist_callback;
253 debug("xmlhttp busy");
254 //printLockingError();
262 function viewCurrentFeed(subop) {
264 // if (getActiveFeedId()) {
265 if (getActiveFeedId() != undefined) {
266 viewfeed(getActiveFeedId(), subop);
268 disableContainerChildren("headlinesToolbar", false, document);
269 // viewfeed(-1, subop); // FIXME
271 return false; // block unneeded form submits
274 function viewfeed(feed, subop) {
275 var f = window.frames["feeds-frame"];
276 f.viewfeed(feed, subop);
280 scheduleFeedUpdate(false);
282 var refresh_time = getInitParam("feeds_frame_refresh");
284 if (!refresh_time) refresh_time = 600;
286 setTimeout("timeout()", refresh_time*1000);
289 function resetSearch() {
290 var searchbox = document.getElementById("searchbox")
292 if (searchbox.value != "" && getActiveFeedId()) {
293 searchbox.value = "";
294 viewfeed(getActiveFeedId(), "");
298 function searchCancel() {
304 viewCurrentFeed(0, "");
307 function localPiggieFunction(enable) {
309 var query_str = "backend.php?op=feeds&subop=piggie";
311 if (xmlhttp_ready(xmlhttp)) {
313 xmlhttp.open("GET", query_str, true);
314 xmlhttp.onreadystatechange=feedlist_callback;
320 // if argument is undefined, current subtitle is not updated
321 // use blank string to clear subtitle
322 function updateTitle(s) {
323 var tmp = "Tiny Tiny RSS";
325 if (s != undefined) {
326 current_subtitle = s;
329 if (global_unread > 0) {
330 tmp = tmp + " (" + global_unread + ")";
333 if (current_subtitle) {
334 tmp = tmp + " - " + current_subtitle;
337 if (active_title_text.length > 0) {
338 tmp = tmp + " > " + active_title_text;
341 document.title = tmp;
344 function genericSanityCheck() {
346 if (!xmlhttp) fatalError(1);
348 setCookie("ttrss_vf_test", "TEST");
350 if (getCookie("ttrss_vf_test") != "TEST") {
361 // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html
363 if (arguments.callee.done) return;
364 arguments.callee.done = true;
366 disableContainerChildren("headlinesToolbar", true);
368 Form.disable("main_toolbar_form");
370 if (!genericSanityCheck())
373 if (getURLParam('debug')) {
374 document.getElementById('debug_output').style.display = 'block';
375 debug('debug mode activated');
378 var params = "&ua=" + param_escape(navigator.userAgent);
380 xmlhttp.open("GET", "backend.php?op=rpc&subop=sanityCheck" + params, true);
381 xmlhttp.onreadystatechange=backend_sanity_check_callback;
385 exception_error("init", e);
389 function resize_headlines() {
391 var h_frame = document.getElementById("headlines-frame");
392 var c_frame = document.getElementById("content-frame");
393 var f_frame = document.getElementById("footer");
395 if (!c_frame || !h_frame) return;
397 debug("resize_headlines");
400 h_frame.style.height = 30 + "%";
401 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
402 h_frame.style.height = h_frame.offsetHeight + "px";
404 h_frame.style.height = document.documentElement.clientHeight * 0.3 + "px";
405 c_frame.style.top = h_frame.offsetTop + h_frame.offsetHeight + 1 + "px";
407 var c_bottom = document.documentElement.clientHeight;
410 c_bottom = f_frame.offsetTop;
413 c_frame.style.height = c_bottom - (h_frame.offsetTop +
414 h_frame.offsetHeight + 1) + "px";
415 h_frame.style.height = h_frame.offsetHeight + "px";
420 function init_second_stage() {
424 cookie_lifetime = getCookie("ttrss_cltime");
426 delCookie("ttrss_vf_test");
428 // document.onresize = resize_headlines;
431 var toolbar = document.forms["main_toolbar_form"];
433 dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode"));
434 dropboxSelect(toolbar.limit, getInitParam("default_view_limit"));
436 daemon_enabled = getInitParam("daemon_enabled") == 1;
437 daemon_refresh_only = getInitParam("daemon_refresh_only") == 1;
439 setTimeout('updateFeedList(false, false)', 50);
441 debug("second stage ok");
444 exception_error("init_second_stage", e);
448 function quickMenuChange() {
449 var chooser = document.getElementById("quickMenuChooser");
450 var opid = chooser[chooser.selectedIndex].value;
452 chooser.selectedIndex = 0;
456 function quickMenuGo(opid) {
459 if (opid == "qmcPrefs") {
463 if (opid == "qmcSearch") {
464 displayDlg("search", getActiveFeedId() + ":" + activeFeedIsCat());
468 if (opid == "qmcAddFeed") {
469 displayDlg("quickAddFeed");
473 if (opid == "qmcEditFeed") {
474 editFeedDlg(getActiveFeedId());
477 if (opid == "qmcRemoveFeed") {
478 var actid = getActiveFeedId();
480 if (!actid || activeFeedIsCat()) {
481 alert("Please select some feed first.");
485 var fn = getFeedName(actid);
487 if (confirm("Unsubscribe from " + fn + "?")) {
494 if (opid == "qmcUpdateFeeds") {
495 scheduleFeedUpdate(true);
499 if (opid == "qmcCatchupAll") {
504 if (opid == "qmcShowOnlyUnread") {
509 if (opid == "qmcAddFilter") {
510 displayDlg("quickAddFilter", getActiveFeedId());
513 exception_error("quickMenuGo", e);
517 function qfdDelete(feed_id) {
519 notify_progress("Removing feed...");
521 if (!xmlhttp_ready(xmlhttp)) {
526 _qfd_deleted_feed = feed_id;
528 xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id);
529 xmlhttp.onreadystatechange=dlg_frefresh_callback;
536 function updateFeedTitle(t) {
537 active_title_text = t;
541 function toggleDispRead() {
544 if (!xmlhttp_ready(xmlhttp)) {
549 var hide_read_feeds = (getInitParam("hide_read_feeds") == "1");
551 hide_read_feeds = !hide_read_feeds;
553 debug("toggle_disp_read => " + hide_read_feeds);
555 hideOrShowFeeds(getFeedsContext().document, hide_read_feeds);
557 storeInitParam("hide_read_feeds", hide_read_feeds, true);
559 /* var query = "backend.php?op=rpc&subop=setpref" +
560 "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds);
562 new Ajax.Request(query); */
565 exception_error("toggleDispRead", e);
569 function parse_runtime_info(elem) {
571 debug("parse_runtime_info: elem is null, aborting");
575 var param = elem.firstChild;
577 debug("parse_runtime_info: " + param);
580 var k = param.getAttribute("key");
581 var v = param.getAttribute("value");
583 debug("RI: " + k + " => " + v);
585 if (k == "new_version_available") {
586 var icon = document.getElementById("newVersionIcon");
589 icon.style.display = "inline";
591 icon.style.display = "none";
596 if (k == "daemon_is_running" && v != 1) {
597 notify_error("<span onclick=\"javascript:explainError(1)\">Update daemon is not runing.</span>");
600 /* var w = document.getElementById("noDaemonWarning");
603 if (k == "daemon_is_running" && v != 1) {
604 w.style.display = "block";
606 w.style.display = "none";
609 param = param.nextSibling;
613 function catchupCurrentFeed() {
615 var fn = getFeedName(getActiveFeedId(), active_feed_is_cat);
617 var str = "Mark all articles in " + fn + " as read?";
619 /* if (active_feed_is_cat) {
620 str = "Mark all articles in this category as read?";
623 if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) {
624 return viewCurrentFeed('MarkAllRead')
628 function userSwitch() {
629 var chooser = document.getElementById("userSwitch");
630 var user = chooser[chooser.selectedIndex].value;
631 window.location = "tt-rss.php?swu=" + user;
634 function editFeedDlg(feed) {
639 alert("Please select some feed first.");
643 if (feed <= 0 || active_feed_is_cat || tagsAreDisplayed()) {
644 alert("You can't edit this kind of feed.");
648 if (xmlhttp_ready(xmlhttp)) {
649 xmlhttp.open("GET", "backend.php?op=pref-feeds&subop=editfeed&id=" +
650 param_escape(feed), true);
651 xmlhttp.onreadystatechange=infobox_callback;
658 /* this functions duplicate those of prefs.js feed editor, with
659 some differences because there is no feedlist */
661 function feedEditCancel() {
666 function feedEditSave() {
670 if (!xmlhttp_ready(xmlhttp)) {
675 // FIXME: add parameter validation
677 var query = Form.serialize("edit_feed_form");
679 notify_progress("Saving feed...");
681 xmlhttp.open("POST", "backend.php", true);
682 xmlhttp.onreadystatechange=dlg_frefresh_callback;
683 xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
691 exception_error("feedEditSave (main)", e);
695 function localHotkeyHandler(e) {
700 keycode = window.event.keyCode;
705 var shift_key = false;
708 shift_key = e.shiftKey;
711 if (keycode == 66 && shift_key) { // shift-B
713 var op = history_pop();
716 var op_s = op.split(":");
719 for (i = 0; i < op_s.length; i++) {
720 if (op_s[i] == 'undefined') {
724 if (op_s[i] == 'false') {
728 if (op_s[i] == 'true') {
734 debug("history split: " + op_s);
736 if (op_s[0] == "ARTICLE") {
737 debug("history: reverting to article " + op_s[1] + "/" + op_s[2]);
738 view(op_s[1], op_s[2], true);
741 if (op_s[0] == "FEED") {
742 viewfeed(op_s[1], op_s[2], op_s[3], op_s[4], true);
746 notify_error("No operation to undo");
753 debug("LKP=" + keycode);
756 function history_push(op) {
757 debug("history_push: " + op);
760 while (op_history.length > 30) {
765 function history_pop() {
766 var op = op_history.pop();
767 debug("history_pop: " + op);
771 function history_clear() {
772 debug("history_clear");