tt-rss/plugins/digest/digest.js

853 lines
18 KiB
JavaScript
Raw Normal View History

2010-09-09 14:50:10 +02:00
var last_feeds = [];
var init_params = {};
2010-09-09 19:44:04 +02:00
var _active_feed_id = false;
2010-09-10 11:59:21 +02:00
var _update_timeout = false;
var _view_update_timeout = false;
2010-09-12 09:05:03 +02:00
var _feedlist_expanded = false;
var _update_seq = 1;
2010-09-12 09:05:03 +02:00
2010-09-12 17:36:59 +02:00
function article_appear(article_id) {
try {
new Effect.Appear('A-' + article_id);
} catch (e) {
exception_error("article_appear", e);
}
}
2010-09-12 09:05:03 +02:00
function catchup_feed(feed_id, callback) {
try {
var fn = find_feed(last_feeds, feed_id).title;
if (confirm(__("Mark all articles in %s as read?").replace("%s", fn))) {
var is_cat = "";
if (feed_id < 0) is_cat = "true"; // KLUDGE
2010-09-12 09:05:03 +02:00
2011-12-12 19:46:25 +01:00
var query = "?op=rpc&method=catchupFeed&feed_id=" +
2010-09-12 09:05:03 +02:00
feed_id + "&is_cat=" + is_cat;
new Ajax.Request("backend.php", {
2011-09-01 08:15:37 +02:00
parameters: query,
2010-09-12 09:05:03 +02:00
onComplete: function(transport) {
if (callback) callback(transport);
2011-09-01 08:15:37 +02:00
2010-09-12 09:05:03 +02:00
update();
} });
}
} catch (e) {
exception_error("catchup_article", e);
}
}
function get_visible_article_ids() {
2010-09-12 11:08:13 +02:00
try {
2010-09-13 10:24:30 +02:00
var elems = $("headlines-content").getElementsByTagName("LI");
var ids = [];
2011-09-01 08:15:37 +02:00
2010-09-13 10:24:30 +02:00
for (var i = 0; i < elems.length; i++) {
if (elems[i].id && elems[i].id.match("A-")) {
ids.push(elems[i].id.replace("A-", ""));
2010-09-12 18:29:10 +02:00
}
2010-09-13 10:24:30 +02:00
}
return ids;
} catch (e) {
exception_error("get_visible_article_ids", e);
}
}
function catchup_visible_articles(callback) {
try {
var ids = get_visible_article_ids();
2010-09-13 10:24:30 +02:00
if (confirm(__("Mark %d displayed articles as read?").replace("%d", ids.length))) {
2011-12-12 19:46:25 +01:00
var query = "?op=rpc&method=catchupSelected" +
2010-09-12 18:29:10 +02:00
"&cmode=0&ids=" + param_escape(ids);
2011-09-01 08:15:37 +02:00
2010-09-12 18:29:10 +02:00
new Ajax.Request("backend.php", {
2011-09-01 08:15:37 +02:00
parameters: query,
2010-09-12 18:29:10 +02:00
onComplete: function(transport) {
if (callback) callback(transport);
2011-09-01 08:15:37 +02:00
2010-09-12 18:29:10 +02:00
viewfeed(_active_feed_id, 0);
} });
2011-09-01 08:15:37 +02:00
2010-09-12 18:29:10 +02:00
}
2010-09-12 11:08:13 +02:00
} catch (e) {
exception_error("catchup_visible_articles", e);
}
}
2010-09-09 19:44:04 +02:00
2010-09-11 13:25:47 +02:00
function catchup_article(article_id, callback) {
try {
2011-12-12 19:46:25 +01:00
var query = "?op=rpc&method=catchupSelected" +
2010-09-11 13:25:47 +02:00
"&cmode=0&ids=" + article_id;
new Ajax.Request("backend.php", {
2011-09-01 08:15:37 +02:00
parameters: query,
2010-09-11 13:25:47 +02:00
onComplete: function(transport) {
if (callback) callback(transport);
} });
} catch (e) {
exception_error("catchup_article", e);
}
}
2011-09-01 14:46:50 +02:00
function set_selected_article(article_id) {
try {
$$("#headlines-content > li[id*=A-]").each(function(article) {
var id = article.id.replace("A-", "");
var cb = article.getElementsByTagName("INPUT")[0];
if (id == article_id) {
article.addClassName("selected");
cb.checked = true;
} else {
article.removeClassName("selected");
cb.checked = false;
}
});
} catch (e) {
exception_error("mark_selected_feed", e);
}
}
2010-09-11 13:25:47 +02:00
function set_selected_feed(feed_id) {
2010-09-11 09:33:47 +02:00
try {
var feeds = $("feeds-content").getElementsByTagName("LI");
for (var i = 0; i < feeds.length; i++) {
if (feeds[i].id == "F-" + feed_id)
feeds[i].className = "selected";
else
feeds[i].className = "";
}
2010-09-11 13:25:47 +02:00
_active_feed_id = feed_id;
2010-09-11 09:33:47 +02:00
} catch (e) {
exception_error("mark_selected_feed", e);
}
}
2010-09-10 11:59:21 +02:00
function load_more() {
try {
2010-09-13 10:24:30 +02:00
var pr = $("H-LOADING-IMG");
if (pr) Element.show(pr);
2011-09-01 14:46:50 +02:00
var offset = $$("#headlines-content > li[id*=A-][class*=fresh],li[id*=A-][class*=unread]").length;
viewfeed(false, offset, false, false, true,
2011-09-01 08:15:37 +02:00
function() {
2010-09-13 10:24:30 +02:00
var pr = $("H-LOADING-IMG");
2011-09-01 08:15:37 +02:00
if (pr) Element.hide(pr);
2010-09-13 10:24:30 +02:00
});
2010-09-10 11:59:21 +02:00
} catch (e) {
exception_error("load_more", e);
}
}
2010-09-13 10:24:30 +02:00
function update(callback) {
2010-09-10 11:59:21 +02:00
try {
2010-09-11 13:25:47 +02:00
console.log('updating feeds...');
window.clearTimeout(_update_timeout);
new Ajax.Request("backend.php", {
2012-12-24 07:16:01 +01:00
parameters: "?op=digest&method=digestinit",
2010-09-11 13:25:47 +02:00
onComplete: function(transport) {
fatal_error_check(transport);
2010-09-11 13:25:47 +02:00
parse_feeds(transport);
set_selected_feed(_active_feed_id);
2010-09-13 10:24:30 +02:00
if (callback) callback(transport);
2010-09-11 13:25:47 +02:00
} });
_update_timeout = window.setTimeout('update()', 5*1000);
2010-09-10 11:59:21 +02:00
} catch (e) {
exception_error("update", e);
}
}
2010-09-11 13:25:47 +02:00
function remove_headline_entry(article_id) {
2010-09-10 11:59:21 +02:00
try {
var elem = $('A-' + article_id);
2010-09-11 13:25:47 +02:00
if (elem) {
elem.parentNode.removeChild(elem);
}
2010-09-10 11:59:21 +02:00
2010-09-11 13:25:47 +02:00
} catch (e) {
exception_error("remove_headline_entry", e);
}
}
2010-09-10 11:59:21 +02:00
function view_update() {
try {
2010-09-13 10:24:30 +02:00
viewfeed(_active_feed_id, _active_feed_offset, false, true, true);
update();
} catch (e) {
exception_error("view_update", e);
}
}
2011-09-01 14:46:50 +02:00
function view(article_id) {
2010-09-11 13:25:47 +02:00
try {
2011-09-01 14:46:50 +02:00
$("content").addClassName("move");
2010-09-10 11:59:21 +02:00
2011-09-01 14:46:50 +02:00
var a = $("A-" + article_id);
var h = $("headlines");
setTimeout(function() {
// below or above viewport, reposition headline
if (a.offsetTop > h.scrollTop + h.offsetHeight || a.offsetTop+a.offsetHeight < h.scrollTop+a.offsetHeight)
h.scrollTop = a.offsetTop - (h.offsetHeight/2 - a.offsetHeight/2);
}, 500);
new Ajax.Request("backend.php", {
2012-12-24 07:16:01 +01:00
parameters: "?op=digest&method=digestgetcontents&article_id=" +
2011-09-01 14:46:50 +02:00
article_id,
onComplete: function(transport) {
fatal_error_check(transport);
var reply = JSON.parse(transport.responseText);
if (reply) {
var article = reply['article'];
var mark_part = "";
var publ_part = "";
var tags_part = "";
if (article.tags.length > 0) {
tags_part = " " + __("in") + " ";
2010-09-10 11:59:21 +02:00
2011-09-01 14:46:50 +02:00
for (var i = 0; i < Math.min(5, article.tags.length); i++) {
//tags_part += "<a href=\"#\" onclick=\"viewfeed('" +
// article.tags[i] + "')\">" +
// article.tags[i] + "</a>, ";
tags_part += article.tags[i] + ", ";
}
tags_part = tags_part.replace(/, $/, "");
tags_part = "<span class=\"tags\">" + tags_part + "</span>";
}
if (article.marked)
2012-12-25 11:01:33 +01:00
mark_part = "<img title='"+ __("Unstar article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_set.svg'>";
2011-09-01 14:46:50 +02:00
else
2012-12-25 11:01:33 +01:00
mark_part = "<img title='"+__("Star article")+"' onclick=\"toggle_mark(this, "+article.id+")\" src='images/mark_unset.svg'>";
2011-09-01 14:46:50 +02:00
if (article.published)
2012-12-25 11:01:33 +01:00
publ_part = "<img title='"+__("Unpublish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_set.svg'>";
2011-09-01 14:46:50 +02:00
else
2012-12-25 11:01:33 +01:00
publ_part = "<img title='"+__("Publish article")+"' onclick=\"toggle_pub(this, "+article.id+")\" src='images/pub_unset.svg'>";
2011-09-01 14:46:50 +02:00
2012-11-07 09:40:52 +01:00
var tmp = "<div id=\"inner\">" +
2011-09-01 14:46:50 +02:00
"<div id=\"ops\">" +
mark_part +
publ_part +
"</div>" +
2012-11-07 09:40:52 +01:00
"<h1>" + "<a target=\"_blank\" href=\""+article.url+"\">" +
article.title + "</a>" + "</h1>" +
2011-09-01 14:46:50 +02:00
"<div id=\"tags\">" +
tags_part +
"</div>" +
article.content + "</div>";
$("article-content").innerHTML = tmp;
$("article").addClassName("visible");
set_selected_article(article.id);
catchup_article(article_id,
function() {
$("A-" + article_id).addClassName("read");
});
} else {
elem.innerHTML = __("Error: unable to load article.");
}
}
});
return false;
2010-09-09 20:01:35 +02:00
} catch (e) {
exception_error("view", e);
}
}
2011-09-01 14:46:50 +02:00
function close_article() {
$("content").removeClassName("move");
$("article").removeClassName("visible");
}
2010-09-13 10:24:30 +02:00
function viewfeed(feed_id, offset, replace, no_effects, no_indicator, callback) {
2010-09-09 17:02:12 +02:00
try {
2010-09-09 19:44:04 +02:00
if (!feed_id) feed_id = _active_feed_id;
2011-09-01 14:46:50 +02:00
if (offset == undefined) offset = 0;
2010-09-12 17:36:59 +02:00
if (replace == undefined) replace = (offset == 0);
_update_seq = _update_seq + 1;
2011-09-01 14:46:50 +02:00
if (!offset) $("headlines").scrollTop = 0;
2012-12-24 07:16:01 +01:00
var query = "backend.php?op=digest&method=digestupdate&feed_id=" +
param_escape(feed_id) + "&offset=" + offset +
"&seq=" + _update_seq;
2010-09-12 12:37:47 +02:00
console.log(query);
2010-09-09 19:44:04 +02:00
2011-12-10 18:26:59 +01:00
var img = false;
2011-12-12 20:32:29 +01:00
if ($("F-" + feed_id)) {
2011-12-10 18:26:59 +01:00
img = $("F-" + feed_id).getElementsByTagName("IMG")[0];
if (img && !no_indicator) {
img.setAttribute("orig_src", img.src);
img.src = 'images/indicator_tiny.gif';
}
2010-09-13 10:24:30 +02:00
}
2010-09-09 17:02:12 +02:00
new Ajax.Request("backend.php", {
2011-09-01 08:15:37 +02:00
parameters: query,
2010-09-09 17:02:12 +02:00
onComplete: function(transport) {
2010-09-13 12:39:16 +02:00
Element.hide("overlay");
fatal_error_check(transport);
2010-09-12 17:36:59 +02:00
parse_headlines(transport, replace, no_effects);
2011-09-01 08:15:37 +02:00
set_selected_feed(feed_id);
2010-09-09 19:44:04 +02:00
_active_feed_offset = offset;
2010-09-13 10:24:30 +02:00
if (img && !no_indicator)
img.src = img.getAttribute("orig_src");
if (callback) callback(transport);
2010-09-11 09:33:47 +02:00
} });
2010-09-09 17:02:12 +02:00
} catch (e) {
exception_error("view", e);
}
}
2010-09-10 11:59:21 +02:00
function find_article(articles, article_id) {
try {
for (var i = 0; i < articles.length; i++) {
if (articles[i].id == article_id)
return articles[i];
}
return false;
} catch (e) {
exception_error("find_article", e);
}
}
2010-09-09 14:50:10 +02:00
function find_feed(feeds, feed_id) {
try {
for (var i = 0; i < feeds.length; i++) {
if (feeds[i].id == feed_id)
return feeds[i];
}
return false;
} catch (e) {
exception_error("find_feed", e);
}
}
2010-09-09 17:02:12 +02:00
function get_feed_icon(feed) {
try {
if (feed.has_icon)
2010-11-05 14:16:30 +01:00
return getInitParam('icons_url') + "/" + feed.id + '.ico';
2010-09-09 17:02:12 +02:00
if (feed.id == -1)
2012-12-25 11:01:33 +01:00
return 'images/mark_set.svg';
2010-09-09 17:02:12 +02:00
if (feed.id == -2)
2012-12-25 11:01:33 +01:00
return 'images/pub_set.svg';
2010-09-09 17:02:12 +02:00
if (feed.id == -3)
return 'images/fresh.png';
2011-09-01 08:15:37 +02:00
if (feed.id == -4)
2010-09-09 17:02:12 +02:00
return 'images/tag.png';
2011-09-01 08:15:37 +02:00
if (feed.id < -10)
2010-09-09 17:02:12 +02:00
return 'images/label.png';
2010-09-11 13:25:47 +02:00
return 'images/blank_icon.gif';
2010-09-09 17:02:12 +02:00
} catch (e) {
exception_error("get_feed_icon", e);
}
}
2010-09-09 14:50:10 +02:00
function add_feed_entry(feed) {
try {
var icon_part = "";
2010-09-09 17:02:12 +02:00
icon_part = "<img src='" + get_feed_icon(feed) + "'/>";
2010-09-09 14:50:10 +02:00
2012-11-07 09:40:52 +01:00
var title = (feed.title.length > 30) ?
feed.title.substring(0, 30) + "&hellip;" :
feed.title;
2011-09-01 14:46:50 +02:00
var tmp_html = "<li id=\"F-"+feed.id+"\" onclick=\"viewfeed("+feed.id+")\">" +
2012-11-07 09:40:52 +01:00
icon_part + title +
2011-09-01 14:46:50 +02:00
"<div class='unread-ctr'>" + "<span class=\"unread\">" + feed.unread + "</span>" +
"</div>" + "</li>";
2010-09-09 14:50:10 +02:00
$("feeds-content").innerHTML += tmp_html;
2011-09-01 14:46:50 +02:00
2010-09-09 14:50:10 +02:00
} catch (e) {
exception_error("add_feed_entry", e);
}
}
2010-09-12 17:36:59 +02:00
function add_headline_entry(article, feed, no_effects) {
2010-09-09 14:50:10 +02:00
try {
var icon_part = "";
2010-09-11 13:25:47 +02:00
icon_part = "<img class='icon' src='" + get_feed_icon(feed) + "'/>";
2010-09-09 14:50:10 +02:00
2010-09-12 17:36:59 +02:00
var style = "";
2011-09-01 14:46:50 +02:00
//if (!no_effects) style = "style=\"display : none\"";
2010-09-12 17:36:59 +02:00
2010-09-13 06:40:37 +02:00
if (article.excerpt.trim() == "")
article.excerpt = __("Click to expand article.");
2010-09-13 16:32:34 +02:00
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";
2011-09-01 14:46:50 +02:00
//"<img title='" + __("Mark as read") + "' onclick=\"view("+article.id+", true)\" src='images/digest_checkbox.png'>" +
var checkbox_part = "<input type=\"checkbox\" class=\"cb\" onclick=\"toggle_select_article(this)\"/>";
var date = new Date(article.updated * 1000);
var date_part = date.toString().substring(0,21);
2011-09-01 08:15:37 +02:00
var tmp_html = "<li id=\"A-"+article.id+"\" "+style+" class=\""+li_class+"\">" +
2011-09-01 14:46:50 +02:00
checkbox_part +
2010-09-09 14:50:10 +02:00
icon_part +
2010-09-09 20:01:35 +02:00
"<a target=\"_blank\" href=\""+article.link+"\""+
2011-09-01 08:15:37 +02:00
"onclick=\"return view("+article.id+")\" class='title'>" +
2010-09-09 20:01:35 +02:00
article.title + "</a>" +
2011-09-01 08:15:37 +02:00
"<div class='body'>" +
2011-09-01 14:46:50 +02:00
"<div onclick=\"view("+article.id+")\" class='excerpt'>" +
2010-09-10 11:59:21 +02:00
article.excerpt + "</div>" +
2012-11-07 09:40:52 +01:00
"<div onclick=\"view("+article.id+")\" class='info'>";
2011-09-01 14:46:50 +02:00
/* tmp_html += "<a href=\#\" onclick=\"viewfeed("+feed.id+")\">" +
feed.title + "</a> " + " @ "; */
tmp_html += date_part + "</div>" +
2010-09-09 19:44:04 +02:00
"</div></li>";
2010-09-09 14:50:10 +02:00
$("headlines-content").innerHTML += tmp_html;
2010-09-12 17:36:59 +02:00
if (!no_effects)
window.setTimeout('article_appear(' + article.id + ')', 100);
2010-09-09 14:50:10 +02:00
} catch (e) {
exception_error("add_headline_entry", e);
}
}
2010-09-12 09:05:03 +02:00
function expand_feeds() {
try {
_feedlist_expanded = true;
redraw_feedlist(last_feeds);
} catch (e) {
exception_error("expand_feeds", e);
}
}
function redraw_feedlist(feeds) {
try {
$('feeds-content').innerHTML = "";
var limit = 10;
if (_feedlist_expanded) limit = feeds.length;
for (var i = 0; i < Math.min(limit, feeds.length); i++) {
add_feed_entry(feeds[i]);
}
if (feeds.length > limit) {
$('feeds-content').innerHTML += "<li id='F-MORE-PROMPT'>" +
2011-09-01 08:15:37 +02:00
"<img src='images/blank_icon.gif'>" +
2010-09-12 09:05:03 +02:00
"<a href=\"#\" onclick=\"expand_feeds()\">" +
2011-09-01 08:15:37 +02:00
__("%d more...").replace("%d", feeds.length-10) +
2010-09-12 09:05:03 +02:00
"</a>" + "</li>";
}
2010-11-25 12:21:20 +01:00
if (feeds.length == 0) {
2011-09-01 08:15:37 +02:00
$('feeds-content').innerHTML =
"<div class='insensitive' style='text-align : center'>" +
2010-11-25 12:39:06 +01:00
__("No unread feeds.") + "</div>";
2010-11-25 12:21:20 +01:00
}
2011-09-01 14:46:50 +02:00
if (_active_feed_id)
set_selected_feed(_active_feed_id);
2010-09-12 09:05:03 +02:00
} catch (e) {
exception_error("redraw_feedlist", e);
}
}
2010-09-11 13:25:47 +02:00
function parse_feeds(transport) {
try {
2010-11-25 12:21:20 +01:00
var reply = JSON.parse(transport.responseText);
2010-09-11 13:25:47 +02:00
2010-11-25 12:21:20 +01:00
if (!reply) return;
2010-09-12 09:05:03 +02:00
2010-11-25 12:21:20 +01:00
var feeds = reply['feeds'];
2010-09-11 13:25:47 +02:00
if (feeds) {
2011-09-01 08:15:37 +02:00
feeds.sort( function (a,b)
{
if (b.unread != a.unread)
2011-12-10 18:26:59 +01:00
return (b.unread - a.unread);
else
if (a.title > b.title)
return 1;
else if (a.title < b.title)
return -1;
else
2011-09-01 08:15:37 +02:00
return 0;
});
var all_articles = find_feed(feeds, -4);
update_title(all_articles.unread);
2010-09-11 13:25:47 +02:00
last_feeds = feeds;
2010-09-12 09:05:03 +02:00
redraw_feedlist(feeds);
2010-09-11 13:25:47 +02:00
}
} catch (e) {
exception_error("parse_feeds", e);
}
}
2010-09-12 17:36:59 +02:00
function parse_headlines(transport, replace, no_effects) {
2010-09-11 13:25:47 +02:00
try {
2010-11-25 12:21:20 +01:00
var reply = JSON.parse(transport.responseText);
if (!reply) return;
2010-09-12 09:05:03 +02:00
2010-11-25 12:21:20 +01:00
var seq = reply['seq'];
if (seq) {
if (seq != _update_seq) {
console.log("parse_headlines: wrong sequence received.");
return;
}
} else {
return;
}
2010-11-25 12:21:20 +01:00
var headlines = reply['headlines']['content'];
var headlines_title = reply['headlines']['title'];
2010-09-11 13:25:47 +02:00
2010-09-12 12:37:47 +02:00
if (headlines && headlines_title) {
2010-09-12 12:50:45 +02:00
if (replace) {
$('headlines-content').innerHTML = '';
}
2010-09-11 13:25:47 +02:00
2010-09-12 09:05:03 +02:00
var pr = $('H-MORE-PROMPT');
2010-09-11 13:25:47 +02:00
if (pr) pr.parentNode.removeChild(pr);
2010-09-12 12:50:45 +02:00
var inserted = false;
2010-09-11 13:25:47 +02:00
for (var i = 0; i < headlines.length; i++) {
2011-09-01 08:15:37 +02:00
2010-09-11 13:25:47 +02:00
if (!$('A-' + headlines[i].id)) {
2011-09-01 08:15:37 +02:00
add_headline_entry(headlines[i],
2010-09-12 17:36:59 +02:00
find_feed(last_feeds, headlines[i].feed_id), !no_effects);
2010-09-12 12:50:45 +02:00
2010-09-11 13:25:47 +02:00
}
}
2011-09-01 14:46:50 +02:00
console.log(inserted.id);
var ids = get_visible_article_ids();
if (ids.length > 0) {
if (pr) {
$('headlines-content').appendChild(pr);
2011-09-01 14:46:50 +02:00
} else {
$('headlines-content').innerHTML += "<li id='H-MORE-PROMPT'>" +
"<div class='body'>" +
"<a href=\"#\" onclick=\"catchup_visible_articles()\">" +
2011-09-01 08:15:37 +02:00
__("Mark as read") + "</a> | " +
"<a href=\"javascript:load_more()\">" +
__("Load more...") + "</a>" +
"<img style=\"display : none\" "+
2010-09-12 18:29:10 +02:00
"id=\"H-LOADING-IMG\" src='images/indicator_tiny.gif'>" +
"</div></li>";
}
} else {
// FIXME : display some kind of "nothing to see here" prompt here
2010-09-11 13:25:47 +02:00
}
2011-09-01 14:46:50 +02:00
// if (replace && !no_effects)
// new Effect.Appear('headlines-content', {duration : 0.3});
2010-09-12 12:50:45 +02:00
//new Effect.Appear('headlines-content');
2010-09-11 13:25:47 +02:00
}
} catch (e) {
exception_error("parse_headlines", e);
}
}
function init_second_stage() {
2010-09-09 14:50:10 +02:00
try {
new Ajax.Request("backend.php", {
2012-12-24 07:16:01 +01:00
parameters: "backend.php?op=digest&method=digestinit",
2010-09-09 14:50:10 +02:00
onComplete: function(transport) {
2010-09-11 13:25:47 +02:00
parse_feeds(transport);
2011-09-01 14:46:50 +02:00
Element.hide("overlay");
2012-11-07 09:40:52 +01:00
document.onkeydown = hotkey_handler;
2010-09-09 19:44:04 +02:00
window.setTimeout('viewfeed(-4)', 100);
2010-09-11 13:25:47 +02:00
_update_timeout = window.setTimeout('update()', 5*1000);
2010-09-09 14:50:10 +02:00
} });
} catch (e) {
exception_error("init_second_stage", e);
}
}
function init() {
try {
dojo.require("dijit.Dialog");
new Ajax.Request("backend.php", {
2012-11-06 17:02:00 +01:00
parameters: {op: "rpc", method: "sanityCheck"},
2011-09-01 08:15:37 +02:00
onComplete: function(transport) {
backend_sanity_check_callback(transport);
} });
2010-09-09 14:50:10 +02:00
} catch (e) {
exception_error("digest_init", e);
}
}
2010-11-13 23:41:27 +01:00
function toggle_mark(img, id) {
try {
2011-12-12 19:46:25 +01:00
var query = "?op=rpc&id=" + id + "&method=mark";
2010-11-13 23:41:27 +01:00
if (!img) return;
2010-11-13 23:41:27 +01:00
if (img.src.match("mark_unset")) {
img.src = img.src.replace("mark_unset", "mark_set");
img.alt = __("Unstar article");
query = query + "&mark=1";
} else {
2010-11-13 23:41:27 +01:00
img.src = img.src.replace("mark_set", "mark_unset");
img.alt = __("Star article");
query = query + "&mark=0";
}
new Ajax.Request("backend.php", {
parameters: query,
2011-09-01 08:15:37 +02:00
onComplete: function(transport) {
update();
} });
} catch (e) {
exception_error("toggle_mark", e);
}
}
2010-11-13 23:41:27 +01:00
function toggle_pub(img, id, note) {
try {
2011-12-12 19:46:25 +01:00
var query = "?op=rpc&id=" + id + "&method=publ";
2011-09-01 08:15:37 +02:00
if (note != undefined) {
query = query + "&note=" + param_escape(note);
} else {
query = query + "&note=undefined";
}
2010-11-13 23:41:27 +01:00
if (!img) return;
2010-11-13 23:41:27 +01:00
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 {
2010-11-13 23:41:27 +01:00
img.src = img.src.replace("pub_set", "pub_unset");
img.alt = __("Publish article");
query = query + "&pub=0";
}
new Ajax.Request("backend.php", {
parameters: query,
2011-09-01 08:15:37 +02:00
onComplete: function(transport) {
update();
} });
} catch (e) {
exception_error("toggle_pub", e);
}
}
function fatal_error(code, msg) {
2011-09-01 08:15:37 +02:00
try {
if (code == 6) {
window.location.href = "digest.php";
} else if (code == 5) {
window.location.href = "db-updater.php";
} else {
2011-09-01 08:15:37 +02:00
if (msg == "") msg = "Unknown error";
2011-09-01 08:15:37 +02:00
console.error("Fatal error: " + code + "\n" +
msg);
2011-09-01 08:15:37 +02:00
}
} catch (e) {
exception_error("fatalError", e);
}
}
function fatal_error_check(transport) {
try {
if (transport.responseXML) {
var error = transport.responseXML.getElementsByTagName("error")[0];
if (error) {
var code = error.getAttribute("error-code");
var msg = error.getAttribute("error-msg");
if (code != 0) {
fatal_error(code, msg);
return false;
}
}
}
} catch (e) {
exception_error("fatal_error_check", e);
}
return true;
}
function update_title(unread) {
try {
document.title = "Tiny Tiny RSS";
if (unread > 0)
document.title += " (" + unread + ")";
} catch (e) {
exception_error("update_title", e);
}
}
2011-09-01 14:46:50 +02:00
function toggle_select_article(elem) {
try {
var article = elem.parentNode;
if (article.hasClassName("selected"))
article.removeClassName("selected");
else
article.addClassName("selected");
} catch (e) {
exception_error("toggle_select_article", e);
}
}
2012-11-07 09:40:52 +01:00
function hotkey_handler(e) {
try {
if (e.target.nodeName == "INPUT" || e.target.nodeName == "TEXTAREA") return;
var keycode = false;
var shift_key = false;
var cmdline = $('cmdline');
try {
shift_key = e.shiftKey;
} catch (e) {
}
if (window.event) {
keycode = window.event.keyCode;
} else if (e) {
keycode = e.which;
}
var keychar = String.fromCharCode(keycode);
if (keycode == 16) return; // ignore lone shift
if (keycode == 17) return; // ignore lone ctrl
switch (keycode) {
case 27: // esc
close_article();
break;
default:
console.log("KP: CODE=" + keycode + " CHAR=" + keychar);
}
} catch (e) {
exception_error("hotkey_handler", e);
}
}