consolidate counter parsing code
This commit is contained in:
parent
c3d74dca93
commit
1a6a9555ff
2 changed files with 58 additions and 77 deletions
104
functions.js
104
functions.js
|
@ -344,6 +344,61 @@ if (!xmlhttp_rpc && typeof XMLHttpRequest!='undefined') {
|
||||||
xmlhttp_rpc = new XMLHttpRequest();
|
xmlhttp_rpc = new XMLHttpRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parse_counters(reply, f_document) {
|
||||||
|
try {
|
||||||
|
for (var l = 0; l < reply.childNodes.length; l++) {
|
||||||
|
var id = reply.childNodes[l].getAttribute("id");
|
||||||
|
var t = reply.childNodes[l].getAttribute("type");
|
||||||
|
var ctr = reply.childNodes[l].getAttribute("counter");
|
||||||
|
|
||||||
|
if (id == "global-unread") {
|
||||||
|
parent.global_unread = ctr;
|
||||||
|
parent.updateTitle();
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (t == "category") {
|
||||||
|
var catctr = f_document.getElementById("FCATCTR-" + id);
|
||||||
|
if (catctr) {
|
||||||
|
catctr.innerHTML = "(" + ctr + " unread)";
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var feedctr = f_document.getElementById("FEEDCTR-" + id);
|
||||||
|
var feedu = f_document.getElementById("FEEDU-" + id);
|
||||||
|
var feedr = f_document.getElementById("FEEDR-" + id);
|
||||||
|
|
||||||
|
if (feedctr && feedu && feedr) {
|
||||||
|
|
||||||
|
feedu.innerHTML = ctr;
|
||||||
|
|
||||||
|
if (ctr > 0) {
|
||||||
|
feedctr.className = "odd";
|
||||||
|
if (!feedr.className.match("Unread")) {
|
||||||
|
var is_selected = feedr.className.match("Selected");
|
||||||
|
|
||||||
|
feedr.className = feedr.className.replace("Selected", "");
|
||||||
|
feedr.className = feedr.className.replace("Unread", "");
|
||||||
|
|
||||||
|
feedr.className = feedr.className + "Unread";
|
||||||
|
|
||||||
|
if (is_selected) {
|
||||||
|
feedr.className = feedr.className + "Selected";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
feedctr.className = "invisible";
|
||||||
|
feedr.className = feedr.className.replace("Unread", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
exception_error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function all_counters_callback() {
|
function all_counters_callback() {
|
||||||
if (xmlhttp_rpc.readyState == 4) {
|
if (xmlhttp_rpc.readyState == 4) {
|
||||||
try {
|
try {
|
||||||
|
@ -353,57 +408,10 @@ function all_counters_callback() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var reply = xmlhttp_rpc.responseXML.firstChild;
|
var reply = xmlhttp_rpc.responseXML.firstChild;
|
||||||
|
|
||||||
var f_document = parent.frames["feeds-frame"].document;
|
var f_document = parent.frames["feeds-frame"].document;
|
||||||
|
|
||||||
for (var l = 0; l < reply.childNodes.length; l++) {
|
|
||||||
var id = reply.childNodes[l].getAttribute("id");
|
|
||||||
var t = reply.childNodes[l].getAttribute("type");
|
|
||||||
var ctr = reply.childNodes[l].getAttribute("counter");
|
|
||||||
|
|
||||||
if (id == "global-unread") {
|
parse_counters(reply, f_document);
|
||||||
parent.global_unread = ctr;
|
|
||||||
parent.updateTitle();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (t == "category") {
|
|
||||||
var catctr = f_document.getElementById("FCATCTR-" + id);
|
|
||||||
if (catctr) {
|
|
||||||
catctr.innerHTML = "(" + ctr + " unread)";
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var feedctr = f_document.getElementById("FEEDCTR-" + id);
|
|
||||||
var feedu = f_document.getElementById("FEEDU-" + id);
|
|
||||||
var feedr = f_document.getElementById("FEEDR-" + id);
|
|
||||||
|
|
||||||
if (feedctr && feedu && feedr) {
|
|
||||||
|
|
||||||
feedu.innerHTML = ctr;
|
|
||||||
|
|
||||||
if (ctr > 0) {
|
|
||||||
feedctr.className = "odd";
|
|
||||||
if (!feedr.className.match("Unread")) {
|
|
||||||
var is_selected = feedr.className.match("Selected");
|
|
||||||
|
|
||||||
feedr.className = feedr.className.replace("Selected", "");
|
|
||||||
feedr.className = feedr.className.replace("Unread", "");
|
|
||||||
|
|
||||||
feedr.className = feedr.className + "Unread";
|
|
||||||
|
|
||||||
if (is_selected) {
|
|
||||||
feedr.className = feedr.className + "Selected";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
feedctr.className = "invisible";
|
|
||||||
feedr.className = feedr.className.replace("Unread", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
exception_error("all_counters_callback", e);
|
exception_error("all_counters_callback", e);
|
||||||
}
|
}
|
||||||
|
|
31
tt-rss.js
31
tt-rss.js
|
@ -92,35 +92,8 @@ function refetch_callback() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var f_document = window.frames["feeds-frame"].document;
|
var f_document = window.frames["feeds-frame"].document;
|
||||||
|
|
||||||
for (var l = 0; l < reply.childNodes.length; l++) {
|
parse_counters(reply, f_document);
|
||||||
var id = reply.childNodes[l].getAttribute("id");
|
|
||||||
var ctr = reply.childNodes[l].getAttribute("counter");
|
|
||||||
|
|
||||||
var feedctr = f_document.getElementById("FEEDCTR-" + id);
|
|
||||||
var feedu = f_document.getElementById("FEEDU-" + id);
|
|
||||||
var feedr = f_document.getElementById("FEEDR-" + id);
|
|
||||||
|
|
||||||
if (id == "global-unread") {
|
|
||||||
global_unread = ctr;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (feedctr && feedu && feedr) {
|
|
||||||
|
|
||||||
feedu.innerHTML = ctr;
|
|
||||||
|
|
||||||
if (ctr > 0) {
|
|
||||||
feedctr.className = "odd";
|
|
||||||
if (!feedr.className.match("Unread")) {
|
|
||||||
feedr.className = feedr.className + "Unread";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
feedctr.className = "invisible";
|
|
||||||
feedr.className = feedr.className.replace("Unread", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
updateTitle("");
|
updateTitle("");
|
||||||
notify("All feeds updated.");
|
notify("All feeds updated.");
|
||||||
|
|
Loading…
Reference in a new issue