code cleanup

master
Andrew Dolgov 14 years ago
parent f1e4d924c9
commit d5d5632952

@ -117,6 +117,7 @@ a:hover {
#feeds ul#feeds-content li { #feeds ul#feeds-content li {
margin : 0px 0px 2px 0px; margin : 0px 0px 2px 0px;
padding : 2px; padding : 2px;
clear : both;
} }
#feeds ul#feeds-content li.selected { #feeds ul#feeds-content li.selected {
@ -181,10 +182,6 @@ a:hover {
clear : left; clear : left;
} }
#headlines ul#headlines-content li:hover {
background : #fafafa;
}
#headlines ul#headlines-content a.title { #headlines ul#headlines-content a.title {
font-weight : bold; font-weight : bold;
font-size : 16px; font-size : 16px;

@ -4,7 +4,23 @@ var _active_feed_id = false;
var _active_feed_offset = false; var _active_feed_offset = false;
var _update_timeout = false; var _update_timeout = false;
function mark_selected_feed(feed_id) { function catchup_article(article_id, callback) {
try {
var query = "?op=rpc&subop=catchupSelected" +
"&cmode=0&ids=" + article_id;
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
if (callback) callback(transport);
} });
} catch (e) {
exception_error("catchup_article", e);
}
}
function set_selected_feed(feed_id) {
try { try {
var feeds = $("feeds-content").getElementsByTagName("LI"); var feeds = $("feeds-content").getElementsByTagName("LI");
@ -15,6 +31,8 @@ function mark_selected_feed(feed_id) {
feeds[i].className = ""; feeds[i].className = "";
} }
_active_feed_id = feed_id;
} catch (e) { } catch (e) {
exception_error("mark_selected_feed", e); exception_error("mark_selected_feed", e);
} }
@ -36,14 +54,8 @@ function zoom(article_id) {
} }
} }
var query = "backend.php?op=rpc&subop=digest-mark&article_id=" + article_id; catchup_article(article_id,
function() { update(); });
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
window.clearTimeout(_update_timeout);
_update_timeout = window.setTimeout('update()', 1000);
} });
} catch (e) { } catch (e) {
exception_error("zoom", e); exception_error("zoom", e);
@ -52,13 +64,6 @@ function zoom(article_id) {
function load_more() { function load_more() {
try { try {
var elem = $('MORE-PROMPT');
if (elem) {
elem.id = '';
Element.hide(elem);
}
viewfeed(_active_feed_id, _active_feed_offset + 10); viewfeed(_active_feed_id, _active_feed_offset + 10);
} catch (e) { } catch (e) {
exception_error("load_more", e); exception_error("load_more", e);
@ -67,30 +72,42 @@ function load_more() {
function update() { function update() {
try { try {
viewfeed(_active_feed_id, _active_feed_offset); console.log('updating feeds...');
window.clearTimeout(_update_timeout);
new Ajax.Request("backend.php", {
parameters: "?op=rpc&subop=digest-init",
onComplete: function(transport) {
parse_feeds(transport);
set_selected_feed(_active_feed_id);
} });
_update_timeout = window.setTimeout('update()', 5*1000);
} catch (e) { } catch (e) {
exception_error("update", e); exception_error("update", e);
} }
} }
function view(article_id, dismiss_only) { function remove_headline_entry(article_id) {
try { try {
var elem = $('A-' + article_id); var elem = $('A-' + article_id);
elem.id = ''; if (elem) {
elem.parentNode.removeChild(elem);
//new Effect.Fade(elem, {duration : 0.3}); }
Element.hide(elem); } catch (e) {
exception_error("remove_headline_entry", e);
}
}
var query = "backend.php?op=rpc&subop=digest-mark&article_id=" + article_id; function view(article_id, dismiss_only) {
try {
remove_headline_entry(article_id);
new Ajax.Request("backend.php", { catchup_article(article_id,
parameters: query, function() { update(); });
onComplete: function(transport) {
window.clearTimeout(_update_timeout);
_update_timeout = window.setTimeout('update()', 1000);
} });
return dismiss_only != true; return dismiss_only != true;
} catch (e) { } catch (e) {
@ -103,23 +120,21 @@ function viewfeed(feed_id, offset) {
if (!feed_id) feed_id = _active_feed_id; if (!feed_id) feed_id = _active_feed_id;
if (!offset) if (!offset) {
offset = 0; offset = 0;
else } else {
offset = _active_feed_offset + offset; offset = _active_feed_offset + offset;
}
var query = "backend.php?op=rpc&subop=digest-update&feed_id=" + feed_id + var query = "backend.php?op=rpc&subop=digest-update&feed_id=" + feed_id +
"&offset=" + offset; "&offset=" + offset;
console.log(query);
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: query, parameters: query,
onComplete: function(transport) { onComplete: function(transport) {
digest_update(transport, feed_id); parse_headlines(transport, offset == 0);
_active_feed_id = feed_id; set_selected_feed(feed_id);
_active_feed_offset = offset; _active_feed_offset = offset;
mark_selected_feed(feed_id);
} }); } });
} catch (e) { } catch (e) {
@ -175,6 +190,8 @@ function get_feed_icon(feed) {
if (feed.id < -10) if (feed.id < -10)
return 'images/label.png'; return 'images/label.png';
return 'images/blank_icon.gif';
} catch (e) { } catch (e) {
exception_error("get_feed_icon", e); exception_error("get_feed_icon", e);
} }
@ -199,24 +216,12 @@ function add_feed_entry(feed) {
} }
} }
function add_latest_entry(article, feed) {
try {
//$("latest-content").innerHTML += "bbb";
} catch (e) {
exception_error("add_latest_entry", e);
}
}
function add_headline_entry(article, feed) { function add_headline_entry(article, feed) {
try { try {
var icon_part = ""; var icon_part = "";
if (article.has_icon) icon_part = "<img class='icon' src='" + get_feed_icon(feed) + "'/>";
icon_part = "<img class='icon' src='icons/" + article.feed_id + ".ico'/>";
var tmp_html = "<li id=\"A-"+article.id+"\">" + var tmp_html = "<li id=\"A-"+article.id+"\">" +
icon_part + icon_part +
@ -245,7 +250,66 @@ function add_headline_entry(article, feed) {
} }
} }
function digest_update(transport, feed_id) { function parse_feeds(transport) {
try {
var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
if (feeds) {
feeds = eval("(" + feeds.firstChild.nodeValue + ")");
last_feeds = feeds;
$('feeds-content').innerHTML = "";
for (var i = 0; i < feeds.length; i++) {
add_feed_entry(feeds[i]);
}
}
} catch (e) {
exception_error("parse_feeds", e);
}
}
function parse_headlines(transport, replace) {
try {
var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
if (headlines) {
headlines = eval("(" + headlines.firstChild.nodeValue + ")");
if (replace) $('headlines-content').innerHTML = '';
var pr = $('MORE-PROMPT');
if (pr) pr.parentNode.removeChild(pr);
for (var i = 0; i < headlines.length; i++) {
if (!$('A-' + headlines[i].id)) {
add_headline_entry(headlines[i],
find_feed(last_feeds, headlines[i].feed_id));
}
}
if (pr) {
$('headlines-content').appendChild(pr);
} else {
$('headlines-content').innerHTML += "<li id='MORE-PROMPT'>" +
"<div class='body'><a href=\"javascript:load_more()\">" +
__("More articles...") + "</a></div></li>";
}
new Effect.Appear('headlines-content');
}
} catch (e) {
exception_error("parse_headlines", e);
}
}
/*function digest_update(transport, feed_id, offset) {
try { try {
var feeds = transport.responseXML.getElementsByTagName('feeds')[0]; var feeds = transport.responseXML.getElementsByTagName('feeds')[0];
var headlines = transport.responseXML.getElementsByTagName('headlines')[0]; var headlines = transport.responseXML.getElementsByTagName('headlines')[0];
@ -267,11 +331,9 @@ function digest_update(transport, feed_id) {
if (headlines) { if (headlines) {
headlines = eval("(" + headlines.firstChild.nodeValue + ")"); headlines = eval("(" + headlines.firstChild.nodeValue + ")");
if (_active_feed_id != feed_id) if (_active_feed_id != feed_id || !offset)
$('headlines-content').innerHTML = ""; $('headlines-content').innerHTML = "";
//Element.hide('headlines-content');
var pr = $('MORE-PROMPT'); var pr = $('MORE-PROMPT');
if (pr) { if (pr) {
@ -283,7 +345,8 @@ function digest_update(transport, feed_id) {
var elem = $('A-' + headlines[i].id); var elem = $('A-' + headlines[i].id);
if (elem && Element.visible(elem)) { if (elem && Element.visible(elem)) {
if (!headlines[i].unread)
remove_headline_entry(headlines[i].id);
} else { } else {
add_headline_entry(headlines[i], find_feed(feeds, headlines[i].feed_id)); add_headline_entry(headlines[i], find_feed(feeds, headlines[i].feed_id));
@ -295,22 +358,30 @@ function digest_update(transport, feed_id) {
__("More articles...") + "</a></div></li>"; __("More articles...") + "</a></div></li>";
new Effect.Appear('headlines-content'); new Effect.Appear('headlines-content');
}
if (feed_id != undefined) {
_active_feed_id = feed_id;
} }
if (offset != undefined) _active_feed_offset = offset;
mark_selected_feed(_active_feed_id);
} catch (e) { } catch (e) {
exception_error("digest_update", e); exception_error("digest_update", e);
} }
} } */
function digest_init() { function init() {
try { try {
new Ajax.Request("backend.php", { new Ajax.Request("backend.php", {
parameters: "backend.php?op=rpc&subop=digest-init", parameters: "backend.php?op=rpc&subop=digest-init",
onComplete: function(transport) { onComplete: function(transport) {
digest_update(transport, -4); parse_feeds(transport);
window.setTimeout('viewfeed(-4)', 100); window.setTimeout('viewfeed(-4)', 100);
_update_timeout = window.setTimeout('update()', 5*1000);
} }); } });
} catch (e) { } catch (e) {
@ -363,9 +434,6 @@ function toggleMark(mark_img, id) {
if (!mark_img) return; if (!mark_img) return;
var vfeedu = $("FEEDU--1");
var crow = $("RROW-" + id);
if (mark_img.src.match("mark_unset")) { if (mark_img.src.match("mark_unset")) {
mark_img.src = mark_img.src.replace("mark_unset", "mark_set"); mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
mark_img.alt = __("Unstar article"); mark_img.alt = __("Unstar article");

@ -45,7 +45,7 @@
<script type="text/javascript"> <script type="text/javascript">
Event.observe(window, 'load', function() { Event.observe(window, 'load', function() {
digest_init(); init();
}); });
</script> </script>
</head> </head>

@ -6782,7 +6782,6 @@
"title" => $line["title"], "title" => $line["title"],
"link" => $line["link"], "link" => $line["link"],
"feed_id" => $line["feed_id"], "feed_id" => $line["feed_id"],
"has_icon" => feed_has_icon($line["feed_id"])
); );
if ($show_excerpt) { if ($show_excerpt) {

Loading…
Cancel
Save