X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=inline;f=tt-rss.js;h=82472729138534a40f1b52d78e100e7fd210e798;hb=b4e75b2a25d0a30d77b2160c8195835c9816cfe0;hp=879fff23c13c04b75bf0e47fd594558d0412a306;hpb=c8d5dcfe2b640d0a0d8d9d6904fcc0f0ce9d1b1c;p=tt-rss.git diff --git a/tt-rss.js b/tt-rss.js index 879fff23..82472729 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -1,3 +1,4 @@ + var total_unread = 0; var first_run = true; var display_tags = false; @@ -8,16 +9,50 @@ var daemon_enabled = false; var daemon_refresh_only = false; //var _qfd_deleted_feed = 0; var firsttime_update = true; -var active_feed_id = 0; -var active_feed_is_cat = false; +var _active_feed_id = 0; +var _active_feed_is_cat = false; var number_of_feeds = 0; var sanity_check_done = false; var _hfd_scrolltop = 0; var hotkey_prefix = false; +var hotkey_prefix_pressed = false; var init_params = new Object(); var ver_offset = 0; var hor_offset = 0; var feeds_sort_by_unread = false; +var feedlist_sortable_enabled = false; + +function activeFeedIsCat() { + return _active_feed_is_cat; +} + +function getActiveFeedId() { + try { + debug("gAFID: " + _active_feed_id); + return _active_feed_id; + } catch (e) { + exception_error("getActiveFeedId", e); + } +} + +function setActiveFeedId(id, is_cat) { + try { + debug("sAFID(" + id + ", " + is_cat + ")"); + _active_feed_id = id; + + if (is_cat != undefined) { + _active_feed_is_cat = is_cat; + } + + } catch (e) { + exception_error("setActiveFeedId", e); + } +} + + +function isFeedlistSortable() { + return feedlist_sortable_enabled; +} function tagsAreDisplayed() { return display_tags; @@ -29,7 +64,7 @@ function toggleTags(show_all) { debug("toggleTags: " + show_all + "; " + display_tags); - var p = document.getElementById("dispSwitchPrompt"); + var p = $("dispSwitchPrompt"); if (!show_all && !display_tags) { displayDlg("printTagCloud"); @@ -53,7 +88,7 @@ function toggleTags(show_all) { function dlg_frefresh_callback(transport, deleted_feed) { if (getActiveFeedId() == deleted_feed) { - var h = document.getElementById("headlines-frame"); + var h = $("headlines-frame"); if (h) { h.innerHTML = "
" + __('No feed selected.') + "
"; } @@ -96,14 +131,24 @@ function backend_sanity_check_callback(transport) { } if (!transport.responseXML) { - fatalError(3, "[D001, Received reply is not XML]: " + transport.responseText); - return; + if (!store) { + fatalError(3, "Sanity check: Received reply is not XML", + transport.responseText); + return; + } else { + init_offline(); + return; + } + } + + if (getURLParam("offline")) { + return init_offline(); } var reply = transport.responseXML.firstChild.firstChild; if (!reply) { - fatalError(3, "[D002, Invalid RPC reply]: " + transport.responseText); + fatalError(3, "Sanity check: invalid RPC reply", transport.responseText); return; } @@ -126,6 +171,13 @@ function backend_sanity_check_callback(transport) { var v = param.getAttribute("value"); debug(k + " => " + v); init_params[k] = v; + + if (db) { + db.execute("DELETE FROM init_params WHERE key = ?", [k]); + db.execute("INSERT INTO init_params (key,value) VALUES (?, ?)", + [k, v]); + } + param = param.nextSibling; } } @@ -135,7 +187,7 @@ function backend_sanity_check_callback(transport) { init_second_stage(); } catch (e) { - exception_error("backend_sanity_check_callback", e); + exception_error("backend_sanity_check_callback", e, transport); } } @@ -177,7 +229,8 @@ function scheduleFeedUpdate(force) { debug("REFETCH query: " + query_str); - new Ajax.Request(query_str, { + new Ajax.Request("backend.php", { + parameters: query_str, onComplete: function(transport) { refetch_callback2(transport); } }); @@ -191,6 +244,8 @@ function updateFeedList(silent, fetch) { debug("updateFeedList"); + if (offline_mode) return render_offline_feedlist(); + var query_str = "backend.php?op=feeds"; if (display_tags) { @@ -207,12 +262,13 @@ function updateFeedList(silent, fetch) { if (fetch) query_str = query_str + "&fetch=yes"; -// var feeds_frame = document.getElementById("feeds-frame"); +// var feeds_frame = $("feeds-frame"); // feeds_frame.src = query_str; debug("updateFeedList Q=" + query_str); - new Ajax.Request(query_str, { + new Ajax.Request("backend.php", { + parameters: query_str, onComplete: function(transport) { feedlist_callback2(transport); } }); @@ -231,7 +287,8 @@ function catchupAllFeeds() { debug("catchupAllFeeds Q=" + query_str); - new Ajax.Request(query_str, { + new Ajax.Request("backend.php", { + parameters: query_str, onComplete: function(transport) { feedlist_callback2(transport); } }); @@ -245,7 +302,7 @@ function viewCurrentFeed(subop) { // if (getActiveFeedId()) { if (getActiveFeedId() != undefined) { - viewfeed(getActiveFeedId(), subop, active_feed_is_cat); + viewfeed(getActiveFeedId(), subop, activeFeedIsCat()); } else { disableContainerChildren("headlinesToolbar", false, document); // viewfeed(-1, subop); // FIXME @@ -271,7 +328,7 @@ function timeout() { } function resetSearch() { - var searchbox = document.getElementById("searchbox") + var searchbox = $("searchbox") if (searchbox.value != "" && getActiveFeedId()) { searchbox.value = ""; @@ -316,9 +373,9 @@ function genericSanityCheck() { // if (!Ajax.getTransport()) fatalError(1); - setCookie("ttrss_vf_test", "TEST"); + setCookie("ttrss_test", "TEST"); - if (getCookie("ttrss_vf_test") != "TEST") { + if (getCookie("ttrss_test") != "TEST") { fatalError(2); } @@ -329,10 +386,7 @@ function init() { try { - // this whole shebang is based on http://www.birnamdesigns.com/misc/busted2.html - - if (arguments.callee.done) return; - arguments.callee.done = true; + init_gears(); disableContainerChildren("headlinesToolbar", true); @@ -350,7 +404,8 @@ function init() { loading_set_progress(30); - new Ajax.Request("backend.php?op=rpc&subop=sanityCheck" + params, { + new Ajax.Request("backend.php", { + parameters: "backend.php?op=rpc&subop=sanityCheck" + params, onComplete: function(transport) { backend_sanity_check_callback(transport); } }); @@ -366,12 +421,12 @@ function resize_headlines(delta_x, delta_y) { debug("resize_headlines: " + delta_x + ":" + delta_y); - var h_frame = document.getElementById("headlines-frame"); - var c_frame = document.getElementById("content-frame"); - var f_frame = document.getElementById("footer"); - var feeds_frame = document.getElementById("feeds-holder"); - var resize_grab = document.getElementById("resize-grabber"); - var resize_handle = document.getElementById("resize-handle"); + var h_frame = $("headlines-frame"); + var c_frame = $("content-frame"); + var f_frame = $("footer"); + var feeds_frame = $("feeds-holder"); + var resize_grab = $("resize-grabber"); + var resize_handle = $("resize-handle"); if (!c_frame || !h_frame) return; @@ -412,7 +467,7 @@ function resize_headlines(delta_x, delta_y) { h_frame.style.height = (300 - ver_offset) + "px"; - c_frame.style.top = (h_frame.offsetTop + h_frame.offsetHeight + 1) + "px"; + c_frame.style.top = (h_frame.offsetTop + h_frame.offsetHeight + 0) + "px"; h_frame.style.height = h_frame.offsetHeight + "px"; var theme_c = 0; @@ -451,19 +506,34 @@ function init_second_stage() { try { - delCookie("ttrss_vf_test"); + delCookie("ttrss_test"); // document.onresize = resize_headlines; + window.onresize=resize_headlines; var toolbar = document.forms["main_toolbar_form"]; dropboxSelect(toolbar.view_mode, getInitParam("default_view_mode")); dropboxSelect(toolbar.limit, getInitParam("default_view_limit")); + dropboxSelect(toolbar.order_by, getInitParam("default_view_order_by")); daemon_enabled = getInitParam("daemon_enabled") == 1; daemon_refresh_only = getInitParam("daemon_refresh_only") == 1; feeds_sort_by_unread = getInitParam("feeds_sort_by_unread") == 1; +/* var fl = cache_find_param("FEEDLIST", getInitParam("num_feeds")); + + if (fl) { + render_feedlist(fl); + if ($("feedList")) { + request_counters(); + } else { + setTimeout('updateFeedList(false, false)', 50); + } + } else { + setTimeout('updateFeedList(false, false)', 50); + } */ + setTimeout('updateFeedList(false, false)', 50); debug("second stage ok"); @@ -473,6 +543,8 @@ function init_second_stage() { ver_offset = parseInt(getCookie("ttrss_offset_ver")); hor_offset = parseInt(getCookie("ttrss_offset_hor")); + debug("got offsets from cookies: ver " + ver_offset + " hor " + hor_offset); + /* fuck IE */ if (isNaN(hor_offset)) hor_offset = 0; @@ -482,13 +554,15 @@ function init_second_stage() { resize_headlines(); + enable_offline_reading(); + } catch (e) { exception_error("init_second_stage", e); } } function quickMenuChange() { - var chooser = document.getElementById("quickMenuChooser"); + var chooser = $("quickMenuChooser"); var opid = chooser[chooser.selectedIndex].value; chooser.selectedIndex = 0; @@ -584,6 +658,10 @@ function quickMenuGo(opid) { displayDlg("quickAddFilter", getActiveFeedId()); } + if (opid == "qmcAddLabel") { + addLabel(); + } + if (opid == "qmcRescoreFeed") { rescoreCurrentFeed(); } @@ -599,6 +677,22 @@ function quickMenuGo(opid) { resize_headlines(); } + if (opid == "qmcResetCats") { + + if (confirm(__("Reset category order?"))) { + + var query = "?op=feeds&subop=catsortreset"; + + notify_progress("Loading, please wait...", true); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + window.setTimeout('updateFeedList(false, false)', 50); + } }); + } + } + } catch (e) { exception_error("quickMenuGo", e); } @@ -612,9 +706,10 @@ function unsubscribeFeed(feed_id, title) { if (title == undefined || confirm(msg)) { notify_progress("Removing feed..."); - var query = "backend.php?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; + var query = "?op=pref-feeds&quiet=1&subop=remove&ids=" + feed_id; - new Ajax.Request(query, { + new Ajax.Request("backend.php", { + parameters: query, onComplete: function(transport) { dlg_frefresh_callback(transport, feed_id); } }); @@ -663,8 +758,12 @@ function parse_runtime_info(elem) { debug("RI: " + k + " => " + v); + if (k == "num_feeds") { + init_params[k] = v; + } + if (k == "new_version_available") { - var icon = document.getElementById("newVersionIcon"); + var icon = $("newVersionIcon"); if (icon) { if (v == "1") { icon.style.display = "inline"; @@ -690,7 +789,7 @@ function parse_runtime_info(elem) { notify(''); } -/* var w = document.getElementById("noDaemonWarning"); +/* var w = $("noDaemonWarning"); if (w) { if (k == "daemon_is_running" && v != 1) { @@ -705,25 +804,29 @@ function parse_runtime_info(elem) { function catchupCurrentFeed() { - var fn = getFeedName(getActiveFeedId(), active_feed_is_cat); + var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); var str = __("Mark all articles in %s as read?").replace("%s", fn); -/* if (active_feed_is_cat) { - str = "Mark all articles in this category as read?"; - } */ - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { return viewCurrentFeed('MarkAllRead') } } -function catchupFeedInGroup(id, title) { +function catchupFeedInGroup(id) { - var str = __("Mark all articles in %s as read?").replace("%s", title); + try { - if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { - return viewCurrentFeed('MarkAllReadGR:' + id) + var title = getFeedName(id); + + var str = __("Mark all articles in %s as read?").replace("%s", title); + + if (getInitParam("confirm_feed_catchup") != 1 || confirm(str)) { + return viewCurrentFeed('MarkAllReadGR:' + id) + } + + } catch (e) { + exception_error("catchupFeedInGroup", e); } } @@ -735,7 +838,7 @@ function editFeedDlg(feed) { return; } - if ((feed <= 0 && feed > -10) || activeFeedIsCat() || tagsAreDisplayed()) { + if ((feed <= 0) || activeFeedIsCat() || tagsAreDisplayed()) { alert(__("You can't edit this kind of feed.")); return; } @@ -743,14 +846,17 @@ function editFeedDlg(feed) { var query = ""; if (feed > 0) { - query = "backend.php?op=pref-feeds&subop=editfeed&id=" + param_escape(feed); + query = "?op=pref-feeds&subop=editfeed&id=" + param_escape(feed); } else { - query = "backend.php?op=pref-labels&subop=edit&id=" + param_escape(-feed-11); + query = "?op=pref-labels&subop=edit&id=" + param_escape(-feed-11); } disableHotkeys(); - new Ajax.Request(query, { + notify_progress("Loading, please wait...", true); + + new Ajax.Request("backend.php", { + parameters: query, onComplete: function(transport) { infobox_callback2(transport); } }); @@ -794,41 +900,14 @@ function feedEditSave() { } } -function labelEditCancel() { - closeInfoBox(); - return false; -} - -function labelEditSave() { - - try { - - closeInfoBox(); - - notify_progress("Saving label..."); - - query = Form.serialize("label_edit_form"); - - new Ajax.Request("backend.php?" + query, { - onComplete: function(transport) { - dlg_frefresh_callback(transport); - } }); - - return false; - - } catch (e) { - exception_error("feedEditSave (main)", e); - } - -} - function clearFeedArticles(feed_id) { notify_progress("Clearing feed..."); - var query = "backend.php?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id; + var query = "?op=pref-feeds&quiet=1&subop=clear&id=" + feed_id; - new Ajax.Request(query, { + new Ajax.Request("backend.php", { + parameters: query, onComplete: function(transport) { dlg_frefresh_callback(transport, feed_id); } }); @@ -836,28 +915,6 @@ function clearFeedArticles(feed_id) { return false; } -/* -function toggle_feedlist() { - try { - debug("toggle_feedlist"); - - var fl = document.getElementById("feeds-holder"); - - if (!Element.visible(fl)) { - Element.show(fl); - fl.style.zIndex = 30; - fl.scrollTop = _hfd_scrolltop; - } else { - _hfd_scrolltop = fl.scrollTop; - Element.hide(fl); -// Effect.Fade(fl, {duration : 0.2, -// queue: { position: 'end', scope: 'FLFADEQ', limit: 1 }}); - } - } catch (e) { - exception_error("toggle_feedlist", e); - } -} */ - function collapse_feedlist() { try { debug("toggle_feedlist"); @@ -866,13 +923,13 @@ function collapse_feedlist() { if (theme != "" && theme != "compact" && theme != "graycube" && theme != "compat") return; - var fl = document.getElementById("feeds-holder"); - var fh = document.getElementById("headlines-frame"); - var fc = document.getElementById("content-frame"); - var ft = document.getElementById("toolbar"); - var ff = document.getElementById("footer"); - var fhdr = document.getElementById("header"); - var fbtn = document.getElementById("collapse_feeds_btn"); + var fl = $("feeds-holder"); + var fh = $("headlines-frame"); + var fc = $("content-frame"); + var ft = $("toolbar"); + var ff = $("footer"); + var fhdr = $("header"); + var fbtn = $("collapse_feeds_btn"); if (!Element.visible(fl)) { Element.show(fl); @@ -892,7 +949,9 @@ function collapse_feedlist() { if (fc) fc.style.left = fl.offsetWidth + 40 + "px"; } - setCookie("ttrss_vf_fclps", "0"); + query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=false"; + + new Ajax.Request("backend.php", { parameters: query }); } else { Element.hide(fl); @@ -914,7 +973,10 @@ function collapse_feedlist() { } - setCookie("ttrss_vf_fclps", "1"); + query = "?op=rpc&subop=setpref&key=_COLLAPSED_FEEDLIST&value=true"; + + new Ajax.Request("backend.php", { parameters: query }); + } } catch (e) { exception_error("toggle_feedlist", e); @@ -931,15 +993,16 @@ function viewLimitChanged() { return viewCurrentFeed(0, '') } -function adjustArticleScore(id, score) { +/* function adjustArticleScore(id, score) { try { var pr = prompt(__("Assign score to article:"), score); if (pr != undefined) { - var query = "backend.php?op=rpc&subop=setScore&id=" + id + "&score=" + pr; + var query = "?op=rpc&subop=setScore&id=" + id + "&score=" + pr; - new Ajax.Request(query, { + new Ajax.Request("backend.php", { + parameters: query, onComplete: function(transport) { viewCurrentFeed(); } }); @@ -948,7 +1011,7 @@ function adjustArticleScore(id, score) { } catch (e) { exception_error("adjustArticleScore", e); } -} +} */ function rescoreCurrentFeed() { @@ -970,12 +1033,13 @@ function rescoreCurrentFeed() { if (confirm(pr)) { notify_progress("Rescoring articles..."); - var query = "backend.php?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid; + var query = "?op=pref-feeds&subop=rescore&quiet=1&ids=" + actid; - new Ajax.Request(query, { - onComplete: function(transport) { - viewCurrentFeed(); - } }); + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + viewCurrentFeed(); + } }); } } @@ -986,7 +1050,8 @@ function hotkey_handler(e) { var keycode; var shift_key = false; - var feedlist = document.getElementById('feedList'); + var cmdline = $('cmdline'); + var feedlist = $('feedList'); try { shift_key = e.shiftKey; @@ -1017,11 +1082,19 @@ function hotkey_handler(e) { if (keycode == 16) return; // ignore lone shift - if ((keycode == 70 || keycode == 67 || keycode == 71 || - keycode == 224 || keycode == 91) && !hotkey_prefix) { + if ((keycode == 70 || keycode == 67 || keycode == 71) + && !hotkey_prefix) { + + var date = new Date(); + var ts = Math.round(date.getTime() / 1000); hotkey_prefix = keycode; - debug("KP: PREFIX=" + keycode + " CHAR=" + keychar); + hotkey_prefix_pressed = ts; + + cmdline.innerHTML = keychar; + Element.show(cmdline); + + debug("KP: PREFIX=" + keycode + " CHAR=" + keychar + " TS=" + ts); return true; } @@ -1031,6 +1104,8 @@ function hotkey_handler(e) { /* Global hotkeys */ + Element.hide(cmdline); + if (!hotkey_prefix) { if (keycode == 68 && shift_key) { // d @@ -1064,13 +1139,6 @@ function hotkey_handler(e) { return; } - if (keycode == 82) { // r - if (getActiveFeedId()) { - viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat()); - return; - } - } - if (keycode == 74) { // j var feed = getActiveFeedId(); var new_feed = getRelativeFeedId2(feed, activeFeedIsCat(), 'prev'); @@ -1103,16 +1171,27 @@ function hotkey_handler(e) { return; } - if (shift_key && (keycode == 78 || keycode == 40)) { // shift - n, down + if (shift_key && keycode == 40) { // shift-down catchupRelativeToArticle(1); return; } - if (shift_key && (keycode == 80 || keycode == 38)) { // shift - p, up + if (shift_key && keycode == 38) { // shift-up catchupRelativeToArticle(0); return; } + if (shift_key && keycode == 78) { // N + scrollArticle(50); + return; + } + + if (shift_key && keycode == 80) { // P + scrollArticle(-50); + return; + } + + if (keycode == 78 || keycode == 40) { // n, down if (typeof moveToPost != 'undefined') { moveToPost('next'); @@ -1163,7 +1242,7 @@ function hotkey_handler(e) { if (keycode == 9) { // tab var id = getArticleUnderPointer(); if (id) { - var cb = document.getElementById("RCHK-" + id); + var cb = $("RCHK-" + id); if (cb) { cb.checked = !cb.checked; @@ -1187,26 +1266,6 @@ function hotkey_handler(e) { } } - if (keycode == 81) { // q - if (getActiveFeedId()) { - catchupCurrentFeed(); - return; - } - } - - if (keycode == 220 && shift_key) { // shift + | - if (document.getElementById("subtoolbar_search")) { - if (Element.visible("subtoolbar_search")) { - Element.hide("subtoolbar_search"); - Element.show("subtoolbar_ftitle"); - setTimeout("Element.focus('subtoolbar_search_box')", 100); - } else { - Element.show("subtoolbar_search"); - Element.hide("subtoolbar_ftitle"); - } - } - } - if (keycode == 88) { // x if (activeFeedIsCat()) { toggleCollapseCat(getActiveFeedId()); @@ -1220,6 +1279,20 @@ function hotkey_handler(e) { hotkey_prefix = false; + if (keycode == 81) { // q + if (getActiveFeedId()) { + catchupCurrentFeed(); + return; + } + } + + if (keycode == 82) { // r + if (getActiveFeedId()) { + viewfeed(getActiveFeedId(), "ForceUpdate", activeFeedIsCat()); + return; + } + } + if (keycode == 65) { // a toggleDispRead(); return false; @@ -1283,6 +1356,11 @@ function hotkey_handler(e) { return false; } + if (keycode == 76) { // l + addLabel(); + return false; + } + if (keycode == 83) { // s if (typeof collapse_feedlist != 'undefined') { collapse_feedlist(); @@ -1290,6 +1368,28 @@ function hotkey_handler(e) { } } + if (keycode == 77) { // m + feedlist_sortable_enabled = !feedlist_sortable_enabled; + if (feedlist_sortable_enabled) { + notify_info("Category reordering enabled"); + toggle_sortable_feedlist(true); + } else { + notify_info("Category reordering disabled"); + toggle_sortable_feedlist(false); + } + } + + if (keycode == 78) { // n + catchupRelativeToArticle(1); + return; + } + + if (keycode == 80) { // p + catchupRelativeToArticle(0); + return; + } + + } /* Prefix g */ @@ -1298,6 +1398,12 @@ function hotkey_handler(e) { hotkey_prefix = false; + + if (keycode == 65) { // a + viewfeed(-4); + return false; + } + if (keycode == 83) { // s viewfeed(-1); return false; @@ -1346,3 +1452,69 @@ function hotkey_handler(e) { function feedsSortByUnread() { return feeds_sort_by_unread; } + +function addLabel() { + + try { + + var caption = prompt(__("Please enter label caption:"), ""); + + if (caption != undefined) { + + if (caption == "") { + alert(__("Can't create label: missing caption.")); + return false; + } + + var query = "?op=pref-labels&subop=add&caption=" + + param_escape(caption); + + notify_progress("Loading, please wait...", true); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + updateFeedList(); + } }); + + } + + } catch (e) { + exception_error("addLabel", e); + } +} + +function visitOfficialSite() { + window.open("http://tt-rss.org/"); +} + + +function feedBrowserSubscribe() { + try { + + var selected = getSelectedFeedsFromBrowser(); + + if (selected.length > 0) { + closeInfoBox(); + + notify_progress("Loading, please wait...", true); + + var query = "backend.php?op=pref-feeds&subop=massSubscribe&ids="+ + param_escape(selected.toString()); + + new Ajax.Request("backend.php", { + parameters: query, + onComplete: function(transport) { + updateFeedList(); + } }); + + } else { + alert(__("No feeds are selected.")); + } + + } catch (e) { + exception_error("feedBrowserSubscribe", e); + } +} + +