var last_feeds = [];
var init_params = {};
-var db = false;
-var store = false;
-
var _active_feed_id = false;
var _active_feed_offset = false;
var _update_timeout = false;
}
}
-function catchup_visible_articles(callback) {
+function get_visible_article_ids() {
try {
-
var elems = $("headlines-content").getElementsByTagName("LI");
var ids = [];
}
}
+ return ids;
+
+ } catch (e) {
+ exception_error("get_visible_article_ids", e);
+ }
+}
+
+function catchup_visible_articles(callback) {
+ try {
+
+ var ids = get_visible_article_ids();
+
if (confirm(__("Mark %d displayed articles as read?").replace("%d", ids.length))) {
var query = "?op=rpc&subop=catchupSelected" +
onComplete: function(transport) {
fatal_error_check(transport);
- if (transport.responseXML) {
- var article = transport.responseXML.getElementsByTagName('article')[0];
- elem.innerHTML = article.firstChild.nodeValue;
+ var reply = JSON.parse(transport.responseText);
+
+ if (reply) {
+ var article = reply['article'];
+
+ elem.innerHTML = article.content;
new Effect.BlindDown(elem, {duration : 0.5});
console.log(query);
- var img = $("F-" + feed_id).getElementsByTagName("IMG")[0];
+ if ($("F-" + feed_id)) {
+ var img = $("F-" + feed_id).getElementsByTagName("IMG")[0];
- if (img && !no_indicator) {
- img.setAttribute("orig_src", img.src);
- img.src = 'images/indicator_tiny.gif';
+ if (img && !no_indicator) {
+ img.setAttribute("orig_src", img.src);
+ img.src = 'images/indicator_tiny.gif';
+ }
}
new Ajax.Request("backend.php", {
function get_feed_icon(feed) {
try {
if (feed.has_icon)
- return getInitParam('icons_location') + "/" + feed.id + '.ico';
+ return getInitParam('icons_url') + "/" + feed.id + '.ico';
if (feed.id == -1)
return 'images/mark_set.png';
if (article.excerpt.trim() == "")
article.excerpt = __("Click to expand article.");
- var tmp_html = "<li id=\"A-"+article.id+"\" "+style+" class=\"unread\">" +
+ var li_class = "unread";
+
+ var fresh_max = getInitParam("fresh_article_max_age") * 60 * 60;
+ var d = new Date();
+
+ if (d.getTime() / 1000 - article.updated < fresh_max)
+ li_class = "fresh";
+
+ var tmp_html = "<li id=\"A-"+article.id+"\" "+style+" class=\""+li_class+"\">" +
icon_part +
"<div class='digest-check'>" +
mark_part +
publ_part +
+ "<img title='" + __("Share on Twitter") + "' onclick=\"tweet_article("+article.id+", true)\" src='images/art-tweet.png'>" +
"<img title='" + __("Mark as read") + "' onclick=\"view("+article.id+", true)\" src='images/digest_checkbox.png'>" +
"</div>" +
"<a target=\"_blank\" href=\""+article.link+"\""+
"</a>" + "</li>";
}
+ if (feeds.length == 0) {
+ $('feeds-content').innerHTML =
+ "<div class='insensitive' style='text-align : center'>" +
+ __("No unread feeds.") + "</div>";
+ }
+
} catch (e) {
exception_error("redraw_feedlist", e);
}
function parse_feeds(transport) {
try {
+ var reply = JSON.parse(transport.responseText);
- if (!transport.responseXML) return;
+ if (!reply) return;
- var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
+ var feeds = reply['feeds'];
if (feeds) {
- feeds = eval("(" + feeds.firstChild.nodeValue + ")");
feeds.sort( function (a,b)
{
function parse_headlines(transport, replace, no_effects) {
try {
- if (!transport.responseXML) return;
+ var reply = JSON.parse(transport.responseText);
+ if (!reply) return;
- var seq = transport.responseXML.getElementsByTagName('seq')[0];
+ var seq = reply['seq'];
if (seq) {
- seq = seq.firstChild.nodeValue;
if (seq != _update_seq) {
console.log("parse_headlines: wrong sequence received.");
return;
return;
}
- var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
- var headlines_title = transport.responseXML.getElementsByTagName('headlines-title')[0];
+ var headlines = reply['headlines']['content'];
+ var headlines_title = reply['headlines']['title'];
if (headlines && headlines_title) {
- headlines = eval("(" + headlines.firstChild.nodeValue + ")");
-
- var title = headlines_title.firstChild.nodeValue;
-
- $("headlines-title").innerHTML = title;
+ $("headlines-title").innerHTML = headlines_title
if (replace) {
$('headlines-content').innerHTML = '';
}
}
- if (pr) {
- $('headlines-content').appendChild(pr);
- if (!no_effects) new Effect.ScrollTo(inserted);
- } else {
- $('headlines-content').innerHTML += "<li id='H-MORE-PROMPT'>" +
- "<div class='body'>" +
- "<a href=\"javascript:catchup_visible_articles()\">" +
- __("Mark as read") + "</a> | " +
- "<a href=\"javascript:load_more()\">" +
- __("Load more...") + "</a>" +
- "<img style=\"display : none\" "+
+ var ids = get_visible_article_ids();
+
+ if (ids.length > 0) {
+ if (pr) {
+ $('headlines-content').appendChild(pr);
+ if (!no_effects && inserted) new Effect.ScrollTo(inserted);
+ } else {
+ $('headlines-content').innerHTML += "<li id='H-MORE-PROMPT'>" +
+ "<div class='body'>" +
+ "<a href=\"#\" onclick=\"catchup_visible_articles()\">" +
+ __("Mark as read") + "</a> | " +
+ "<a href=\"#\" onclick=\"load_more()\">" +
+ __("Load more...") + "</a>" +
+ "<img style=\"display : none\" "+
"id=\"H-LOADING-IMG\" src='images/indicator_tiny.gif'>" +
- "</div></li>";
+ "</div></li>";
+ }
+ } else {
+ // FIXME : display some kind of "nothing to see here" prompt here
}
if (replace && !no_effects)
function init() {
try {
+ dojo.require("dijit.Dialog");
new Ajax.Request("backend.php", {
parameters: "?op=rpc&subop=sanityCheck",
}
}
-function toggle_mark(mark_img, id) {
+function toggle_mark(img, id) {
try {
var query = "?op=rpc&id=" + id + "&subop=mark";
-
- query = query + "&afid=" + _active_feed_id;
- query = query + "&omode=c";
- if (!mark_img) return;
+ if (!img) return;
- if (mark_img.src.match("mark_unset")) {
- mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
- mark_img.alt = __("Unstar article");
+ if (img.src.match("mark_unset")) {
+ img.src = img.src.replace("mark_unset", "mark_set");
+ img.alt = __("Unstar article");
query = query + "&mark=1";
} else {
- mark_img.alt = __("Please wait...");
+ img.src = img.src.replace("mark_set", "mark_unset");
+ img.alt = __("Star article");
query = query + "&mark=0";
-
- mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
- mark_img.alt = __("Star article");
}
new Ajax.Request("backend.php", {
}
}
-function toggle_pub(mark_img, id, note) {
+function toggle_pub(img, id, note) {
try {
var query = "?op=rpc&id=" + id + "&subop=publ";
- query = query + "&afid=" + _active_feed_id;
-
if (note != undefined) {
query = query + "¬e=" + param_escape(note);
} else {
query = query + "¬e=undefined";
}
- query = query + "&omode=c";
-
- if (!mark_img) return;
+ if (!img) return;
- if (mark_img.src.match("pub_unset") || note != undefined) {
- mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
- mark_img.alt = __("Unpublish article");
+ if (img.src.match("pub_unset") || note != undefined) {
+ img.src = img.src.replace("pub_unset", "pub_set");
+ img.alt = __("Unpublish article");
query = query + "&pub=1";
} else {
- mark_img.alt = __("Please wait...");
+ img.src = img.src.replace("pub_set", "pub_unset");
+ img.alt = __("Publish article");
query = query + "&pub=0";
-
- mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
- mark_img.alt = __("Publish article");
}
new Ajax.Request("backend.php", {
if (code == 6) {
window.location.href = "digest.php";
} else if (code == 5) {
- window.location.href = "update.php";
+ window.location.href = "db-updater.php";
} else {
if (msg == "") msg = "Unknown error";
}
}
+function tweet_article(id) {
+ try {
+
+ var query = "?op=rpc&subop=getTweetInfo&id=" + param_escape(id);
+
+ console.log(query);
+
+ var d = new Date();
+ var ts = d.getTime();
+
+ var w = window.open('backend.php?op=loading', 'ttrss_tweet',
+ "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ var ti = JSON.parse(transport.responseText);
+
+ var share_url = "http://twitter.com/share?_=" + ts +
+ "&text=" + param_escape(ti.title) +
+ "&url=" + param_escape(ti.link);
+
+ w.location.href = share_url;
+
+ } });
+
+ } catch (e) {
+ exception_error("tweet_article", e);
+ }
+}