js: misc fixes, code cleanup

This commit is contained in:
Andrew Dolgov 2010-11-12 13:52:53 +03:00
parent 6bb0ed42f4
commit e69fb880a3
15 changed files with 927 additions and 1252 deletions

28
deprecated.js Normal file
View File

@ -0,0 +1,28 @@
function selectTableRow(r, do_select) {
r.className = r.className.replace("Selected", "");
if (do_select) {
r.className = r.className + "Selected";
}
}
function selectTableRowById(elem_id, check_id, do_select) {
try {
var row = $(elem_id);
if (row) {
selectTableRow(row, do_select);
}
var check = $(check_id);
if (check) {
check.checked = do_select;
}
} catch (e) {
exception_error("selectTableRowById", e);
}
}

View File

@ -13,6 +13,9 @@ var resize_enabled = false;
var selection_disabled = false;
var counters_last_request = 0;
var feeds_sort_by_unread = false;
var feedlist_sortable_enabled = false;
function toggle_sortable_feedlist(enabled) {
try {
@ -656,4 +659,549 @@ function request_counters() {
}
}
function displayNewContentPrompt(id) {
try {
var msg = "<a href='#' onclick='viewfeed("+id+")'>" +
__("New articles available in this feed (click to show)") + "</a>";
msg = msg.replace("%s", getFeedName(id));
$('auxDlg').innerHTML = msg;
new Effect.Appear('auxDlg', {duration : 0.5});
} catch (e) {
exception_error("displayNewContentPrompt", e);
}
}
function parse_counters(reply, scheduled_call) {
try {
var feeds_found = 0;
var elems = JSON.parse(reply.firstChild.nodeValue);
for (var l = 0; l < elems.length; l++) {
var id = elems[l].id
var kind = elems[l].kind;
var ctr = parseInt(elems[l].counter)
var error = elems[l].error;
var has_img = elems[l].has_img;
var updated = elems[l].updated;
var title = elems[l].title;
var xmsg = elems[l].xmsg;
if (id == "global-unread") {
if (ctr > global_unread) {
offlineDownloadStart(1);
}
global_unread = ctr;
updateTitle();
continue;
}
if (id == "subscribed-feeds") {
feeds_found = ctr;
continue;
}
if (kind && kind == "cat") {
var catctr = $("FCATCTR-" + id);
if (catctr) {
catctr.innerHTML = "(" + ctr + ")";
if (ctr > 0) {
catctr.className = "catCtrHasUnread";
} else {
catctr.className = "catCtrNoUnread";
}
}
continue;
}
var feedctr = $("FEEDCTR-" + id);
var feedu = $("FEEDU-" + id);
var feedr = $("FEEDR-" + id);
var feed_img = $("FIMG-" + id);
var feedlink = $("FEEDL-" + id);
var feedupd = $("FLUPD-" + id);
if (updated && feedlink) {
if (error) {
feedlink.title = "Error: " + error + " (" + updated + ")";
} else {
feedlink.title = "Updated: " + updated;
}
}
if (feedupd) {
if (!updated) updated = "";
if (error) {
if (xmsg) {
feedupd.innerHTML = updated + " " + xmsg + " (Error)";
} else {
feedupd.innerHTML = updated + " (Error)";
}
} else {
if (xmsg) {
feedupd.innerHTML = updated + " (" + xmsg + ")";
} else {
feedupd.innerHTML = updated;
}
}
}
if (has_img && feed_img) {
if (!feed_img.src.match(id + ".ico")) {
feed_img.src = getInitParam("icons_url") + "/" + id + ".ico";
}
}
if (feedlink && title) {
feedlink.innerHTML = title;
}
if (feedctr && feedu && feedr) {
// if (id == getActiveFeedId())
// console.log("HAS CTR: " + feedu.innerHTML + " GOT CTR: " + ctr +
// " IS_SCHED: " + scheduled_call);
if (parseInt(ctr) > 0 &&
parseInt(feedu.innerHTML) < parseInt(ctr) &&
id == getActiveFeedId() && scheduled_call) {
displayNewContentPrompt(id);
}
var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
feedu.innerHTML = ctr;
if (error) {
feedr.className = feedr.className.replace("feed", "error");
} else if (id > 0) {
feedr.className = feedr.className.replace("error", "feed");
}
if (ctr > 0) {
feedctr.className = "feedCtrHasUnread";
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";
}
}
if (row_needs_hl &&
!getInitParam("theme_options").match('no_highlights')) {
new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
cache_invalidate("F:" + id);
}
} else {
feedctr.className = "feedCtrNoUnread";
feedr.className = feedr.className.replace("Unread", "");
}
}
}
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
var feeds_stored = number_of_feeds;
//console.log("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
if (feeds_stored != feeds_found) {
number_of_feeds = feeds_found;
if (feeds_stored != 0 && feeds_found != 0) {
console.log("Subscribed feed number changed, refreshing feedlist");
setTimeout('updateFeedList(false, false)', 50);
}
} else {
/* var fl = $("feeds-frame").innerHTML;
if (fl) {
cache_invalidate("FEEDLIST");
cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
} */
}
} catch (e) {
exception_error("parse_counters", e);
}
}
function get_feed_unread(id) {
try {
return parseInt($("FEEDU-" + id).innerHTML);
} catch (e) {
return -1;
}
}
function get_cat_unread(id) {
try {
var ctr = $("FCATCTR-" + id).innerHTML;
ctr = ctr.replace("(", "");
ctr = ctr.replace(")", "");
return parseInt(ctr);
} catch (e) {
return -1;
}
}
function get_feed_entry_unread(elem) {
var id = elem.id.replace("FEEDR-", "");
if (id <= 0) {
return -1;
}
try {
return parseInt($("FEEDU-" + id).innerHTML);
} catch (e) {
return -1;
}
}
function get_feed_entry_name(elem) {
var id = elem.id.replace("FEEDR-", "");
return getFeedName(id);
}
function resort_category(node, cat_mode) {
try {
console.log("resort_category: " + node + " CM=" + cat_mode);
var by_unread = feedsSortByUnread();
var list = node.getElementsByTagName("LI");
for (i = 0; i < list.length; i++) {
for (j = i+1; j < list.length; j++) {
var tmp_val = get_feed_entry_unread(list[i]);
var cur_val = get_feed_entry_unread(list[j]);
var tmp_name = get_feed_entry_name(list[i]);
var cur_name = get_feed_entry_name(list[j]);
/* we don't want to match FEEDR-0 - e.g. Archived articles */
var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[1-9]/) &&
list[j].id.match(/FEEDR-[1-9]/));
if (valid_pair && ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name)))) {
tempnode_i = list[i].cloneNode(true);
tempnode_j = list[j].cloneNode(true);
node.replaceChild(tempnode_i, list[j]);
node.replaceChild(tempnode_j, list[i]);
}
}
}
} catch (e) {
exception_error("resort_category", e);
}
}
function resort_feedlist() {
console.log("resort_feedlist");
if ($("FCATLIST--1")) {
var lists = document.getElementsByTagName("UL");
for (var i = 0; i < lists.length; i++) {
if (lists[i].id && lists[i].id.match("FCATLIST-")) {
resort_category(lists[i], true);
}
}
} else {
resort_category($("feedList"), false);
}
}
function hideOrShowFeeds(hide) {
try {
//console.log("hideOrShowFeeds: " + hide);
if ($("FCATLIST--1")) {
var lists = document.getElementsByTagName("UL");
for (var i = 0; i < lists.length; i++) {
if (lists[i].id && lists[i].id.match("FCATLIST-")) {
var id = lists[i].id.replace("FCATLIST-", "");
hideOrShowFeedsCategory(id, hide);
}
}
} else {
hideOrShowFeedsCategory(null, hide);
}
} catch (e) {
exception_error("hideOrShowFeeds", e);
}
}
function hideOrShowFeedsCategory(id, hide) {
try {
var node = null;
var cat_node = null;
if (id) {
node = $("FCATLIST-" + id);
cat_node = $("FCAT-" + id);
} else {
node = $("feedList"); // no categories
}
// console.log("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
var cat_unread = 0;
if (!node) {
console.warn("hideOrShowFeeds: passed node is null, aborting");
return;
}
// console.log("cat: " + node.id);
if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
for (i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeName != "LI") { continue; }
if (node.childNodes[i].style != undefined) {
var has_unread = (node.childNodes[i].className != "feed" &&
node.childNodes[i].className != "label" &&
!(!getInitParam("hide_read_shows_special") &&
node.childNodes[i].className == "virt") &&
node.childNodes[i].className != "error" &&
node.childNodes[i].className != "tag");
var has_error = node.childNodes[i].className.match("error");
// console.log(node.childNodes[i].id + " --> " + has_unread);
if (hide && !has_unread) {
var id = node.childNodes[i].id;
Effect.Fade(node.childNodes[i], {duration : 0.3,
queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
}
if (!hide) {
Element.show(node.childNodes[i]);
}
if (has_unread) {
Element.show(node.childNodes[i]);
cat_unread++;
}
//if (has_error) Element.hide(node.childNodes[i]);
}
}
}
// console.log("end cat: " + node.id + " unread " + cat_unread);
if (cat_node) {
if (cat_unread == 0) {
if (cat_node.style == undefined) {
console.log("ERROR: supplied cat_node " + cat_node +
" has no styles. WTF?");
return;
}
if (hide) {
//cat_node.style.display = "none";
Effect.Fade(cat_node, {duration : 0.3,
queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
} else {
cat_node.style.display = "list-item";
}
} else {
try {
cat_node.style.display = "list-item";
} catch (e) {
console.log(e);
}
}
}
// console.log("unread for category: " + cat_unread);
} catch (e) {
exception_error("hideOrShowFeedsCategory", e);
}
}
function getFeedName(id, is_cat) {
var e;
if (is_cat) {
e = $("FCATN-" + id);
} else {
e = $("FEEDN-" + id);
}
if (e) {
return e.innerHTML.stripTags();
} else {
return null;
}
}
function getNextUnreadCat(id) {
try {
var rows = $("feedList").getElementsByTagName("LI");
var feeds = new Array();
var unread_only = true;
var is_cat = true;
for (var i = 0; i < rows.length; i++) {
if (rows[i].id.match("FCAT-")) {
if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
if (cat_id >= 0) {
if (!unread_only || get_cat_unread(cat_id) > 0) {
feeds.push(cat_id);
}
}
}
}
}
var idx = feeds.indexOf(id);
if (idx != -1 && idx < feeds.length) {
return feeds[idx+1];
} else {
return feeds.shift();
}
} catch (e) {
exception_error("getNextUnreadCat", e);
}
}
function getRelativeFeedId2(id, is_cat, direction, unread_only) {
try {
// alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
var rows = $("feedList").getElementsByTagName("LI");
var feeds = new Array();
for (var i = 0; i < rows.length; i++) {
if (rows[i].id.match("FEEDR-")) {
if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
if (!unread_only ||
(rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
feeds.push(rows[i].id.replace("FEEDR-", ""));
}
}
}
if (rows[i].id.match("FCAT-")) {
if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
if (cat_id >= 0) {
if (!unread_only || get_cat_unread(cat_id) > 0) {
feeds.push("CAT:"+cat_id);
}
}
}
}
}
// alert(feeds.toString());
if (!id) {
if (direction == "next") {
return feeds.shift();
} else {
return feeds.pop();
}
} else {
if (direction == "next") {
if (is_cat) id = "CAT:" + id;
var idx = feeds.indexOf(id);
if (idx != -1 && idx < feeds.length) {
return feeds[idx+1];
} else {
return getRelativeFeedId2(false, is_cat, direction, unread_only);
}
} else {
if (is_cat) id = "CAT:" + id;
var idx = feeds.indexOf(id);
if (idx > 0) {
return feeds[idx-1];
} else {
return getRelativeFeedId2(false, is_cat, direction, unread_only);
}
}
}
} catch (e) {
exception_error("getRelativeFeedId2", e);
}
}
function clean_feed_selections() {
try {
var feeds = $("feedList").getElementsByTagName("LI");
for (var i = 0; i < feeds.length; i++) {
if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
feeds[i].className = feeds[i].className.replace("Selected", "");
}
if (feeds[i].id && feeds[i].id.match("FCAT-")) {
feeds[i].className = feeds[i].className.replace("Selected", "");
}
}
} catch (e) {
exception_error("clean_feed_selections", e);
}
}
function feedsSortByUnread() {
return feeds_sort_by_unread;
}

View File

@ -107,15 +107,6 @@ function param_unescape(arg) {
return unescape(arg);
}
function delay(gap) {
var then,now;
then=new Date().getTime();
now=then;
while((now-then)<gap) {
now=new Date().getTime();
}
}
var notify_hide_timerid = false;
function hide_notify() {
@ -206,10 +197,6 @@ function notify_info(msg, no_hide) {
notify_real(msg, no_hide, 4);
}
function printLockingError() {
notify_info("Please wait until operation finishes.");
}
function cleanSelected(element) {
var content = $(element);
@ -234,85 +221,6 @@ function getVisibleUnreadHeadlines() {
return rows;
}
function getVisibleHeadlineIds() {
var content = $("headlinesList");
var rows = new Array();
if (!content) return rows;
for (i = 0; i < content.rows.length; i++) {
var row_id = content.rows[i].id.replace("RROW-", "");
if (row_id.length > 0) {
rows.push(row_id);
}
}
return rows;
}
function getFirstVisibleHeadlineId() {
if (isCdmMode()) {
var rows = cdmGetVisibleArticles();
return rows[0];
} else {
var rows = getVisibleHeadlineIds();
return rows[0];
}
}
function getLastVisibleHeadlineId() {
if (isCdmMode()) {
var rows = cdmGetVisibleArticles();
return rows[rows.length-1];
} else {
var rows = getVisibleHeadlineIds();
return rows[rows.length-1];
}
}
function markHeadline(id) {
var row = $("RROW-" + id);
if (row) {
var is_active = false;
if (row.className.match("Active")) {
is_active = true;
}
row.className = row.className.replace("Selected", "");
row.className = row.className.replace("Active", "");
row.className = row.className.replace("Insensitive", "");
if (is_active) {
row.className = row.className = "Active";
}
var check = $("RCHK-" + id);
if (check) {
check.checked = true;
}
row.className = row.className + "Selected";
}
}
function getFeedIds() {
var content = $("feedsList");
var rows = new Array();
for (i = 0; i < content.rows.length; i++) {
var id = content.rows[i].id.replace("FEEDR-", "");
if (id.length > 0) {
rows.push(id);
}
}
return rows;
}
function setCookie(name, value, lifetime, path, domain, secure) {
var d = false;
@ -377,308 +285,6 @@ function gotoExportOpml() {
document.location.href = "opml.php?op=Export";
}
function parse_counters(reply, scheduled_call) {
try {
var feeds_found = 0;
var elems = JSON.parse(reply.firstChild.nodeValue);
for (var l = 0; l < elems.length; l++) {
var id = elems[l].id
var kind = elems[l].kind;
var ctr = parseInt(elems[l].counter)
var error = elems[l].error;
var has_img = elems[l].has_img;
var updated = elems[l].updated;
var title = elems[l].title;
var xmsg = elems[l].xmsg;
if (id == "global-unread") {
if (ctr > global_unread) {
offlineDownloadStart(1);
}
global_unread = ctr;
updateTitle();
continue;
}
if (id == "subscribed-feeds") {
feeds_found = ctr;
continue;
}
if (kind && kind == "cat") {
var catctr = $("FCATCTR-" + id);
if (catctr) {
catctr.innerHTML = "(" + ctr + ")";
if (ctr > 0) {
catctr.className = "catCtrHasUnread";
} else {
catctr.className = "catCtrNoUnread";
}
}
continue;
}
var feedctr = $("FEEDCTR-" + id);
var feedu = $("FEEDU-" + id);
var feedr = $("FEEDR-" + id);
var feed_img = $("FIMG-" + id);
var feedlink = $("FEEDL-" + id);
var feedupd = $("FLUPD-" + id);
if (updated && feedlink) {
if (error) {
feedlink.title = "Error: " + error + " (" + updated + ")";
} else {
feedlink.title = "Updated: " + updated;
}
}
if (feedupd) {
if (!updated) updated = "";
if (error) {
if (xmsg) {
feedupd.innerHTML = updated + " " + xmsg + " (Error)";
} else {
feedupd.innerHTML = updated + " (Error)";
}
} else {
if (xmsg) {
feedupd.innerHTML = updated + " (" + xmsg + ")";
} else {
feedupd.innerHTML = updated;
}
}
}
if (has_img && feed_img) {
if (!feed_img.src.match(id + ".ico")) {
feed_img.src = getInitParam("icons_url") + "/" + id + ".ico";
}
}
if (feedlink && title) {
feedlink.innerHTML = title;
}
if (feedctr && feedu && feedr) {
// if (id == getActiveFeedId())
// console.log("HAS CTR: " + feedu.innerHTML + " GOT CTR: " + ctr +
// " IS_SCHED: " + scheduled_call);
if (parseInt(ctr) > 0 &&
parseInt(feedu.innerHTML) < parseInt(ctr) &&
id == getActiveFeedId() && scheduled_call) {
displayNewContentPrompt(id);
}
var row_needs_hl = (ctr > 0 && ctr > parseInt(feedu.innerHTML));
feedu.innerHTML = ctr;
if (error) {
feedr.className = feedr.className.replace("feed", "error");
} else if (id > 0) {
feedr.className = feedr.className.replace("error", "feed");
}
if (ctr > 0) {
feedctr.className = "feedCtrHasUnread";
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";
}
}
if (row_needs_hl &&
!getInitParam("theme_options").match('no_highlights')) {
new Effect.Highlight(feedr, {duration: 1, startcolor: "#fff7d5",
queue: { position:'end', scope: 'EFQ-' + id, limit: 1 } } );
cache_invalidate("F:" + id);
}
} else {
feedctr.className = "feedCtrNoUnread";
feedr.className = feedr.className.replace("Unread", "");
}
}
}
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
var feeds_stored = number_of_feeds;
//console.log("Feed counters, C: " + feeds_found + ", S:" + feeds_stored);
if (feeds_stored != feeds_found) {
number_of_feeds = feeds_found;
if (feeds_stored != 0 && feeds_found != 0) {
console.log("Subscribed feed number changed, refreshing feedlist");
setTimeout('updateFeedList(false, false)', 50);
}
} else {
/* var fl = $("feeds-frame").innerHTML;
if (fl) {
cache_invalidate("FEEDLIST");
cache_inject("FEEDLIST", fl, getInitParam("num_feeds"));
} */
}
} catch (e) {
exception_error("parse_counters", e);
}
}
/*function parse_counters_reply(transport, scheduled_call) {
if (!transport.responseXML) {
notify_error("Backend did not return valid XML", true);
return;
}
var reply = transport.responseXML.firstChild;
if (!reply) {
notify_error("Backend did not return expected XML object", true);
updateTitle("");
return;
}
if (!transport_error_check(transport)) return;
var counters = reply.getElementsByTagName("counters")[0];
if (counters)
parse_counters(counters, scheduled_call);
var runtime_info = reply.getElementsByTagName("runtime-info")[0];
if (runtime_info)
parse_runtime_info(runtime_info);
if (feedsSortByUnread()) {
resort_feedlist();
}
hideOrShowFeeds(getInitParam("hide_read_feeds") == 1);
} */
function get_feed_unread(id) {
try {
return parseInt($("FEEDU-" + id).innerHTML);
} catch (e) {
return -1;
}
}
function get_cat_unread(id) {
try {
var ctr = $("FCATCTR-" + id).innerHTML;
ctr = ctr.replace("(", "");
ctr = ctr.replace(")", "");
return parseInt(ctr);
} catch (e) {
return -1;
}
}
function get_feed_entry_unread(elem) {
var id = elem.id.replace("FEEDR-", "");
if (id <= 0) {
return -1;
}
try {
return parseInt($("FEEDU-" + id).innerHTML);
} catch (e) {
return -1;
}
}
function get_feed_entry_name(elem) {
var id = elem.id.replace("FEEDR-", "");
return getFeedName(id);
}
function resort_category(node, cat_mode) {
try {
console.log("resort_category: " + node + " CM=" + cat_mode);
var by_unread = feedsSortByUnread();
var list = node.getElementsByTagName("LI");
for (i = 0; i < list.length; i++) {
for (j = i+1; j < list.length; j++) {
var tmp_val = get_feed_entry_unread(list[i]);
var cur_val = get_feed_entry_unread(list[j]);
var tmp_name = get_feed_entry_name(list[i]);
var cur_name = get_feed_entry_name(list[j]);
/* we don't want to match FEEDR-0 - e.g. Archived articles */
var valid_pair = cat_mode || (list[i].id.match(/FEEDR-[1-9]/) &&
list[j].id.match(/FEEDR-[1-9]/));
if (valid_pair && ((by_unread && (cur_val > tmp_val)) || (!by_unread && (cur_name < tmp_name)))) {
tempnode_i = list[i].cloneNode(true);
tempnode_j = list[j].cloneNode(true);
node.replaceChild(tempnode_i, list[j]);
node.replaceChild(tempnode_j, list[i]);
}
}
}
} catch (e) {
exception_error("resort_category", e);
}
}
function resort_feedlist() {
console.log("resort_feedlist");
if ($("FCATLIST--1")) {
var lists = document.getElementsByTagName("UL");
for (var i = 0; i < lists.length; i++) {
if (lists[i].id && lists[i].id.match("FCATLIST-")) {
resort_category(lists[i], true);
}
}
} else {
resort_category($("feedList"), false);
}
}
/** * @(#)isNumeric.js * * Copyright (c) 2000 by Sundar Dorai-Raj
* * @author Sundar Dorai-Raj
@ -714,229 +320,6 @@ function resort_feedlist() {
}
function hideOrShowFeeds(hide) {
try {
//console.log("hideOrShowFeeds: " + hide);
if ($("FCATLIST--1")) {
var lists = document.getElementsByTagName("UL");
for (var i = 0; i < lists.length; i++) {
if (lists[i].id && lists[i].id.match("FCATLIST-")) {
var id = lists[i].id.replace("FCATLIST-", "");
hideOrShowFeedsCategory(id, hide);
}
}
} else {
hideOrShowFeedsCategory(null, hide);
}
} catch (e) {
exception_error("hideOrShowFeeds", e);
}
}
function hideOrShowFeedsCategory(id, hide) {
try {
var node = null;
var cat_node = null;
if (id) {
node = $("FCATLIST-" + id);
cat_node = $("FCAT-" + id);
} else {
node = $("feedList"); // no categories
}
// console.log("hideOrShowFeedsCategory: " + node + " (" + hide + ")");
var cat_unread = 0;
if (!node) {
console.warn("hideOrShowFeeds: passed node is null, aborting");
return;
}
// console.log("cat: " + node.id);
if (node.hasChildNodes() && node.firstChild.nextSibling != false) {
for (i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeName != "LI") { continue; }
if (node.childNodes[i].style != undefined) {
var has_unread = (node.childNodes[i].className != "feed" &&
node.childNodes[i].className != "label" &&
!(!getInitParam("hide_read_shows_special") &&
node.childNodes[i].className == "virt") &&
node.childNodes[i].className != "error" &&
node.childNodes[i].className != "tag");
// console.log(node.childNodes[i].id + " --> " + has_unread);
if (hide && !has_unread) {
//node.childNodes[i].style.display = "none";
var id = node.childNodes[i].id;
Effect.Fade(node.childNodes[i], {duration : 0.3,
queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }});
}
if (!hide) {
node.childNodes[i].style.display = "list-item";
//Effect.Appear(node.childNodes[i], {duration : 0.3});
}
if (has_unread) {
node.childNodes[i].style.display = "list-item";
cat_unread++;
//Effect.Appear(node.childNodes[i], {duration : 0.3});
//Effect.Highlight(node.childNodes[i]);
}
}
}
}
// console.log("end cat: " + node.id + " unread " + cat_unread);
if (cat_node) {
if (cat_unread == 0) {
if (cat_node.style == undefined) {
console.log("ERROR: supplied cat_node " + cat_node +
" has no styles. WTF?");
return;
}
if (hide) {
//cat_node.style.display = "none";
Effect.Fade(cat_node, {duration : 0.3,
queue: { position: 'end', scope: 'CFADE-' + node.id, limit: 1 }});
} else {
cat_node.style.display = "list-item";
}
} else {
try {
cat_node.style.display = "list-item";
} catch (e) {
console.log(e);
}
}
}
// console.log("unread for category: " + cat_unread);
} catch (e) {
exception_error("hideOrShowFeedsCategory", e);
}
}
function selectTableRow(r, do_select) {
r.className = r.className.replace("Selected", "");
if (do_select) {
r.className = r.className + "Selected";
}
}
function selectTableRowById(elem_id, check_id, do_select) {
try {
var row = $(elem_id);
if (row) {
selectTableRow(row, do_select);
}
var check = $(check_id);
if (check) {
check.checked = do_select;
}
} catch (e) {
exception_error("selectTableRowById", e);
}
}
function selectTableRowsByIdPrefix(content_id, prefix, check_prefix, do_select,
classcheck, reset_others) {
var content = $(content_id);
if (!content) {
console.log("[selectTableRows] Element " + content_id + " not found.");
return;
}
for (i = 0; i < content.rows.length; i++) {
if (Element.visible(content.rows[i])) {
if (!classcheck || content.rows[i].className.match(classcheck)) {
if (content.rows[i].id.match(prefix)) {
selectTableRow(content.rows[i], do_select);
var row_id = content.rows[i].id.replace(prefix, "");
var check = $(check_prefix + row_id);
if (check) {
check.checked = do_select;
}
} else if (reset_others) {
selectTableRow(content.rows[i], false);
var row_id = content.rows[i].id.replace(prefix, "");
var check = $(check_prefix + row_id);
if (check) {
check.checked = false;
}
}
} else if (reset_others) {
selectTableRow(content.rows[i], false);
var row_id = content.rows[i].id.replace(prefix, "");
var check = $(check_prefix + row_id);
if (check) {
check.checked = false;
}
}
}
}
}
function getSelectedTableRowIds(content_id, prefix) {
var content = $(content_id);
if (!content) {
console.log("[getSelectedTableRowIds] Element " + content_id + " not found.");
return new Array();
}
var sel_rows = new Array();
for (i = 0; i < content.rows.length; i++) {
if (content.rows[i].id.match(prefix) &&
content.rows[i].className.match("Selected")) {
var row_id = content.rows[i].id.replace(prefix + "-", "");
sel_rows.push(row_id);
}
}
return sel_rows;
}
function toggleSelectRowById(sender, id) {
var row = $(id);
@ -983,109 +366,6 @@ function toggleSelectRow(sender) {
}
}
function getNextUnreadCat(id) {
try {
var rows = $("feedList").getElementsByTagName("LI");
var feeds = new Array();
var unread_only = true;
var is_cat = true;
for (var i = 0; i < rows.length; i++) {
if (rows[i].id.match("FCAT-")) {
if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
if (cat_id >= 0) {
if (!unread_only || get_cat_unread(cat_id) > 0) {
feeds.push(cat_id);
}
}
}
}
}
var idx = feeds.indexOf(id);
if (idx != -1 && idx < feeds.length) {
return feeds[idx+1];
} else {
return feeds.shift();
}
} catch (e) {
exception_error("getNextUnreadCat", e);
}
}
function getRelativeFeedId2(id, is_cat, direction, unread_only) {
try {
// alert(id + " IC: " + is_cat + " D: " + direction + " U: " + unread_only);
var rows = $("feedList").getElementsByTagName("LI");
var feeds = new Array();
for (var i = 0; i < rows.length; i++) {
if (rows[i].id.match("FEEDR-")) {
if (rows[i].id == "FEEDR-" + id && !is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
if (!unread_only ||
(rows[i].className.match("Unread") || rows[i].id == "FEEDR-" + id)) {
feeds.push(rows[i].id.replace("FEEDR-", ""));
}
}
}
if (rows[i].id.match("FCAT-")) {
if (rows[i].id == "FCAT-" + id && is_cat || (Element.visible(rows[i]) && Element.visible(rows[i].parentNode))) {
var cat_id = parseInt(rows[i].id.replace("FCAT-", ""));
if (cat_id >= 0) {
if (!unread_only || get_cat_unread(cat_id) > 0) {
feeds.push("CAT:"+cat_id);
}
}
}
}
}
// alert(feeds.toString());
if (!id) {
if (direction == "next") {
return feeds.shift();
} else {
return feeds.pop();
}
} else {
if (direction == "next") {
if (is_cat) id = "CAT:" + id;
var idx = feeds.indexOf(id);
if (idx != -1 && idx < feeds.length) {
return feeds[idx+1];
} else {
return getRelativeFeedId2(false, is_cat, direction, unread_only);
}
} else {
if (is_cat) id = "CAT:" + id;
var idx = feeds.indexOf(id);
if (idx > 0) {
return feeds[idx-1];
} else {
return getRelativeFeedId2(false, is_cat, direction, unread_only);
}
}
}
} catch (e) {
exception_error("getRelativeFeedId2", e);
}
}
function checkboxToggleElement(elem, id) {
if (elem.checked) {
Effect.Appear(id, {duration : 0.5});
@ -1461,21 +741,6 @@ function fatalError(code, msg, ext_info) {
}
}
function getFeedName(id, is_cat) {
var e;
if (is_cat) {
e = $("FCATN-" + id);
} else {
e = $("FEEDN-" + id);
}
if (e) {
return e.innerHTML.stripTags();
} else {
return null;
}
}
function filterDlgCheckType(sender) {
try {
@ -1607,115 +872,6 @@ function explainError(code) {
return displayDlg("explainError", code);
}
// this only searches loaded headlines list, not in CDM
function getRelativePostIds(id, limit) {
if (!limit) limit = 3;
//console.log("getRelativePostIds: " + id + " limit=" + limit);
var ids = new Array();
var container = $("headlinesList");
if (container) {
var rows = container.rows;
for (var i = 0; i < rows.length; i++) {
var r_id = rows[i].id.replace("RROW-", "");
if (r_id == id) {
for (var k = 1; k <= limit; k++) {
var nid = false;
if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
if (nid) ids.push(nid);
if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
if (nid) ids.push(nid);
}
return ids;
}
}
}
return false;
}
function openArticleInNewWindow(id) {
try {
console.log("openArticleInNewWindow: " + id);
var query = "?op=rpc&subop=getArticleLink&id=" + id;
var wname = "ttrss_article_" + id;
console.log(query + " " + wname);
var w = window.open("", wname);
if (!w) notify_error("Failed to open window for the article");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
var link = transport.responseXML.getElementsByTagName("link")[0];
var id = transport.responseXML.getElementsByTagName("id")[0];
console.log("open_article received link: " + link);
if (link && id) {
var wname = "ttrss_article_" + id.firstChild.nodeValue;
console.log("link url: " + link.firstChild.nodeValue + ", wname " + wname);
var w = window.open(link.firstChild.nodeValue, wname);
if (!w) { notify_error("Failed to load article in new window"); }
if (id) {
id = id.firstChild.nodeValue;
if (!$("headlinesList")) {
window.setTimeout("toggleUnread(" + id + ", 0)", 100);
}
}
} else {
notify_error("Can't open article: received invalid article link");
}
} });
} catch (e) {
exception_error("openArticleInNewWindow", e);
}
}
function isCdmMode() {
return !$("headlinesList");
}
function getSelectedArticleIds2() {
var rows = new Array();
var cdm_mode = isCdmMode();
if (cdm_mode) {
rows = cdmGetSelectedArticles();
} else {
rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
}
var ids = new Array();
for (var i = 0; i < rows.length; i++) {
var chk = $("RCHK-" + rows[i]);
if (chk && chk.checked) {
ids.push(rows[i]);
}
}
return ids;
}
function displayHelpInfobox(topic_id) {
var url = "backend.php?op=help&tid=" + param_escape(topic_id);
@ -1874,23 +1030,6 @@ function hideAuxDlg() {
}
}
function displayNewContentPrompt(id) {
try {
var msg = "<a href='#' onclick='viewfeed("+id+")'>" +
__("New articles available in this feed (click to show)") + "</a>";
msg = msg.replace("%s", getFeedName(id));
$('auxDlg').innerHTML = msg;
new Effect.Appear('auxDlg', {duration : 0.5});
} catch (e) {
exception_error("displayNewContentPrompt", e);
}
}
function feedBrowserSubscribe() {
try {
@ -2364,3 +1503,77 @@ function dropbox_replace_options(elem, options) {
exception_error("dropbox_replace_options", e);
}
}
// mode = all, none, invert
function selectTableRows(id, mode) {
try {
var rows = $(id).rows;
for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var cb = false;
if (row.id && row.className) {
var bare_id = row.id.replace(/^[A-Z]*?-/, "");
var inputs = rows[i].getElementsByTagName("input");
for (var j = 0; j < inputs.length; j++) {
var input = inputs[j];
if (input.getAttribute("type") == "checkbox" &&
input.id.match(bare_id)) {
cb = input;
break;
}
}
if (cb) {
var issel = row.className.match("Selected");
if (mode == "all" && !issel) {
row.className += "Selected";
cb.checked = true;
} else if (mode == "none" && issel) {
row.className = row.className.replace("Selected", "");
cb.checked = false;
} else if (mode == "invert") {
if (issel) {
row.className = row.className.replace("Selected", "");
cb.checked = false;
} else {
row.className += "Selected";
cb.checked = true;
}
}
}
}
}
} catch (e) {
exception_error("selectTableRows", e);
}
}
function getSelectedTableRowIds(id) {
var rows = [];
try {
var elem_rows = $(id).rows;
for (i = 0; i < elem_rows.length; i++) {
if (elem_rows[i].className.match("Selected")) {
var bare_id = elem_rows[i].id.replace(/^[A-Z]*?-/, "");
rows.push(bare_id);
}
}
} catch (e) {
exception_error("getSelectedTableRowIds", e);
}
return rows;
}

View File

@ -4137,30 +4137,14 @@
$archive_sel_link = "javascript:archiveSelection()";
$delete_sel_link = "javascript:deleteSelection()";
if (!get_pref($link, 'COMBINED_DISPLAY_MODE')) {
$sel_all_link = "javascript:selectArticles('all')";
$sel_unread_link = "javascript:selectArticles('unread')";
$sel_none_link = "javascript:selectArticles('none')";
$sel_inv_link = "javascript:selectArticles('invert')";
$sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
$sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
$sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
$sel_inv_link = "javascript:invertHeadlineSelection()";
$tog_unread_link = "javascript:selectionToggleUnread()";
$tog_marked_link = "javascript:selectionToggleMarked()";
$tog_published_link = "javascript:selectionTogglePublished()";
} else {
$sel_all_link = "javascript:cdmSelectArticles('all')";
$sel_unread_link = "javascript:cdmSelectArticles('unread')";
$sel_none_link = "javascript:cdmSelectArticles('none')";
$sel_inv_link = "javascript:invertHeadlineSelection()";
$tog_unread_link = "javascript:selectionToggleUnread()";
$tog_marked_link = "javascript:selectionToggleMarked()";
$tog_published_link = "javascript:selectionTogglePublished()";
}
$tog_unread_link = "javascript:selectionToggleUnread()";
$tog_marked_link = "javascript:selectionToggleMarked()";
$tog_published_link = "javascript:selectionTogglePublished()";
print "<div id=\"subtoolbar_ftitle\">";
@ -4223,10 +4207,10 @@
print "</div>";
print __('Select:')."
<a href=\"$sel_all_link\">".__('All')."</a>,
<a href=\"$sel_unread_link\">".__('Unread')."</a>,
<a href=\"$sel_inv_link\">".__('Invert')."</a>,
<a href=\"$sel_none_link\">".__('None')."</a></li>";
<a href=\"#\" onclick=\"$sel_all_link\">".__('All')."</a>,
<a href=\"#\" onclick=\"$sel_unread_link\">".__('Unread')."</a>,
<a href=\"#\" onclick=\"$sel_inv_link\">".__('Invert')."</a>,
<a href=\"#\" onclick=\"$sel_none_link\">".__('None')."</a></li>";
print "&nbsp;&nbsp;";

View File

@ -47,7 +47,7 @@
<tr><td class='n'>f s</td><td><?php echo __("Subscribe to feed") ?></td></tr>
<tr><td class='n'>f e</td><td><?php echo __("Edit feed") ?></td></tr>
<tr><td class='n'>f w</td><td><?php echo __("Sort by name or unread count") ?></td></tr>
<tr><td class='n'>f h</td><td><?php echo __("Hide visible read articles") ?></td></tr>
<!-- <tr><td class='n'>f h</td><td><?php echo __("Hide visible read articles") ?></td></tr> -->
<tr><td class='n'>f q</td><td><?php echo __("Mark feed as read") ?></td></tr>
<tr><td class='n'>f x</td><td><?php echo __("Reverse headlines order") ?></td></tr>
<tr><td class='n'>Q</td><td><?php echo __("Mark all feeds as read") ?></td></tr>

View File

@ -80,8 +80,8 @@
WHERE owner_uid = ".$_SESSION["uid"]." ORDER BY title");
print __('Select:')."
<a href=\"#\" onclick=\"selectPrefRows('fcat', true)\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectPrefRows('fcat', false)\">".__('None')."</a>";
<a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'all')\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'none')\">".__('None')."</a>";
print "<div class=\"prefFeedCatHolder\">";
@ -343,10 +343,6 @@
$owner_uid = $_SESSION["uid"];
/* print __('Select:')."
<a href=\"javascript:selectPrefRows('fbrowse', true)\">".__('All')."</a>,
<a href=\"javascript:selectPrefRows('fbrowse', false)\">".__('None')."</a>"; */
print "<ul class='browseFeedList' id='browseFeedList'>";
print_feed_browser($link, $search, 25);
print "</ul>";

View File

@ -993,8 +993,8 @@
if (db_num_rows($result) != 0) {
print __('Select:')."
<a href=\"#\" onclick=\"selectPrefRows('fcat', true)\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectPrefRows('fcat', false)\">".__('None')."</a>";
<a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'all')\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectTableRows('prefFeedCatList', 'none')\">".__('None')."</a>";
print "<div class=\"prefFeedCatHolder\">";
@ -1199,8 +1199,8 @@
$show_last_article_checked><label
for='show_last_article_times'>".__('Show last article times')."</label></div>".
__('Select:')."
<a href=\"#\" onclick=\"selectPrefRows('feed', true)\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectPrefRows('feed', false)\">".__('None')."</a>
<a href=\"#\" onclick=\"selectTableRows('prefFeedList', 'all')\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectTableRows('prefFeedList', 'none')\">".__('None')."</a>
</td</tr>";
if (!get_pref($link, 'ENABLE_FEED_CATS')) {

View File

@ -376,8 +376,8 @@
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
".__('Select:')."
<a href=\"#\" onclick=\"selectPrefRows('filter', true)\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectPrefRows('filter', false)\">".__('None')."</a>
<a href=\"#\" onclick=\"selectTableRows('prefFilterList', 'all')\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectTableRows('prefFilterList', 'none')\">".__('None')."</a>
</td</tr>";
$lnum = 0;

View File

@ -199,8 +199,6 @@
owner_uid = ".$_SESSION["uid"]."
ORDER BY $sort");
// print "<div id=\"infoBoxShadow\"><div id=\"infoBox\">PLACEHOLDER</div></div>";
if (db_num_rows($result) != 0) {
print "<p><table width=\"100%\" cellspacing=\"0\"
@ -208,16 +206,10 @@
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
".__('Select:')."
<a href=\"#\" onclick=\"selectPrefRows('label', true)\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectPrefRows('label', false)\">".__('None')."</a>
<a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'all')\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectTableRows('prefLabelList', 'none')\">".__('None')."</a>
</td</tr>";
/* print "<tr class=\"title\">
<td width=\"5%\">&nbsp;</td>
<td width=\"95%\"><a href=\"javascript:updateLabelList('caption')\">".__('Caption')."</a></td>
</td>
</tr>"; */
$lnum = 0;
while ($line = db_fetch_assoc($result)) {

View File

@ -417,8 +417,8 @@
print "<tr><td class=\"selectPrompt\" colspan=\"8\">
".__('Select:')."
<a href=\"#\" onclick=\"selectPrefRows('user', true)\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectPrefRows('user', false)\">".__('None')."</a>
<a href=\"#\" onclick=\"selectTableRows('prefUserList', 'all')\">".__('All')."</a>,
<a href=\"#\" onclick=\"selectTableRows('prefUserList', 'none')\">".__('None')."</a>
</td</tr>";
print "<tr class=\"title\">

View File

@ -140,35 +140,16 @@ function viewfeed_offline(feed_id, subop, is_cat, subop_param, skip_history, off
tmp += feed_title;
tmp += "</div>";
var sel_all_link;
var sel_unread_link;
var sel_none_link;
var sel_inv_link;
var catchup_feed_link = "javascript:catchupCurrentFeed()";
var catchup_sel_link = "javascript:catchupSelection()";
var tog_unread_link;
var tog_marked_link;
var sel_all_link = "javascript:selectArticles('all')";
var sel_unread_link = "javascript:selectArticles('unread')";
var sel_none_link = "javascript:selectArticles('none')";
var sel_inv_link = "javascript:invertHeadlineSelection()";
if ($("content-frame")) {
sel_all_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, '', true)";
sel_unread_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true)";
sel_none_link = "javascript:selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false)";
sel_inv_link = "javascript:invertHeadlineSelection()";
tog_unread_link = "javascript:selectionToggleUnread()";
tog_marked_link = "javascript:selectionToggleMarked()";
} else {
sel_all_link = "javascript:cdmSelectArticles('all')";
sel_unread_link = "javascript:cdmSelectArticles('unread')";
sel_none_link = "javascript:cdmSelectArticles('none')";
sel_inv_link = "javascript:invertHeadlineSelection()";
tog_unread_link = "javascript:selectionToggleUnread()";
tog_marked_link = "javascript:selectionToggleMarked()";
}
var tog_unread_link = "javascript:selectionToggleUnread()";
var tog_marked_link = "javascript:selectionToggleMarked()";
tmp += __('Select:')+
" <a href=\""+sel_all_link+"\">"+__('All')+"</a>, "+

View File

@ -337,7 +337,7 @@ function editUser(id, event) {
notify_progress("Loading, please wait...");
selectTableRowsByIdPrefix('prefUserList', 'UMRR-', 'UMCHK-', false);
selectTableRows('prefUserList', 'none');
selectTableRowById('UMRR-'+id, 'UMCHK-'+id, true);
var query = "?op=pref-users&subop=edit&id=" +
@ -372,7 +372,7 @@ function editFilter(id, event) {
notify_progress("Loading, please wait...");
selectTableRowsByIdPrefix('prefFilterList', 'FILRR-', 'FICHK-', false);
selectTableRows('prefFilterList', 'none');
selectTableRowById('FILRR-'+id, 'FICHK-'+id, true);
var query = "?op=pref-filters&subop=edit&id=" +
@ -404,9 +404,8 @@ function editFeed(feed, event) {
disableHotkeys();
notify_progress("Loading, please wait...");
// clean selection from all rows & select row being edited
selectTableRowsByIdPrefix('prefFeedList', 'FEEDR-', 'FRCHK-', false);
selectTableRows('prefFeedList', 'none');
selectTableRowById('FEEDR-'+feed, 'FRCHK-'+feed, true);
var query = "?op=pref-feeds&subop=editfeed&id=" +
@ -432,23 +431,23 @@ function editFeed(feed, event) {
}
function getSelectedLabels() {
return getSelectedTableRowIds("prefLabelList", "LILRR");
return getSelectedTableRowIds("prefLabelList");
}
function getSelectedUsers() {
return getSelectedTableRowIds("prefUserList", "UMRR");
return getSelectedTableRowIds("prefUserList");
}
function getSelectedFeeds() {
return getSelectedTableRowIds("prefFeedList", "FEEDR");
return getSelectedTableRowIds("prefFeedList");
}
function getSelectedFilters() {
return getSelectedTableRowIds("prefFilterList", "FILRR");
return getSelectedTableRowIds("prefFilterList");
}
function getSelectedFeedCats() {
return getSelectedTableRowIds("prefFeedCatList", "FCATR");
return getSelectedTableRowIds("prefFeedCatList");
}
@ -706,11 +705,7 @@ function removeSelectedFeedCats() {
}
function feedEditCancel() {
closeInfoBox();
selectPrefRows('feed', false); // cleanup feed selection
return false;
}
@ -740,21 +735,12 @@ function feedEditSave() {
}
function userEditCancel() {
selectPrefRows('user', false); // cleanup feed selection
closeInfoBox();
return false;
}
function filterEditCancel() {
try {
selectPrefRows('filter', false); // cleanup feed selection
} catch (e) { }
closeInfoBox();
return false;
}
@ -1242,54 +1228,6 @@ function validatePrefsReset() {
}
function selectPrefRows(kind, select) {
if (kind) {
var opbarid = false;
var nchk = false;
var nrow = false;
var lname = false;
if (kind == "feed") {
opbarid = "feedOpToolbar";
nrow = "FEEDR-";
nchk = "FRCHK-";
lname = "prefFeedList";
} else if (kind == "fcat") {
opbarid = "catOpToolbar";
nrow = "FCATR-";
nchk = "FCCHK-";
lname = "prefFeedCatList";
} else if (kind == "filter") {
opbarid = "filterOpToolbar";
nrow = "FILRR-";
nchk = "FICHK-";
lname = "prefFilterList";
} else if (kind == "label") {
opbarid = "labelOpToolbar";
nrow = "LILRR-";
nchk = "LICHK-";
lname = "prefLabelList";
} else if (kind == "user") {
opbarid = "userOpToolbar";
nrow = "UMRR-";
nchk = "UMCHK-";
lname = "prefUserList";
} else if (kind == "fbrowse") {
opbarid = "browseOpToolbar";
nrow = "FBROW-";
nchk = "FBCHK-";
lname = "browseFeedList";
}
if (opbarid) {
selectTableRowsByIdPrefix(lname, nrow, nchk, select);
}
}
}
function pref_hotkey_handler(e) {
try {
@ -1906,7 +1844,7 @@ function labelColorAsk(id, kind) {
var query = "?op=pref-labels&subop=color-set&kind=" + kind +
"&ids="+ param_escape(id) + "&color=" + param_escape(p);
selectPrefRows('label', false);
selectTableRows('prefLabelList', 'none');
var e = $("LICID-" + id);

View File

@ -46,6 +46,8 @@
<script type="text/javascript" charset="utf-8" src="localized_js.php?<?php echo $dt_add ?>"></script>
<script type="text/javascript" charset="utf-8" src="functions.js?<?php echo $dt_add ?>"></script>
<script type="text/javascript" charset="utf-8" src="deprecated.js?<?php echo $dt_add ?>"></script>
<script type="text/javascript" charset="utf-8" src="prefs.js?<?php echo $dt_add ?>"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

View File

@ -10,8 +10,6 @@ var hotkey_prefix_pressed = false;
var init_params = {};
var ver_offset = 0;
var hor_offset = 0;
var feeds_sort_by_unread = false;
var feedlist_sortable_enabled = false;
var _force_scheduled_update = false;
var last_scheduled_update = false;
@ -831,7 +829,6 @@ function hotkey_handler(e) {
var shift_key = false;
var cmdline = $('cmdline');
var feedlist = $('feedList');
try {
shift_key = e.shiftKey;
@ -1118,11 +1115,6 @@ function hotkey_handler(e) {
return resort_feedlist();
}
if (keycode == 72) { // h
hideReadHeadlines();
return;
}
if (keycode == 88) { // x
reverseHeadlineOrder();
return;
@ -1233,10 +1225,6 @@ function hotkey_handler(e) {
}
}
function feedsSortByUnread() {
return feeds_sort_by_unread;
}
function inPreferences() {
return false;
}

View File

@ -33,23 +33,6 @@ function catchup_callback2(transport, callback) {
}
}
function clean_feed_selections() {
try {
var feeds = $("feedList").getElementsByTagName("LI");
for (var i = 0; i < feeds.length; i++) {
if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
feeds[i].className = feeds[i].className.replace("Selected", "");
}
if (feeds[i].id && feeds[i].id.match("FCAT-")) {
feeds[i].className = feeds[i].className.replace("Selected", "");
}
}
} catch (e) {
exception_error("clean_feed_selections", e);
}
}
function headlines_callback2(transport, feed_cur_page) {
try {
@ -217,7 +200,7 @@ function headlines_callback2(transport, feed_cur_page) {
if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
if (!$("headlinesList") &&
if (isCdmMode() &&
getActiveFeedId() != -3 &&
getInitParam("cdm_auto_catchup") == 1) {
console.log("starting CDM watchdog");
@ -275,8 +258,8 @@ function showArticleInHeadlines(id) {
crow.className = crow.className.replace("Unread", "");
selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
selectArticles('none');
var upd_img_pic = $("FUPDPIC-" + id);
var cache_prefix = "";
@ -563,7 +546,7 @@ function toggleMark(id, client_only, no_effects) {
mark_img.alt = __("Please wait...");
query = query + "&mark=0";
if ($("headlinesList") && !no_effects) {
if (!isCdmMode() && !no_effects) {
Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
} else {
mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
@ -630,7 +613,7 @@ function togglePub(id, client_only, no_effects, note) {
mark_img.alt = __("Please wait...");
query = query + "&pub=0";
if ($("headlinesList") && !no_effects) {
if (!isCdmMode() && !no_effects) {
Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
} else {
mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
@ -709,14 +692,8 @@ function moveToPost(mode) {
try {
var rows;
var rows = getVisibleArticleIds();
if (isCdmMode()) {
rows = cdmGetVisibleArticles();
} else {
rows = getVisibleHeadlineIds();
}
var prev_id = false;
var next_id = false;
@ -1126,12 +1103,18 @@ function selectionTogglePublished() {
}
}
function cdmGetSelectedArticles() {
function getSelectedArticleIds2() {
var sel_articles = new Array();
var container = $("headlinesInnerContainer");
for (i = 0; i < container.childNodes.length; i++) {
var child = container.childNodes[i];
var children;
if (isCdmMode())
var children = $("headlinesInnerContainer").childNodes;
else
var children = $("headlinesList").rows;
for (i = 0; i < children.length; i++) {
var child = children[i];
if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
var c_id = child.id.replace("RROW-", "");
@ -1142,14 +1125,18 @@ function cdmGetSelectedArticles() {
return sel_articles;
}
function cdmGetVisibleArticles() {
function getLoadedArticleIds() {
var sel_articles = new Array();
var container = $("headlinesInnerContainer");
if (!container) return sel_articles;
if (isCdmMode())
var children = $("headlinesInnerContainer").childNodes;
else
var children = $("headlinesList").rows;
for (i = 0; i < container.childNodes.length; i++) {
var child = container.childNodes[i];
if (!children) return sel_articles;
for (i = 0; i < children.length; i++) {
var child = children[i];
if (child.id && child.id.match("RROW-")) {
var c_id = child.id.replace("RROW-", "");
@ -1160,50 +1147,53 @@ function cdmGetVisibleArticles() {
return sel_articles;
}
function cdmGetUnreadArticles() {
var sel_articles = new Array();
var container = $("headlinesInnerContainer");
// mode = all,none,unread,invert
function selectArticles(mode) {
try {
for (i = 0; i < container.childNodes.length; i++) {
var child = container.childNodes[i];
var children;
if (isCdmMode())
var children = $("headlinesInnerContainer").childNodes;
else
var children = $("headlinesList").rows;
if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
var c_id = child.id.replace("RROW-", "");
sel_articles.push(c_id);
for (i = 0; i < children.length; i++) {
var child = children[i];
if (child.id && child.id.match("RROW-")) {
var aid = child.id.replace("RROW-", "");
var cb = $("RCHK-" + aid);
if (mode == "all") {
if (!child.className.match("Selected")) {
child.className = child.className + "Selected";
cb.checked = true;
}
} else if (mode == "unread") {
if (child.className.match("Unread") && !child.className.match("Selected")) {
child.className = child.className + "Selected";
cb.checked = true;
}
} else if (mode == "invert") {
if (child.className.match("Selected")) {
child.className = child.className.replace("Selected", "");
cb.checked = false;
} else {
child.className = child.className + "Selected";
cb.checked = true;
}
} else {
child.className = child.className.replace("Selected", "");
cb.checked = false;
}
}
}
}
return sel_articles;
}
// mode = all,none,unread
function cdmSelectArticles(mode) {
var container = $("headlinesInnerContainer");
for (i = 0; i < container.childNodes.length; i++) {
var child = container.childNodes[i];
if (child.id && child.id.match("RROW-")) {
var aid = child.id.replace("RROW-", "");
var cb = $("RCHK-" + aid);
if (mode == "all") {
if (!child.className.match("Selected")) {
child.className = child.className + "Selected";
cb.checked = true;
}
} else if (mode == "unread") {
if (child.className.match("Unread") && !child.className.match("Selected")) {
child.className = child.className + "Selected";
cb.checked = true;
}
} else {
child.className = child.className.replace("Selected", "");
cb.checked = false;
}
}
} catch (e) {
exception_error("selectArticles", e);
}
}
@ -1219,15 +1209,9 @@ function catchupPage() {
return;
}
if ($("headlinesList")) {
selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
selectionToggleUnread(false, 'viewCurrentFeed()', true);
selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
} else {
cdmSelectArticles('all');
selectionToggleUnread(false, 'viewCurrentFeed()', true)
cdmSelectArticles('none');
}
selectArticles('all');
selectionToggleUnread(false, 'viewCurrentFeed()', true)
selectArticles('none');
}
function deleteSelection() {
@ -1439,60 +1423,6 @@ function editTagsInsert() {
}
}
function cdmScrollViewport(where) {
console.log("cdmScrollViewport: " + where);
var ctr = $("headlinesInnerContainer");
if (!ctr) return;
if (where == "bottom") {
ctr.scrollTop = ctr.scrollHeight;
} else {
ctr.scrollTop = where;
}
}
function cdmArticleIsBelowViewport(id) {
try {
var ctr = $("headlinesInnerContainer");
var e = $("RROW-" + id);
if (!e || !ctr) return;
// article starts below viewport
if (ctr.scrollTop < e.offsetTop) {
return true;
} else {
return false;
}
} catch (e) {
exception_error("cdmArticleIsVisible", e);
}
}
function cdmArticleIsAboveViewport(id) {
try {
var ctr = $("headlinesInnerContainer");
var e = $("RROW-" + id);
if (!e || !ctr) return;
// article starts above viewport
if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
return true;
} else {
return false;
}
} catch (e) {
exception_error("cdmArticleIsVisible", e);
}
}
function cdmScrollToArticleId(id) {
try {
var ctr = $("headlinesInnerContainer");
@ -1507,36 +1437,6 @@ function cdmScrollToArticleId(id) {
}
}
function cdmArticleIsActuallyVisible(id) {
try {
var ctr = $("headlinesInnerContainer");
var e = $("RROW-" + id);
if (!e || !ctr) return;
// article fits in viewport OR article is longer than viewport and
// its bottom is visible
if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
ctr.scrollTop + ctr.offsetHeight) {
return true;
} else if (e.offsetHeight > ctr.offsetHeight &&
e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
return true;
}
return false;
} catch (e) {
exception_error("cdmArticleIsVisible", e);
}
}
function cdmWatchdog() {
try {
@ -2009,13 +1909,7 @@ function catchupRelativeToArticle(below) {
return;
}
var visible_ids;
if ($("headlinesList")) {
visible_ids = getVisibleHeadlineIds();
} else {
visible_ids = cdmGetVisibleArticles();
}
var visible_ids = getVisibleArticleIds();
var ids_to_mark = new Array();
@ -2077,12 +1971,14 @@ function catchupRelativeToArticle(below) {
function cdmExpandArticle(id) {
try {
hideAuxDlg();
var elem = $("CICD-" + active_post_id);
if (id == active_post_id && Element.visible(elem))
return true;
cdmSelectArticles("none");
selectArticles("none");
var old_offset = $("RROW-" + id).offsetTop;
@ -2135,48 +2031,6 @@ function fixHeadlinesOrder(ids) {
}
}
function hideReadHeadlines() {
try {
var ids = false;
var vis_ids = new Array();
if ($("headlinesList")) {
ids = getVisibleHeadlineIds();
} else {
ids = cdmGetVisibleArticles();
}
var read_headlines_visible = true;
for (var i = 0; i < ids.length; i++) {
var row = $("RROW-" + ids[i]);
if (row && row.className) {
if (read_headlines_visible) {
if (row.className.match("Unread") || row.className.match("Selected")) {
Element.show(row);
vis_ids.push(ids[i]);
} else {
//Effect.Fade(row, {duration : 0.3});
Element.hide(row);
}
} else {
Element.show(row);
vis_ids.push(ids[i]);
}
}
}
fixHeadlinesOrder(vis_ids);
read_headlines_visible = !read_headlines_visible;
} catch (e) {
exception_error("hideReadHeadlines", e);
}
}
function invertHeadlineSelection() {
try {
var rows = new Array();
@ -2400,16 +2254,26 @@ function dismissArticle(id) {
function dismissSelectedArticles() {
try {
var ids = getSelectedArticleIds2();
var ids = getVisibleArticleIds();
var tmp = [];
var sel = [];
for (var i = 0; i < ids.length; i++) {
var elem = $("RROW-" + ids[i]);
new Effect.Fade(elem, {duration : 0.5});
if (elem.className && elem.className.match("Selected")) {
new Effect.Fade(elem, {duration : 0.5});
sel.push(ids[i]);
} else {
tmp.push(ids[i]);
}
}
if (ids.length > 0)
if (sel.length > 0)
selectionToggleUnread(false);
fixHeadlinesOrder(tmp);
} catch (e) {
exception_error("dismissSelectedArticles", e);
}
@ -2419,6 +2283,7 @@ function dismissReadArticles() {
try {
var ids = getVisibleArticleIds();
var tmp = [];
for (var i = 0; i < ids.length; i++) {
var elem = $("RROW-" + ids[i]);
@ -2427,32 +2292,45 @@ function dismissReadArticles() {
!elem.className.match("Selected")) {
new Effect.Fade(elem, {duration : 0.5});
} else {
tmp.push(ids[i]);
}
}
fixHeadlinesOrder(tmp);
} catch (e) {
exception_error("dismissSelectedArticles", e);
}
}
function getVisibleArticleIds() {
var ids = [];
try {
if (isCdmMode()) {
return cdmGetVisibleArticles();
} else {
return getVisibleHeadlineIds();
var tmp = getLoadedArticleIds();
for (var i = 0; i < tmp.length; i++) {
var elem = $("RROW-" + tmp[i]);
if (elem && Element.visible(elem))
ids.push(tmp[i]);
}
} catch (e) {
exception_error("getVisibleArticleIds");
exception_error("getVisibleArticleIds", e);
}
return ids;
}
function cdmClicked(event, id) {
try {
var shift_key = event.shiftKey;
hideAuxDlg();
if (!event.ctrlKey) {
cdmSelectArticles("none");
selectArticles("none");
toggleSelected(id);
var elem = $("RROW-" + id);
@ -2499,3 +2377,130 @@ function hlClicked(event, id) {
return false;
}
function getFirstVisibleHeadlineId() {
var rows = getVisibleArticleIds();
return rows[0];
}
function getLastVisibleHeadlineId() {
var rows = getVisibleArticleIds();
return rows[rows.length-1];
}
// this only searches loaded headlines list, not in CDM
function getRelativePostIds(id, limit) {
if (!limit) limit = 3;
//console.log("getRelativePostIds: " + id + " limit=" + limit);
var ids = new Array();
var container = $("headlinesList");
if (container) {
var rows = container.rows;
for (var i = 0; i < rows.length; i++) {
var r_id = rows[i].id.replace("RROW-", "");
if (r_id == id) {
for (var k = 1; k <= limit; k++) {
var nid = false;
if (i > k-1) var nid = rows[i-k].id.replace("RROW-", "");
if (nid) ids.push(nid);
if (i < rows.length-k) nid = rows[i+k].id.replace("RROW-", "");
if (nid) ids.push(nid);
}
return ids;
}
}
}
return false;
}
function openArticleInNewWindow(id) {
try {
console.log("openArticleInNewWindow: " + id);
var query = "?op=rpc&subop=getArticleLink&id=" + id;
var wname = "ttrss_article_" + id;
console.log(query + " " + wname);
var w = window.open("", wname);
if (!w) notify_error("Failed to open window for the article");
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
var link = transport.responseXML.getElementsByTagName("link")[0];
var id = transport.responseXML.getElementsByTagName("id")[0];
console.log("open_article received link: " + link);
if (link && id) {
var wname = "ttrss_article_" + id.firstChild.nodeValue;
console.log("link url: " + link.firstChild.nodeValue + ", wname " + wname);
var w = window.open(link.firstChild.nodeValue, wname);
if (!w) { notify_error("Failed to load article in new window"); }
if (id) {
id = id.firstChild.nodeValue;
if (!$("headlinesList")) {
window.setTimeout("toggleUnread(" + id + ", 0)", 100);
}
}
} else {
notify_error("Can't open article: received invalid article link");
}
} });
} catch (e) {
exception_error("openArticleInNewWindow", e);
}
}
function isCdmMode() {
return !$("headlinesList");
}
function markHeadline(id) {
var row = $("RROW-" + id);
if (row) {
var is_active = false;
if (row.className.match("Active")) {
is_active = true;
}
row.className = row.className.replace("Selected", "");
row.className = row.className.replace("Active", "");
row.className = row.className.replace("Insensitive", "");
if (is_active) {
row.className = row.className = "Active";
}
var check = $("RCHK-" + id);
if (check) {
check.checked = true;
}
row.className = row.className + "Selected";
}
}