3 var _active_feed_id = false;
4 var _active_feed_offset = false;
5 var _update_timeout = false;
7 function zoom(article_id) {
9 var elem = $('A-' + article_id);
12 var divs = elem.getElementsByTagName('DIV');
14 for (var i = 0; i < divs.length; i++) {
15 if (divs[i].className == 'excerpt')
16 Element.hide(divs[i]);
18 if (divs[i].className == 'content')
19 Element.show(divs[i]);
23 var query = "backend.php?op=rpc&subop=digest-mark&article_id=" + article_id;
25 new Ajax.Request("backend.php", {
27 onComplete: function(transport) {
28 window.clearTimeout(_update_timeout);
29 _update_timeout = window.setTimeout('update()', 1000);
33 exception_error("zoom", e);
37 function load_more() {
39 var elem = $('MORE-PROMPT');
46 viewfeed(_active_feed_id, _active_feed_offset + 10);
48 exception_error("load_more", e);
54 viewfeed(_active_feed_id, _active_feed_offset);
56 exception_error("update", e);
60 function view(article_id, dismiss_only) {
62 var elem = $('A-' + article_id);
66 //new Effect.Fade(elem, {duration : 0.3});
70 var query = "backend.php?op=rpc&subop=digest-mark&article_id=" + article_id;
72 new Ajax.Request("backend.php", {
74 onComplete: function(transport) {
75 window.clearTimeout(_update_timeout);
76 _update_timeout = window.setTimeout('update()', 1000);
79 return dismiss_only != true;
81 exception_error("view", e);
85 function viewfeed(feed_id, offset) {
88 if (!feed_id) feed_id = _active_feed_id;
93 offset = _active_feed_offset + offset;
95 var query = "backend.php?op=rpc&subop=digest-update&feed_id=" + feed_id +
100 new Ajax.Request("backend.php", {
102 onComplete: function(transport) {
103 digest_update(transport, feed_id);
104 _active_feed_id = feed_id;
105 _active_feed_offset = offset;
109 exception_error("view", e);
113 function find_article(articles, article_id) {
115 for (var i = 0; i < articles.length; i++) {
116 if (articles[i].id == article_id)
123 exception_error("find_article", e);
127 function find_feed(feeds, feed_id) {
129 for (var i = 0; i < feeds.length; i++) {
130 if (feeds[i].id == feed_id)
137 exception_error("find_feed", e);
141 function get_feed_icon(feed) {
144 return 'icons/' + feed.id + '.ico';
147 return 'images/mark_set.png';
150 return 'images/pub_set.png';
153 return 'images/fresh.png';
156 return 'images/tag.png';
159 return 'images/label.png';
162 exception_error("get_feed_icon", e);
166 function add_feed_entry(feed) {
170 icon_part = "<img src='" + get_feed_icon(feed) + "'/>";
172 var tmp_html = "<li>" +
174 "<a href=\"#\" onclick=\"viewfeed("+feed.id+")\">" + feed.title +
175 "<div class='unread-ctr'>" + feed.unread + "</div>" +
178 $("feeds-content").innerHTML += tmp_html;
181 exception_error("add_feed_entry", e);
185 function add_latest_entry(article, feed) {
189 //$("latest-content").innerHTML += "bbb";
192 exception_error("add_latest_entry", e);
196 function add_headline_entry(article, feed) {
201 if (article.has_icon)
202 icon_part = "<img src='icons/" + article.feed_id + ".ico'/>";
204 var tmp_html = "<li id=\"A-"+article.id+"\">" +
206 "<div class='digest-check'>" +
207 "<img title='Set starred' onclick=\"toggleMark(this, "+article.id+")\" src='images/mark_unset.png'>" +
208 "<img title='Set published' onclick=\"togglePub(this, "+article.id+")\" src='images/pub_unset.png'>" +
209 "<img title='Dismiss' onclick=\"view("+article.id+", true)\" class='digest-check' src='images/digest_checkbox.png'>" +
211 "<a target=\"_blank\" href=\""+article.link+"\""+
212 "onclick=\"return view("+article.id+")\" class='title'>" +
213 article.title + "</a>" +
214 "<div class='body'>" +
215 "<div title=\"Click to expand article\" onclick=\"zoom("+article.id+")\" class='excerpt'>" +
216 article.excerpt + "</div>" +
217 "<div style='display : none' class='content'>" +
218 article.content + "</div>" +
219 "<div class='info'><a href=\#\" onclick=\"viewfeed("+feed.id+")\">" +
220 feed.title + "</a> " + " @ " +
221 new Date(article.updated * 1000) + "</div>" +
224 $("headlines-content").innerHTML += tmp_html;
227 exception_error("add_headline_entry", e);
231 function digest_update(transport, feed_id) {
233 var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
234 var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
237 feeds = eval("(" + feeds.firstChild.nodeValue + ")");
241 $('feeds-content').innerHTML = "";
243 for (var i = 0; i < feeds.length; i++) {
244 add_feed_entry(feeds[i]);
251 headlines = eval("(" + headlines.firstChild.nodeValue + ")");
253 if (_active_feed_id != feed_id)
254 $('headlines-content').innerHTML = "";
256 //Element.hide('headlines-content');
258 var pr = $('MORE-PROMPT');
265 for (var i = 0; i < headlines.length; i++) {
266 var elem = $('A-' + headlines[i].id);
268 if (elem && Element.visible(elem)) {
272 add_headline_entry(headlines[i], find_feed(feeds, headlines[i].feed_id));
276 $('headlines-content').innerHTML += "<li id='MORE-PROMPT'>" +
277 "<div class='body'><a href=\"#\" onclick=\"load_more()\">" +
278 __("More articles...") + "</a></div></li>";
280 new Effect.Appear('headlines-content');
285 exception_error("digest_update", e);
289 function digest_init() {
292 new Ajax.Request("backend.php", {
293 parameters: "backend.php?op=rpc&subop=digest-init",
294 onComplete: function(transport) {
295 digest_update(transport, -4);
296 window.setTimeout('viewfeed(-4)', 100);
300 exception_error("digest_init", e);
304 function tMark_afh_off(effect) {
306 var elem = effect.effects[0].element;
308 console.log("tMark_afh_off : " + elem.id);
311 elem.src = elem.src.replace("mark_set", "mark_unset");
312 elem.alt = __("Star article");
317 exception_error("tMark_afh_off", e);
321 function tPub_afh_off(effect) {
323 var elem = effect.effects[0].element;
325 console.log("tPub_afh_off : " + elem.id);
328 elem.src = elem.src.replace("pub_set", "pub_unset");
329 elem.alt = __("Publish article");
334 exception_error("tPub_afh_off", e);
338 function toggleMark(mark_img, id) {
342 var query = "?op=rpc&id=" + id + "&subop=mark";
344 query = query + "&afid=" + _active_feed_id;
345 query = query + "&omode=c";
347 if (!mark_img) return;
349 var vfeedu = $("FEEDU--1");
350 var crow = $("RROW-" + id);
352 if (mark_img.src.match("mark_unset")) {
353 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
354 mark_img.alt = __("Unstar article");
355 query = query + "&mark=1";
357 mark_img.alt = __("Please wait...");
358 query = query + "&mark=0";
360 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
361 mark_img.alt = __("Star article");
364 new Ajax.Request("backend.php", {
366 onComplete: function(transport) {
371 exception_error("toggleMark", e);
375 function togglePub(mark_img, id, note) {
379 var query = "?op=rpc&id=" + id + "&subop=publ";
381 query = query + "&afid=" + _active_feed_id;
383 if (note != undefined) {
384 query = query + "¬e=" + param_escape(note);
386 query = query + "¬e=undefined";
389 query = query + "&omode=c";
391 if (!mark_img) return;
393 if (mark_img.src.match("pub_unset") || note != undefined) {
394 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
395 mark_img.alt = __("Unpublish article");
396 query = query + "&pub=1";
399 mark_img.alt = __("Please wait...");
400 query = query + "&pub=0";
402 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
403 mark_img.alt = __("Publish article");
406 new Ajax.Request("backend.php", {
408 onComplete: function(transport) {
413 exception_error("togglePub", e);