var precache_idle_timeout_id = false;
var cids_requested = [];
+var loaded_article_ids = [];
var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
setActiveFeedId(feed_id, is_cat);
+ dijit.getEnclosingWidget(
+ document.forms["main_toolbar_form"].update).attr('disabled',
+ is_cat || feed_id <= 0);
+
try {
if (offset == 0 && infscroll_req == false) {
$("headlines-frame").scrollTop = 0;
//var runtime_info = reply['runtime-info'];
if (offset == 0 && infscroll_req == false) {
+ loaded_article_ids = [];
+
dijit.byId("headlines-frame").attr('content',
reply['headlines']['content']);
dijit.byId("headlines-toolbar").attr('content',
reply['headlines']['toolbar']);
+ $$("#headlines-frame > div[id*=RROW]").each(function(row) {
+ if (loaded_article_ids.indexOf(row.id) != -1) {
+ row.parentNode.removeChild(row);
+ } else {
+ loaded_article_ids.push(row.id);
+ }
+ });
if (getInitParam("cdm_auto_catchup") == 1) {
var hsp = $("headlines-spacer");
initHeadlinesMenu();
+ if (_search_query) {
+ $("feed_title").innerHTML += "<span id='cancel_search'>" +
+ " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
+ "</span>";
+ }
+
} else {
if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
- console.log("adding some more headlines...");
+ console.log("adding some more headlines: " + headlines_count);
var c = dijit.byId("headlines-frame");
var ids = getSelectedArticleIds2();
+ var new_elems = [];
$("headlines-tmp").innerHTML = reply['headlines']['content'];
c.domNode.removeChild(hsp);
$$("#headlines-tmp > div").each(function(row) {
- if ($$("#headlines-frame DIV[id="+row.id+"]").length == 0) {
+ if (row.className == 'cdmFeedTitle') {
+ row.style.display = 'none';
+ c.domNode.appendChild(row);
+ new_elems.push(row);
+ } else if (loaded_article_ids.indexOf(row.id) == -1) {
row.style.display = 'none';
c.domNode.appendChild(row);
+ new_elems.push(row);
+ loaded_article_ids.push(row.id);
} else {
row.parentNode.removeChild(row);
}
c.domNode.appendChild(hsp);
}
+ console.log("added " + new_elems.size() + " headlines");
+
+ if (new_elems.size() == 0)
+ _infscroll_disable = true;
+
console.log("restore selected ids: " + ids);
for (var i = 0; i < ids.length; i++) {
initHeadlinesMenu();
- $$("#headlines-frame > div[id*=RROW]").each(
- function(child) {
- if (!Element.visible(child))
- new Effect.Appear(child, { duration : 0.5 });
+ new_elems.each(function(child) {
+ var cb = dijit.byId(child.id.replace("RROW-", "RCHK-"));
+
+ if (!cb) {
+ dojo.parser.parse(child);
+
+ if (!Element.visible(child))
+ new Effect.Appear(child, { duration : 0.5 });
+ } else {
+ c.domNode.removeChild(child);
+ }
});
} else {
else
request_counters();
- } else {
+ } else if (transport.responseText) {
console.error("Invalid object received: " + transport.responseText);
dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
__('Could not update headlines (invalid object received - see error console for details)') +
"</div>");
+ } else {
+ //notify_error("Error communicating with server.");
+ Element.show("net-alert");
}
_infscroll_request_sent = 0;
selectArticles('none');
- var upd_img_pic = $("FUPDPIC-" + id);
-
var view_mode = false;
try {
//
}
- if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
- upd_img_pic.src.match("fresh_sign.png"))) {
-
- upd_img_pic.src = "images/blank_icon.gif";
-
- cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
-
- } else if (article_is_unread && view_mode == "all_articles") {
+ if (article_is_unread && view_mode == "all_articles") {
cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML);
}
if (reply) {
- var upic = $('FUPDPIC-' + id);
-
- if (upic) upic.src = 'images/blank_icon.gif';
-
reply.each(function(article) {
if (active_post_id == article['id']) {
render_article(article['content']);
// return;
// }
- } else {
+ } else if (transport.responseText) {
console.error("Invalid object received: " + transport.responseText);
render_article("<div class='whiteBox'>" +
__('Could not display article (invalid object received - see error console for details)') + "</div>");
+ } else {
+ Element.show("net-alert");
}
request_counters();
- try {
+ headlines_scroll_handler($("headlines-frame"));
+
+/* try {
if (!_infscroll_disable &&
$$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
}
} catch (e) {
console.warn(e);
- }
+ } */
notify("");
} catch (e) {
precache_headlines();
- if (!cached_article) {
-
- var upic = $('FUPDPIC-' + id);
-
- if (upic) {
- upic.src = getInitParam("sign_progress");
- }
-
- } else if (cached_article && article_is_unread) {
+ if (cached_article && article_is_unread) {
query = query + "&mode=prefetch";
// the server roundtrip altogether
if (cids_to_request.length == 0) {
- try {
+/* try {
if (!_infscroll_disable &&
$$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
}
} catch (e) {
console.warn(e);
- }
+ } */
+
+ headlines_scroll_handler($("headlines-frame"));
return;
}
function toggleSelected(id, force_on) {
try {
- var cb = $("RCHK-" + id);
+ var cb = dijit.byId("RCHK-" + id);
var row = $("RROW-" + id);
if (row) {
if (row.hasClassName('Selected') && !force_on) {
row.removeClassName('Selected');
- if (cb) cb.checked = false;
+ if (cb) cb.attr("checked", false);
} else {
row.addClassName('Selected');
- if (cb) cb.checked = true;
+ if (cb) cb.attr("checked", true);
}
}
} catch (e) {
}
-// mode = all,none,unread,invert
+// mode = all,none,unread,invert,marked,published
function selectArticles(mode) {
try {
children.each(function(child) {
var id = child.id.replace("RROW-", "");
- var cb = $("RCHK-" + id);
+ var cb = dijit.byId("RCHK-" + id);
if (mode == "all") {
child.addClassName("Selected");
- cb.checked = true;
+ if (cb) cb.attr("checked", true);
} else if (mode == "unread") {
if (child.hasClassName("Unread")) {
child.addClassName("Selected");
- cb.checked = true;
+ if (cb) cb.attr("checked", true);
+ } else {
+ child.removeClassName("Selected");
+ if (cb) cb.attr("checked", false);
+ }
+ } else if (mode == "marked") {
+ var img = $("FMPIC-" + child.id.replace("RROW-", ""));
+
+ if (img && img.src.match("mark_set")) {
+ child.addClassName("Selected");
+ if (cb) cb.attr("checked", true);
+ } else {
+ child.removeClassName("Selected");
+ if (cb) cb.attr("checked", false);
+ }
+ } else if (mode == "published") {
+ var img = $("FPPIC-" + child.id.replace("RROW-", ""));
+
+ if (img && img.src.match("pub_set")) {
+ child.addClassName("Selected");
+ if (cb) cb.attr("checked", true);
} else {
child.removeClassName("Selected");
- cb.checked = false;
+ if (cb) cb.attr("checked", false);
}
+
} else if (mode == "invert") {
if (child.hasClassName("Selected")) {
child.removeClassName("Selected");
- cb.checked = false;
+ if (cb) cb.attr("checked", false);
} else {
child.addClassName("Selected");
- cb.checked = true;
+ if (cb) cb.attr("checked", true);
}
} else {
child.removeClassName("Selected");
- cb.checked = false;
+ if (cb) cb.attr("checked", false);
}
});
var hsp = $("headlines-spacer");
if (!_infscroll_disable) {
- if (hsp && (e.scrollTop + e.offsetHeight > hsp.offsetTop) ||
- e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
+ if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
+ (e.scrollHeight != 0 &&
+ ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
if (hsp)
hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " +
try {
if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
+ // make a copy of the array
+ var batch = catchup_id_batch.slice();
var query = "?op=rpc&method=catchupSelected" +
- "&cmode=0&ids=" + param_escape(catchup_id_batch.toString());
+ "&cmode=0&ids=" + param_escape(batch.toString());
+
+ console.log(query);
new Ajax.Request("backend.php", {
parameters: query,
onComplete: function(transport) {
handle_rpc_json(transport);
- catchup_id_batch.each(function(id) {
+ batch.each(function(id) {
var elem = $("RROW-" + id);
if (elem) elem.removeClassName("Unread");
+ catchup_id_batch.remove(id);
});
- catchup_id_batch = [];
} });
}
var elem = $("CICD-" + active_post_id);
- var upd_img_pic = $("FUPDPIC-" + id);
-
- if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
- upd_img_pic.src.match("fresh_sign.png"))) {
-
- upd_img_pic.src = "images/blank_icon.gif";
- }
-
if (id == active_post_id && Element.visible(elem))
return true;
if (!Element.visible(elem)) {
Element.show(elem);
Element.hide("CEXC-" + id);
-
- if ($("CWRAP-" + id).innerHTML == "") {
-
- $("FUPDPIC-" + id).src = "images/indicator_tiny.gif";
-
- $("CWRAP-" + id).innerHTML = "<div class=\"insensitive\">" +
- __("Loading, please wait...") + "</div>";
-
- var query = "?op=rpc&method=cdmGetArticle&id=" + param_escape(id);
-
- var neighbor_ids = getRelativePostIds(id);
-
- /* only request uncached articles */
- var cids_to_request = [];
-
- for (var i = 0; i < neighbor_ids.length; i++) {
- if (cids_requested.indexOf(neighbor_ids[i]) == -1)
- if ($("CWRAP-" + neighbor_ids[i]).innerHTML == "") {
- cids_to_request.push(neighbor_ids[i]);
- cids_requested.push(neighbor_ids[i]);
- }
- }
-
- console.log("additional ids: " + cids_to_request.toString());
-
- query = query + "&cids=" + cids_to_request.toString();
-
- console.log(query);
-
- new Ajax.Request("backend.php", {
- parameters: query,
- onComplete: function(transport) {
-
- $("FUPDPIC-" + id).src = 'images/blank_icon.gif';
-
- handle_rpc_json(transport);
-
- var reply = JSON.parse(transport.responseText);
-
- reply.each(function(article) {
- $("CWRAP-" + article['id']).innerHTML = article['content'];
- cids_requested.remove(article['id']);
- });
- }});
-
- }
}
var new_offset = $("RROW-" + id).offsetTop;
if (elem)
elem.removeClassName("Unread");
- var upd_img_pic = $("FUPDPIC-" + id);
-
- if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
- upd_img_pic.src.match("fresh_sign.png"))) {
-
- upd_img_pic.src = "images/blank_icon.gif";
- }
-
active_post_id = id;
if (article_is_unread) {
function markHeadline(id) {
var row = $("RROW-" + id);
if (row) {
- var check = $("RCHK-" + id);
+ var check = dijit.byId("RCHK-" + id);
if (check) {
- check.checked = true;
+ check.attr("checked", true);
}
row.addClassName("Selected");
var container = $("headlines-frame");
var row = $("RROW-" + id);
+ if (!container || !row) return;
+
var viewport = container.offsetHeight;
var rel_offset_top = row.offsetTop - container.scrollTop;
label: name,
labelId: bare_id,
onClick: function(event) {
- selectionAssignLabel(this.labelId,
- [this.getParent().ownerMenu.callerRowId]);
+ var ids = getSelectedArticleIds2();
+ // cast to string
+ var id = this.getParent().ownerMenu.callerRowId + "";
+
+ ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+ selectionAssignLabel(this.labelId, ids);
}}));
labelDelMenu.addChild(new dijit.MenuItem({
label: name,
labelId: bare_id,
onClick: function(event) {
- selectionRemoveLabel(this.labelId,
- [this.getParent().ownerMenu.callerRowId]);
+ var ids = getSelectedArticleIds2();
+ // cast to string
+ var id = this.getParent().ownerMenu.callerRowId + "";
+
+ ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
+
+ selectionRemoveLabel(this.labelId, ids);
}}));
});
setActiveFeedId(feed, is_cat);
initHeadlinesMenu();
+ dijit.getEnclosingWidget(
+ document.forms["main_toolbar_form"].update).attr('disabled',
+ is_cat || feed <= 0);
+
precache_headlines();
} catch (e) {
function precache_headlines_idle() {
try {
if (!feed_precache_timeout_id) {
- var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
- var uncached = [];
+ if (get_timestamp() - _viewfeed_last > 120) {
- feeds.each(function(item) {
- if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
- uncached.push(item);
- });
+ var feeds = dijit.byId("feedTree").getVisibleUnreadFeeds();
+ var uncached = [];
- if (uncached.length > 0) {
- var rf = uncached[Math.floor(Math.random()*uncached.length)];
- viewfeed(rf[0], '', rf[1], 0, true);
+ feeds.each(function(item) {
+ if (parseInt(item[0]) > 0 && !cache_get("feed:" + item[0] + ":" + item[1]))
+ uncached.push(item);
+ });
+
+ if (uncached.length > 0) {
+ var rf = uncached[Math.floor(Math.random()*uncached.length)];
+ viewfeed(rf[0], '', rf[1], 0, true);
+ }
}
}
precache_idle_timeout_id = setTimeout("precache_headlines_idle()", 1000*30);
if (nuf && !cache_get("feed:" + nuf + ":" + activeFeedIsCat()))
viewfeed(nuf, '', activeFeedIsCat(), 0, true);
- if (nf != nuf && nf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
+ if (nf && nf[0] != nuf && !cache_get("feed:" + nf[0] + ":" + nf[1]))
viewfeed(nf[0], '', nf[1], 0, true);
window.setTimeout(function() {
}
}
+function cancelSearch() {
+ try {
+ _search_query = "";
+ viewCurrentFeed();
+ } catch (e) {
+ exception_error("cancelSearch", e);
+ }
+}
+
+function setSelectionScore() {
+ try {
+ var ids = getSelectedArticleIds2();
+
+ if (ids.length > 0) {
+ console.log(ids);
+
+ var score = prompt(__("Please enter new score for selected articles:"), score);
+
+ if (score != undefined) {
+ var query = "op=rpc&method=setScore&id=" + param_escape(ids.toString()) +
+ "&score=" + param_escape(score);
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ var reply = JSON.parse(transport.responseText);
+ if (reply) {
+ console.log(ids);
+
+ ids.each(function(id) {
+ var row = $("RROW-" + id);
+
+ if (row) {
+ var pic = row.getElementsByClassName("hlScorePic")[0];
+
+ if (pic) {
+ pic.src = pic.src.replace(/score_.*?\.png/,
+ reply["score_pic"]);
+ pic.setAttribute("score", score);
+ }
+ }
+ });
+ }
+ } });
+ }
+
+ } else {
+ alert(__("No articles are selected."));
+ }
+ } catch (e) {
+ exception_error("setSelectionScore", e);
+ }
+}
+
+function changeScore(id, pic) {
+ try {
+ var score = pic.getAttribute("score");
+
+ var new_score = prompt(__("Please enter new score for this article:"), score);
+
+ if (new_score != undefined) {
+
+ var query = "op=rpc&method=setScore&id=" + param_escape(id) +
+ "&score=" + param_escape(new_score);
+
+ new Ajax.Request("backend.php", {
+ parameters: query,
+ onComplete: function(transport) {
+ var reply = JSON.parse(transport.responseText);
+
+ if (reply) {
+ pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
+ pic.setAttribute("score", new_score);
+ }
+ } });
+ }
+ } catch (e) {
+ exception_error("changeScore", e);
+ }
+}