X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=tt-rss.js;h=7167d058410a217c68593802bbb743466b194ccb;hb=e8614131e893af473e0a585addb19d9f4e8b8973;hp=06f9fadc0cd1c0dafcd78e58be12d2cc85b3bf2f;hpb=bb3423cf99b7bcb39e6737ae782e01df3136236c;p=tt-rss.git diff --git a/tt-rss.js b/tt-rss.js index 06f9fadc..7167d058 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -10,25 +10,11 @@ var _qfd_deleted_feed = 0; var firsttime_update = true; var last_refetch = 0; var cookie_lifetime = 0; +var active_feed_id = 0; -/*@cc_on @*/ -/*@if (@_jscript_version >= 5) -// JScript gives us Conditional compilation, we can cope with old IE versions. -// and security blocked creation of the objects. -try { - xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); -} catch (e) { - try { - xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); - } catch (E) { - xmlhttp = false; - } -} -@end @*/ +var xmlhttp = Ajax.getTransport(); -if (!xmlhttp && typeof XMLHttpRequest!='undefined') { - xmlhttp = new XMLHttpRequest(); -} +var init_params = new Object(); function toggleTags() { display_tags = !display_tags; @@ -54,49 +40,7 @@ function dlg_frefresh_callback() { hframe.src = "backend.php?op=error&msg=No%20feed%20selected."; } } - closeDlg(); - } -} - -function dlg_submit_callback() { - if (xmlhttp.readyState == 4) { - notify(xmlhttp.responseText); - closeDlg(); - } -} - -function dlg_display_callback() { - if (xmlhttp.readyState == 4) { - var dlg = document.getElementById("userDlg"); - var dlg_s = document.getElementById("userDlgShadow"); - - dlg.innerHTML = xmlhttp.responseText; - dlg_s.style.display = "block"; - } -} - -function hide_unread_callback() { - if (xmlhttp.readyState == 4) { - - try { - - var reply = xmlhttp.responseXML.firstChild.firstChild; - var value = reply.getAttribute("value"); - var hide_read_feeds = (value != "false") - var feeds_doc = window.frames["feeds-frame"].document; - - hideOrShowFeeds(feeds_doc, hide_read_feeds); - - if (hide_read_feeds) { - setCookie("ttrss_vf_hreadf", 1); - } else { - setCookie("ttrss_vf_hreadf", 0); - } - - } catch (e) { - exception_error("hide_unread_callback", e); - } - + closeInfoBox(); } } @@ -109,14 +53,14 @@ function refetch_callback() { last_refetch = date.getTime() / 1000; if (!xmlhttp.responseXML) { - notify("refetch_callback: backend did not return valid XML"); + notify("refetch_callback: backend did not return valid XML", true, true); return; } var reply = xmlhttp.responseXML.firstChild; if (!reply) { - notify("refetch_callback: backend did not return expected XML object"); + notify("refetch_callback: backend did not return expected XML object", true, true); updateTitle(""); return; } @@ -124,12 +68,16 @@ function refetch_callback() { var error_code = reply.getAttribute("error-code"); if (error_code && error_code != 0) { - return fatalError(error_code); + return fatalError(error_code, reply.getAttribute("error-msg")); } + + var counters = reply.firstChild; - var f_document = window.frames["feeds-frame"].document; + parse_counters(counters, true); + + var runtime_info = counters.nextSibling; - parse_counters(reply, f_document, window, true); + parse_runtime_info(runtime_info); debug("refetch_callback: done"); @@ -153,25 +101,40 @@ function backend_sanity_check_callback() { try { if (!xmlhttp.responseXML) { - fatalError(3, "D001: " + xmlhttp.responseText); + fatalError(3, "[D001, Received reply is not XML]: " + xmlhttp.responseText); return; } - var reply = xmlhttp.responseXML.firstChild; + var reply = xmlhttp.responseXML.firstChild.firstChild; if (!reply) { - fatalError(3, "D002: " + xmlhttp.responseText); + fatalError(3, "[D002, Invalid RPC reply]: " + xmlhttp.responseText); return; } var error_code = reply.getAttribute("error-code"); if (error_code && error_code != 0) { - return fatalError(error_code); + return fatalError(error_code, reply.getAttribute("error-msg")); } debug("sanity check ok"); + var params = reply.nextSibling; + + if (params) { + debug('reading init-params...'); + var param = params.firstChild; + + while (param) { + var k = param.getAttribute("key"); + var v = param.getAttribute("value"); + debug(k + " => " + v); + init_params[k] = v; + param = param.nextSibling; + } + } + init_second_stage(); } catch (e) { @@ -183,7 +146,7 @@ function backend_sanity_check_callback() { function scheduleFeedUpdate(force) { if (!daemon_enabled) { - notify("Updating feeds, please wait."); + notify("Updating feeds, please wait.", true); updateTitle("Updating"); } @@ -216,7 +179,7 @@ function scheduleFeedUpdate(force) { var date = new Date(); if (!xmlhttp_ready(xmlhttp) && last_refetch < date.getTime() / 1000 - 60) { - debug("xmlhttp seems to be stuck, aborting"); + debug("xmlhttp seems to be stuck, aborting"); xmlhttp.abort(); } @@ -282,6 +245,7 @@ function viewCurrentFeed(skip, subop) { disableContainerChildren("headlinesToolbar", false, document); viewfeed(-1, skip, subop); // FIXME } + return false; // block unneeded form submits } function viewfeed(feed, skip, subop) { @@ -292,9 +256,9 @@ function viewfeed(feed, skip, subop) { function timeout() { scheduleFeedUpdate(false); - var refresh_time = getCookie('ttrss_vf_refresh'); + var refresh_time = getInitParam("feeds_frame_refresh"); - if (!refresh_time) refresh_time = 600; + if (!refresh_time) refresh_time = 600; setTimeout("timeout()", refresh_time*1000); } @@ -308,8 +272,12 @@ function resetSearch() { } } +function searchCancel() { + closeInfoBox(true); +} + function search() { - closeDlg(); + closeInfoBox(); viewCurrentFeed(0, ""); } @@ -326,41 +294,6 @@ function localPiggieFunction(enable) { } } -function localHotkeyHandler(keycode) { - - if (keycode == 82) { // r - return scheduleFeedUpdate(true); - } - - if (keycode == 85) { // u - if (getActiveFeedId()) { - return viewfeed(getActiveFeedId(), 0, "ForceUpdate"); - } - } - - if (keycode == 65) { // a - return toggleDispRead(); - } - - var f_doc = window.frames["feeds-frame"].document; - var feedlist = f_doc.getElementById('feedList'); - - if (keycode == 74) { // j - var feed = getActiveFeedId(); - var new_feed = getRelativeFeedId(feedlist, feed, 'prev'); - if (new_feed) viewfeed(new_feed, 0, ''); - } - - if (keycode == 75) { // k - var feed = getActiveFeedId(); - var new_feed = getRelativeFeedId(feedlist, feed, 'next'); - if (new_feed) viewfeed(new_feed, 0, ''); - } - -// notify("KC: " + keycode); - -} - // if argument is undefined, current subtitle is not updated // use blank string to clear subtitle function updateTitle(s) { @@ -409,6 +342,8 @@ function init() { disableContainerChildren("headlinesToolbar", true); + Form.disable("main_toolbar_form"); + if (!genericSanityCheck()) return; @@ -430,9 +365,20 @@ function resize_feeds_frame() { var f = document.getElementById("feeds-frame"); var tf = document.getElementById("mainFooter"); var th = document.getElementById("mainHeader"); - - f.style.height = document.body.scrollHeight - tf.scrollHeight - - th.scrollHeight - 50 + "px"; + + var footer_height = 0; + var header_height = 0; + + if (tf) { + footer_height = tf.scrollHeight; + } + + if (th) { + header_height = th.scrollHeight; + } + + f.style.height = document.body.scrollHeight - footer_height - + header_height - 50 + "px"; } function init_second_stage() { @@ -442,33 +388,24 @@ function init_second_stage() { cookie_lifetime = getCookie("ttrss_cltime"); delCookie("ttrss_vf_test"); - - setCookie("ttrss_vf_actfeed", ""); updateFeedList(false, false); document.onkeydown = hotkey_handler; - - var viewbox = document.getElementById("viewbox"); - var limitbox = document.getElementById("limitbox"); - dropboxSelect(viewbox, getCookie("ttrss_vf_vmode")); - dropboxSelect(limitbox, getCookie("ttrss_vf_limit")); + var tb = parent.document.forms["main_toolbar_form"]; - daemon_enabled = getCookie("ttrss_vf_daemon"); + dropboxSelect(tb.view_mode, getInitParam("toolbar_view_mode")); + dropboxSelect(tb.limit, getInitParam("toolbar_limit")); + + daemon_enabled = getInitParam("daemon_enabled"); // FIXME should be callled after window resize + var h = document.getElementById("headlines"); + var c = document.getElementById("content"); + if (navigator.userAgent.match("Opera")) { resize_feeds_frame(); - -/* // fix headlines frame height for Opera - var h = document.getElementById("headlines"); - var c = document.getElementById("content"); - var nh = document.body.scrollHeight * 0.25; - - h.style.height = nh + "px"; - c.style.height = c.scrollHeight - nh + "px"; */ - } debug("second stage ok"); @@ -480,7 +417,7 @@ function init_second_stage() { function quickMenuChange() { var chooser = document.getElementById("quickMenuChooser"); - var opid = chooser[chooser.selectedIndex].id; + var opid = chooser[chooser.selectedIndex].value; chooser.selectedIndex = 0; quickMenuGo(opid); @@ -507,11 +444,13 @@ function quickMenuGo(opid) { var actid = getActiveFeedId(); if (!actid) { - notify("Please select some feed first."); + alert("Please select some feed first."); return; } + + var fn = getFeedName(actid); - if (confirm("Remove current feed?")) { + if (confirm("Unsubscribe from " + fn + "?")) { qfdDelete(actid); } @@ -541,100 +480,6 @@ function quickMenuGo(opid) { } } -function qafAdd() { - - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } - - var link = document.getElementById("qafInput"); - - if (link.value.length == 0) { - notify("Missing feed URL."); - } else { - notify("Adding feed..."); - - var cat = document.getElementById("qafCat"); - var cat_id = ""; - - if (cat) { - cat_id = cat[cat.selectedIndex].id; - } else { - cat_id = 0; - } - - var feeds_doc = window.frames["feeds-frame"].document; - - feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; - - xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=add&link=" + - param_escape(link.value) + "&cid=" + param_escape(cat_id), true); - xmlhttp.onreadystatechange=dlg_frefresh_callback; - xmlhttp.send(null); - - link.value = ""; - - } -} - -function qaddFilter() { - - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } - - var regexp = document.getElementById("fadd_regexp"); - var match = document.getElementById("fadd_match"); - var feed = document.getElementById("fadd_feed"); - var action = document.getElementById("fadd_action"); - - if (regexp.value.length == 0) { - notify("Missing filter expression."); - } else { - notify("Adding filter..."); - - var v_match = match[match.selectedIndex].text; - var feed_id = feed[feed.selectedIndex].id; - var action_id = action[action.selectedIndex].id; - - xmlhttp.open("GET", "backend.php?op=pref-filters&quiet=1&subop=add®exp=" + - param_escape(regexp.value) + "&match=" + v_match + - "&fid=" + param_escape(feed_id) + "&aid=" + param_escape(action_id), true); - - xmlhttp.onreadystatechange=dlg_submit_callback; - xmlhttp.send(null); - - regexp.value = ""; - } - -} - - -function displayDlg(id, param) { - - if (!xmlhttp_ready(xmlhttp)) { - printLockingError(); - return - } - - notify(""); - - xmlhttp.open("GET", "backend.php?op=dlg&id=" + - param_escape(id) + "¶m=" + param_escape(param), true); - xmlhttp.onreadystatechange=dlg_display_callback; - xmlhttp.send(null); - - disableHotkeys(); -} - -function closeDlg() { - var dlg = document.getElementById("userDlgShadow"); - dlg.style.display = "none"; - enableHotkeys(); -} - function qfdDelete(feed_id) { notify("Removing feed..."); @@ -644,9 +489,6 @@ function qfdDelete(feed_id) { return } -// var feeds_doc = window.frames["feeds-frame"].document; -// feeds_doc.location.href = "backend.php?op=error&msg=Loading,%20please wait..."; - _qfd_deleted_feed = feed_id; xmlhttp.open("GET", "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id); @@ -668,32 +510,46 @@ function toggleDispRead() { return } - var hide_read_feeds = (getCookie("ttrss_vf_hreadf") == 1); + var hide_read_feeds = (getInitParam("hide_read_feeds") == "1"); hide_read_feeds = !hide_read_feeds; - + + debug("toggle_disp_read => " + hide_read_feeds); + + hideOrShowFeeds(getFeedsContext().document, hide_read_feeds); + var query = "backend.php?op=rpc&subop=setpref" + "&key=HIDE_READ_FEEDS&value=" + param_escape(hide_read_feeds); - xmlhttp.open("GET", query); - xmlhttp.onreadystatechange=hide_unread_callback; - xmlhttp.send(null); + storeInitParam("hide_read_feeds", hide_read_feeds, true); + + new Ajax.Request(query); } catch (e) { exception_error("toggleDispRead", e); } } -function debug(msg) { - var c = document.getElementById('debug_output'); - if (c && c.style.display == "block") { - while (c.lastChild != 'undefined' && c.childNodes.length > 20) { - c.removeChild(c.lastChild); +function parse_runtime_info(elem) { + var param = elem.firstChild; + + debug("parse_runtime_info"); + + while (param) { + var k = param.getAttribute("key"); + var v = param.getAttribute("value"); + + debug("RI: " + k + " => " + v); + + var w = document.getElementById("noDaemonWarning"); + + if (w) { + if (k == "daemon_is_running" && v != 1) { + w.style.display = "block"; + } else { + w.style.display = "none"; + } } - - var d = new Date(); - var ts = leading_zero(d.getHours()) + ":" + leading_zero(d.getMinutes()) + - ":" + leading_zero(d.getSeconds()); - c.innerHTML = "
  • [" + ts + "] " + msg + "
  • " + c.innerHTML; + param = param.nextSibling; } }