X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;ds=sidebyside;f=tt-rss.js;h=701bec89d1cb8c59bfba7aa2f210810a9472d975;hb=27c515c380f4f21ce76e52db1becbebc859c3220;hp=d4660d6243ca7a6ce10125da3f07e738ddd92a2b;hpb=c3b81db06c48435ce17528ce0eb9b6bb4c65c513;p=tt-rss.git diff --git a/tt-rss.js b/tt-rss.js index d4660d62..701bec89 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -5,10 +5,17 @@ var xmlhttp = false; var xmlhttp_rpc = false; +var xmlhttp_view = false; var total_unread = 0; var first_run = true; +var active_post_id = false; +var active_feed_id = false; +var active_offset = false; + +var search_query = ""; + /*@cc_on @*/ /*@if (@_jscript_version >= 5) // JScript gives us Conditional compilation, we can cope with old IE versions. @@ -18,8 +25,12 @@ try { } catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); + xmlhttp_rpc = new ActiveXObject("Microsoft.XMLHTTP"); + xmlhttp_view = new ActiveXObject("Microsoft.XMLHTTP"); } catch (E) { xmlhttp = false; + xmlhttp_rpc = false; + xmlhttp_view = false; } } @end @*/ @@ -27,18 +38,7 @@ try { if (!xmlhttp && typeof XMLHttpRequest!='undefined') { xmlhttp = new XMLHttpRequest(); xmlhttp_rpc = new XMLHttpRequest(); - -} - -function printLockingError() { - notify("Please wait until operation finishes"); -} - -function notify_callback() { - var container = document.getElementById('notify'); - if (xmlhttp.readyState == 4) { - container.innerHTML=xmlhttp.responseText; - } + xmlhttp_view = new XMLHttpRequest(); } function feedlist_callback() { @@ -46,76 +46,56 @@ function feedlist_callback() { if (xmlhttp.readyState == 4) { container.innerHTML=xmlhttp.responseText; -// var feedtu = document.getElementById("FEEDTU"); -// if (feedtu) { -// total_unread = feedtu.innerHTML; -// update_title(); -// } - if (first_run) { scheduleFeedUpdate(false); + if (getCookie("ttrss_vf_actfeed")) { + viewfeed(getCookie("ttrss_vf_actfeed"), 0, ""); + } first_run = false; } else { notify(""); - } - } + } + } } -function viewfeed_callback() { - var container = document.getElementById('headlines'); - if (xmlhttp.readyState == 4) { - container.innerHTML = xmlhttp.responseText; - - var factive = document.getElementById("FACTIVE"); - var funread = document.getElementById("FUNREAD"); - var ftotal = document.getElementById("FTOTAL"); - - if (ftotal && factive && funread) { - var feed_id = factive.innerHTML; - - var feedr = document.getElementById("FEEDR-" + feed_id); - var feedt = document.getElementById("FEEDT-" + feed_id); - var feedu = document.getElementById("FEEDU-" + feed_id); - - feedt.innerHTML = ftotal.innerHTML; - feedu.innerHTML = funread.innerHTML; +function refetch_callback() { - if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { - feedr.className = feedr.className + "Unread"; - } else if (feedu.innerHTML <= 0) { - feedr.className = feedr.className.replace("Unread", ""); - } + if (xmlhttp_rpc.readyState == 4) { + notify("All feeds updated"); + var container = document.getElementById('feeds'); + container.innerHTML = xmlhttp_rpc.responseText; + document.title = "Tiny Tiny RSS"; + cleanSelected("feedsList"); + + var feedr = document.getElementById("FEEDR-" + active_feed_id); + if (feedr) { + feedr.className = feedr.className + "Selected"; } - notify(""); - - } + } } -function view_callback() { - var container = document.getElementById('content'); - if (xmlhttp.readyState == 4) { - container.innerHTML=xmlhttp.responseText; - } -} +function updateFeed(feed_id) { -function refetch_callback() { - if (xmlhttp_rpc.readyState == 4) { - notify("All feeds updated"); - - var container = document.getElementById('feeds'); + var query_str = "backend.php?op=rpc&subop=updateFeed&feed=" + feed_id; - container.innerHTML = xmlhttp_rpc.responseText; + if (xmlhttp_ready(xmlhttp_rpc)) { + xmlhttp_rpc.open("GET", query_str, true); + xmlhttp_rpc.onreadystatechange=feed_update_callback; + xmlhttp_rpc.send(null); + } else { + printLockingError(); + } - //updateFeedList(true, false); - } } function scheduleFeedUpdate(force) { notify("Updating feeds in background..."); + document.title = "Tiny Tiny RSS - Updating..."; + var query_str = "backend.php?op=rpc&subop="; if (force) { @@ -124,17 +104,17 @@ function scheduleFeedUpdate(force) { query_str = query_str + "updateAllFeeds"; } - if (xmlhttp_rpc.readyState == 4 || xmlhttp_rpc.readyState == 0) { + if (xmlhttp_ready(xmlhttp_rpc)) { xmlhttp_rpc.open("GET", query_str, true); xmlhttp_rpc.onreadystatechange=refetch_callback; xmlhttp_rpc.send(null); } else { printLockingError(); - } + } } function updateFeedList(silent, fetch) { - + if (silent != true) { notify("Loading feed list..."); } @@ -143,7 +123,7 @@ function updateFeedList(silent, fetch) { if (fetch) query_str = query_str + "&fetch=yes"; - if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) { + if (xmlhttp_ready(xmlhttp)) { xmlhttp.open("GET", query_str, true); xmlhttp.onreadystatechange=feedlist_callback; xmlhttp.send(null); @@ -152,9 +132,10 @@ function updateFeedList(silent, fetch) { } } +/* function catchupPage(feed) { - if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { + if (!xmlhttp_ready(xmlhttp)) { printLockingError(); return } @@ -166,36 +147,56 @@ function catchupPage(feed) { for (i = 0; i < content.rows.length; i++) { var row_id = content.rows[i].id.replace("RROW-", ""); if (row_id.length > 0) { - rows.push(row_id); - content.rows[i].className = content.rows[i].className.replace("Unread", ""); + if (content.rows[i].className.match("Unread")) { + rows.push(row_id); + content.rows[i].className = content.rows[i].className.replace("Unread", ""); + } + + var upd_img_pic = document.getElementById("FUPDPIC-" + row_id); + if (upd_img_pic) { + upd_img_pic.innerHTML = ""; + } } } - var feedr = document.getElementById("FEEDR-" + feed); - var feedu = document.getElementById("FEEDU-" + feed); + if (rows.length > 0) { - feedu.innerHTML = feedu.innerHTML - rows.length; - - if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { - feedr.className = feedr.className + "Unread"; - } else if (feedu.innerHTML <= 0) { - feedr.className = feedr.className.replace("Unread", ""); - } + var feedr = document.getElementById("FEEDR-" + feed); + var feedu = document.getElementById("FEEDU-" + feed); + + feedu.innerHTML = feedu.innerHTML - rows.length; + + if (feedu.innerHTML > 0 && !feedr.className.match("Unread")) { + feedr.className = feedr.className + "Unread"; + } else if (feedu.innerHTML <= 0) { + feedr.className = feedr.className.replace("Unread", ""); + } + + var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + + param_escape(rows.toString()); + + notify("Marking this page as read..."); - var query_str = "backend.php?op=rpc&subop=catchupPage&ids=" + - param_escape(rows.toString()); + var button = document.getElementById("btnCatchupPage"); - notify("Marking this page as read..."); + if (button) { + button.className = "disabledButton"; + button.href = ""; + } + + xmlhttp.open("GET", query_str, true); + xmlhttp.onreadystatechange=notify_callback; + xmlhttp.send(null); - xmlhttp.open("GET", query_str, true); - xmlhttp.onreadystatechange=notify_callback; - xmlhttp.send(null); + } else { + notify("No unread items on this page."); -} + } +} */ function catchupAllFeeds() { - if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { + if (!xmlhttp_ready(xmlhttp)) { printLockingError(); return } @@ -209,95 +210,226 @@ function catchupAllFeeds() { } +function viewCurrentFeed(skip, subop) { + if (active_feed_id ) { + viewfeed(active_feed_id, skip, subop); + } +} + function viewfeed(feed, skip, subop) { -// document.getElementById('headlines').innerHTML='Loading headlines, please wait...'; -// document.getElementById('content').innerHTML=' '; +// notify("Loading headlines..."); - if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { - printLockingError(); - return + enableHotkeys(); + + var searchbox = document.getElementById("searchbox"); + + if (searchbox) { + search_query = searchbox.value; + } else { + search_query = ""; + } + + var viewbox = document.getElementById("viewbox"); + + var view_mode; + + if (viewbox) { + view_mode = viewbox.value; + } else { + view_mode = "All Posts"; } - xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) + - "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) , true); - xmlhttp.onreadystatechange=viewfeed_callback; - xmlhttp.send(null); + setCookie("ttrss_vf_vmode", view_mode); - notify("Loading headlines..."); + var limitbox = document.getElementById("limitbox"); -} + var limit; -function view(id,feed_id) { + if (limitbox) { + limit = limitbox.value; + setCookie("ttrss_vf_limit", limit); + } else { + limit = "All"; + } - if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { - printLockingError(); - return + if (active_feed_id != feed || skip != active_offset) { + active_post_id = false; } - var crow = document.getElementById("RROW-" + id); + active_feed_id = feed; + active_offset = skip; + + setCookie("ttrss_vf_actfeed", feed); - if (crow.className.match("Unread")) { - var umark = document.getElementById("FEEDU-" + feed_id); - umark.innerHTML = umark.innerHTML - 1; - crow.className = crow.className.replace("Unread", ""); + if (subop == "MarkAllRead") { - if (umark.innerHTML == "0") { - var feedr = document.getElementById("FEEDR-" + feed_id); + var feedr = document.getElementById("FEEDR-" + feed); + var feedt = document.getElementById("FEEDT-" + feed); + var feedu = document.getElementById("FEEDU-" + feed); + + feedu.innerHTML = "0"; + + if (feedr.className.match("Unread")) { feedr.className = feedr.className.replace("Unread", ""); } - - total_unread--; - - update_title(); - } + } - var upd_img_pic = document.getElementById("FUPDPIC-" + id); + var query = "backend.php?op=viewfeed&feed=" + param_escape(feed) + + "&skip=" + param_escape(skip) + "&subop=" + param_escape(subop) + + "&view=" + param_escape(view_mode) + "&limit=" + limit; - if (upd_img_pic) { - upd_img_pic.innerHTML = ""; - } + if (search_query != "") { + query = query + "&search=" + param_escape(search_query); + } + + var headlines_frame = document.getElementById("headlines-frame"); + + headlines_frame.src = query + "&addheader=true"; - document.getElementById('content').innerHTML='Loading, please wait...'; + cleanSelected("feedsList"); + var feedr = document.getElementById("FEEDR-" + feed); + if (feedr) { + feedr.className = feedr.className + "Selected"; + } + + disableContainerChildren("headlinesToolbar", false); - xmlhttp.open("GET", "backend.php?op=view&id=" + param_escape(id), true); - xmlhttp.onreadystatechange=view_callback; - xmlhttp.send(null); +// notify(""); } function timeout() { - scheduleFeedUpdate(true); - setTimeout("timeout()", 1800*1000); +} + +function resetSearch() { + var searchbox = document.getElementById("searchbox") + if (searchbox.value != "" && active_feed_id) { + searchbox.value = ""; + viewfeed(active_feed_id, 0, ""); + } } -function search(feed, sender) { +function search() { + if (active_feed_id) { + viewfeed(active_feed_id, 0, ""); + } else { + notify("Please select some feed first."); + } +} - if (xmlhttp.readyState != 4 && xmlhttp.readyState != 0) { - printLockingError(); - return +function localPiggieFunction(enable) { + if (enable) { + var query_str = "backend.php?op=feeds&subop=piggie"; + + if (xmlhttp_ready(xmlhttp)) { + + xmlhttp.open("GET", query_str, true); + xmlhttp.onreadystatechange=feedlist_callback; + xmlhttp.send(null); + } } +} - notify("Search: " + feed + ", " + sender.value) +/* +function moveToPost(mode) { - document.getElementById('headlines').innerHTML='Loading headlines, please wait...'; - document.getElementById('content').innerHTML=' '; + var rows = getVisibleHeadlineIds(); - xmlhttp.open("GET", "backend.php?op=viewfeed&feed=" + param_escape(feed) + - "&search=" + param_escape(sender.value) + "&ext=SEARCH", true); - xmlhttp.onreadystatechange=viewfeed_callback; - xmlhttp.send(null); + var prev_id; + var next_id; + + if (active_post_id == false) { + next_id = getFirstVisibleHeadlineId(); + prev_id = getLastVisibleHeadlineId(); + } else { + for (var i = 0; i < rows.length; i++) { + if (rows[i] == active_post_id) { + prev_id = rows[i-1]; + next_id = rows[i+1]; + } + } + } + + if (mode == "next") { + if (next_id != undefined) { + view(next_id, active_feed_id); + } else { + _viewfeed_autoselect_first = true; + viewfeed(active_feed_id, active_offset+15); + } + } + + if (mode == "prev") { + if ( prev_id != undefined) { + view(prev_id, active_feed_id); + } else { + _viewfeed_autoselect_last = true; + viewfeed(active_feed_id, active_offset-15); + } + } } +*/ + +function localHotkeyHandler(keycode) { + +/* if (keycode == 78) { + return moveToPost('next'); + } + + if (keycode == 80) { + return moveToPost('prev'); + } */ + + if (keycode == 82) { + return scheduleFeedUpdate(true); + } + + if (keycode == 85) { + return viewfeed(active_feed_id, active_offset, "ForceUpdate"); + } + +// notify("KC: " + keycode); -function update_title() { - //document.title = "Tiny Tiny RSS (" + total_unread + " unread)"; } function init() { + + disableContainerChildren("headlinesToolbar", true); + + // IE kludge + + if (xmlhttp && !xmlhttp_rpc) { + xmlhttp_rpc = xmlhttp; + xmlhttp_view = xmlhttp; + } + + if (!xmlhttp || !xmlhttp_rpc || !xmlhttp_view) { + document.getElementById("headlines").innerHTML = + "Fatal error: This program needs XmlHttpRequest " + + "to function properly. Your browser doesn't seem to support it."; + return; + } + updateFeedList(false, false); + document.onkeydown = hotkey_handler; setTimeout("timeout()", 1800*1000); + + var content = document.getElementById("content"); + + if (getCookie("ttrss_vf_vmode")) { + var viewbox = document.getElementById("viewbox"); + viewbox.value = getCookie("ttrss_vf_vmode"); + } + + if (getCookie("ttrss_vf_limit")) { + var limitbox = document.getElementById("limitbox"); + limitbox.value = getCookie("ttrss_vf_limit"); + } } + +