1 var active_post_id = false;
2 var _catchup_callback_func = false;
3 var last_article_view = false;
4 var active_real_feed_id = false;
6 var _tag_active_post_id = false;
7 var _tag_active_feed_id = false;
8 var _tag_active_cdm = false;
10 // FIXME: kludge, to restore scrollTop after tag editor terminates
11 var _tag_cdm_scroll = false;
13 // FIXME: kludges, needs proper implementation
14 var _reload_feedlist_after_view = false;
16 var _cdm_wd_timeout = false;
17 var _cdm_wd_vishist = new Array();
19 function catchup_callback() {
20 if (xmlhttp_rpc.readyState == 4) {
22 debug("catchup_callback");
23 if (_catchup_callback_func) {
24 setTimeout(_catchup_callback_func, 100);
27 all_counters_callback();
29 exception_error("catchup_callback", e);
34 function headlines_callback() {
35 if (xmlhttp.readyState == 4) {
36 debug("headlines_callback");
37 var f = document.getElementById("headlines-frame");
41 f.innerHTML = xmlhttp.responseText;
42 update_all_counters();
43 if (typeof correctPNG != 'undefined') {
47 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
49 if (!document.getElementById("headlinesList") &&
50 getInitParam("cdm_auto_catchup") == 1) {
51 debug("starting CDM watchdog");
52 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
53 _cdm_wd_vishist = new Array();
55 debug("not in CDM mode or watchdog disabled");
58 if (_tag_cdm_scroll) {
60 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
61 _tag_cdm_scroll = false;
69 function article_callback() {
70 if (xmlhttp.readyState == 4) {
71 debug("article_callback");
72 var f = document.getElementById("content-frame");
76 f.innerHTML = xmlhttp.responseText;
78 var date = new Date();
79 last_article_view = date.getTime() / 1000;
81 if (typeof correctPNG != 'undefined') {
85 if (_reload_feedlist_after_view) {
86 setTimeout('updateFeedList(false, false)', 50);
87 _reload_feedlist_after_view = false;
89 update_all_counters();
96 function view(id, feed_id, skip_history) {
99 debug("loading article: " + id + "/" + feed_id);
101 active_real_feed_id = feed_id;
104 history_push("ARTICLE:" + id + ":" + feed_id);
110 //setActiveFeedId(feed_id);
112 var query = "backend.php?op=view&id=" + param_escape(id) +
113 "&feed=" + param_escape(feed_id);
115 var date = new Date();
117 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
118 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
122 if (xmlhttp_ready(xmlhttp)) {
124 cleanSelected("headlinesList");
126 var crow = document.getElementById("RROW-" + active_post_id);
127 crow.className = crow.className.replace("Unread", "");
129 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
132 upd_img_pic.src = "images/blank_icon.gif";
135 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
136 markHeadline(active_post_id);
138 var date = new Date();
139 var timestamp = Math.round(date.getTime() / 1000);
140 query = query + "&ts=" + timestamp;
142 notify_progress("Loading, please wait...");
144 xmlhttp.open("GET", query, true);
145 xmlhttp.onreadystatechange=article_callback;
148 debug("xmlhttp busy (@view)");
153 exception_error("view", e);
157 function toggleMark(id) {
159 if (!xmlhttp_ready(xmlhttp_rpc)) {
164 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
166 var mark_img = document.getElementById("FMARKPIC-" + id);
167 var vfeedu = document.getElementById("FEEDU--1");
168 var crow = document.getElementById("RROW-" + id);
170 if (mark_img.alt != "Reset mark") {
171 mark_img.src = "images/mark_set.png";
172 mark_img.alt = "Reset mark";
173 query = query + "&mark=1";
175 if (vfeedu && crow.className.match("Unread")) {
176 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
180 mark_img.src = "images/mark_unset.png";
181 mark_img.alt = "Set mark";
182 query = query + "&mark=0";
184 if (vfeedu && crow.className.match("Unread")) {
185 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
190 var vfeedctr = document.getElementById("FEEDCTR--1");
191 var vfeedr = document.getElementById("FEEDR--1");
193 if (vfeedu && vfeedctr) {
194 if ((+vfeedu.innerHTML) > 0) {
195 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
196 vfeedr.className = vfeedr.className + "Unread";
197 vfeedctr.className = "odd";
200 vfeedctr.className = "invisible";
201 vfeedr.className = vfeedr.className.replace("Unread", "");
205 debug("toggle starred for aid " + id);
207 new Ajax.Request(query);
211 function moveToPost(mode) {
213 // check for combined mode
214 if (!document.getElementById("headlinesList"))
217 var rows = getVisibleHeadlineIds();
222 if (!document.getElementById('RROW-' + active_post_id)) {
223 active_post_id = false;
226 if (active_post_id == false) {
227 next_id = getFirstVisibleHeadlineId();
228 prev_id = getLastVisibleHeadlineId();
230 for (var i = 0; i < rows.length; i++) {
231 if (rows[i] == active_post_id) {
238 if (mode == "next") {
239 if (next_id != undefined) {
240 view(next_id, getActiveFeedId());
244 if (mode == "prev") {
245 if ( prev_id != undefined) {
246 view(prev_id, getActiveFeedId());
251 function toggleUnread(id, cmode) {
253 if (!xmlhttp_ready(xmlhttp_rpc)) {
258 var row = document.getElementById("RROW-" + id);
260 var nc = row.className;
261 nc = nc.replace("Unread", "");
262 nc = nc.replace("Selected", "");
264 if (row.className.match("Unread")) {
267 row.className = nc + "Unread";
270 if (!cmode) cmode = 2;
272 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
273 param_escape(id) + "&cmode=" + param_escape(cmode);
275 notify_progress("Loading, please wait...");
277 xmlhttp_rpc.open("GET", query, true);
278 xmlhttp_rpc.onreadystatechange=all_counters_callback;
279 xmlhttp_rpc.send(null);
285 exception_error("toggleUnread", e);
289 function selectionToggleUnread(cdm_mode, set_state, callback_func) {
291 if (!xmlhttp_ready(xmlhttp_rpc)) {
299 rows = cdmGetSelectedArticles();
301 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
304 if (rows.length == 0) {
305 alert(__("No articles are selected."));
309 for (i = 0; i < rows.length; i++) {
310 var row = document.getElementById("RROW-" + rows[i]);
312 var nc = row.className;
313 nc = nc.replace("Unread", "");
314 nc = nc.replace("Selected", "");
316 if (row.className.match("Unread")) {
317 row.className = nc + "Selected";
319 row.className = nc + "UnreadSelected";
324 if (rows.length > 0) {
328 if (set_state == undefined) {
330 } else if (set_state == true) {
332 } else if (set_state == false) {
336 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
337 param_escape(rows.toString()) + "&cmode=" + cmode;
339 _catchup_callback_func = callback_func;
341 notify_progress("Loading, please wait...");
343 xmlhttp_rpc.open("GET", query, true);
344 xmlhttp_rpc.onreadystatechange=catchup_callback;
345 xmlhttp_rpc.send(null);
350 exception_error("selectionToggleUnread", e);
354 function selectionToggleMarked(cdm_mode) {
356 if (!xmlhttp_ready(xmlhttp_rpc)) {
364 rows = cdmGetSelectedArticles();
366 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
369 if (rows.length == 0) {
370 alert(__("No articles are selected."));
374 for (i = 0; i < rows.length; i++) {
375 var row = document.getElementById("RROW-" + rows[i]);
376 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
378 if (row && mark_img) {
380 if (mark_img.alt == "Set mark") {
381 mark_img.src = "images/mark_set.png";
382 mark_img.alt = "Reset mark";
383 mark_img.setAttribute('onclick',
384 'javascript:toggleMark('+rows[i]+', false)');
387 mark_img.src = "images/mark_unset.png";
388 mark_img.alt = "Set mark";
389 mark_img.setAttribute('onclick',
390 'javascript:toggleMark('+rows[i]+', true)');
395 if (rows.length > 0) {
397 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
398 param_escape(rows.toString()) + "&cmode=2";
400 xmlhttp_rpc.open("GET", query, true);
401 xmlhttp_rpc.onreadystatechange=all_counters_callback;
402 xmlhttp_rpc.send(null);
407 exception_error("selectionToggleMarked", e);
411 function cdmGetSelectedArticles() {
412 var sel_articles = new Array();
413 var container = document.getElementById("headlinesInnerContainer");
415 for (i = 0; i < container.childNodes.length; i++) {
416 var child = container.childNodes[i];
418 if (child.id.match("RROW-") && child.className.match("Selected")) {
419 var c_id = child.id.replace("RROW-", "");
420 sel_articles.push(c_id);
427 // mode = all,none,unread
428 function cdmSelectArticles(mode) {
429 var container = document.getElementById("headlinesInnerContainer");
431 for (i = 0; i < container.childNodes.length; i++) {
432 var child = container.childNodes[i];
434 if (child.id.match("RROW-")) {
435 var aid = child.id.replace("RROW-", "");
437 var cb = document.getElementById("RCHK-" + aid);
440 if (!child.className.match("Selected")) {
441 child.className = child.className + "Selected";
444 } else if (mode == "unread") {
445 if (child.className.match("Unread") && !child.className.match("Selected")) {
446 child.className = child.className + "Selected";
450 child.className = child.className.replace("Selected", "");
457 function catchupPage() {
459 if (document.getElementById("headlinesList")) {
460 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
461 selectionToggleUnread(false, false, 'viewCurrentFeed()');
462 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
464 cdmSelectArticles('all');
465 selectionToggleUnread(true, false, 'viewCurrentFeed()')
466 cdmSelectArticles('none');
470 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
472 if (!xmlhttp_ready(xmlhttp_rpc)) {
476 var title = prompt("Please enter label title:", "");
480 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
481 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
482 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
483 "&title=" + param_escape(title);
485 debug("LFS: " + query);
487 xmlhttp_rpc.open("GET", query, true);
488 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
489 xmlhttp_rpc.send(null);
494 function editArticleTags(id, feed_id, cdm_enabled) {
495 _tag_active_post_id = id;
496 _tag_active_feed_id = feed_id;
497 _tag_active_cdm = cdm_enabled;
499 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
501 displayDlg('editArticleTags', id);
505 function tag_saved_callback() {
506 if (xmlhttp_rpc.readyState == 4) {
508 debug("in tag_saved_callback");
513 if (tagsAreDisplayed()) {
514 _reload_feedlist_after_view = true;
517 if (!_tag_active_cdm) {
518 if (active_post_id == _tag_active_post_id) {
519 debug("reloading current article");
520 view(_tag_active_post_id, _tag_active_feed_id);
523 debug("reloading current feed");
528 exception_error("catchup_callback", e);
533 function editTagsSave() {
535 if (!xmlhttp_ready(xmlhttp_rpc)) {
539 notify_progress("Saving article tags...");
541 var form = document.forms["tag_edit_form"];
543 var query = Form.serialize("tag_edit_form");
545 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);
546 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
547 xmlhttp_rpc.send(null);
551 function editTagsInsert() {
554 var form = document.forms["tag_edit_form"];
556 var found_tags = form.found_tags;
557 var tags_str = form.tags_str;
559 var tag = found_tags[found_tags.selectedIndex].value;
561 if (tags_str.value.length > 0 &&
562 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
564 tags_str.value = tags_str.value + ", ";
567 tags_str.value = tags_str.value + tag + ", ";
569 found_tags.selectedIndex = 0;
572 exception_error(e, "editTagsInsert");
576 function cdmWatchdog() {
580 var ctr = document.getElementById("headlinesInnerContainer");
584 var ids = new Array();
586 var e = ctr.firstChild;
589 if (e.className && e.className == "cdmArticleUnread" && e.id &&
590 e.id.match("RROW-")) {
592 // article fits in viewport OR article is longer than viewport and
593 // its bottom is visible
595 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
596 ctr.scrollTop + ctr.offsetHeight) {
598 // debug(e.id + " is visible " + e.offsetTop + "." +
599 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
600 // (ctr.scrollTop + ctr.offsetHeight));
602 ids.push(e.id.replace("RROW-", ""));
604 } else if (e.offsetHeight > ctr.offsetHeight &&
605 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
606 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
608 ids.push(e.id.replace("RROW-", ""));
612 // method 2: article bottom is visible and is in upper 1/2 of the viewport
614 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
615 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
617 ids.push(e.id.replace("RROW-", ""));
626 debug("cdmWatchdog, ids= " + ids.toString());
628 if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
630 for (var i = 0; i < ids.length; i++) {
631 var e = document.getElementById("RROW-" + ids[i]);
633 e.className = e.className.replace("Unread", "");
637 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
638 param_escape(ids.toString()) + "&cmode=0";
640 xmlhttp_rpc.open("GET", query, true);
641 xmlhttp_rpc.onreadystatechange=all_counters_callback;
642 xmlhttp_rpc.send(null);
646 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
649 exception_error(e, "cdmWatchdog");