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 debug("starting CDM watchdog");
51 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
52 _cdm_wd_vishist = new Array();
55 if (_tag_cdm_scroll) {
57 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
58 _tag_cdm_scroll = false;
66 function article_callback() {
67 if (xmlhttp.readyState == 4) {
68 debug("article_callback");
69 var f = document.getElementById("content-frame");
73 f.innerHTML = xmlhttp.responseText;
75 var date = new Date();
76 last_article_view = date.getTime() / 1000;
78 if (typeof correctPNG != 'undefined') {
82 if (_reload_feedlist_after_view) {
83 setTimeout('updateFeedList(false, false)', 50);
84 _reload_feedlist_after_view = false;
86 update_all_counters();
93 function view(id, feed_id, skip_history) {
96 debug("loading article: " + id + "/" + feed_id);
98 active_real_feed_id = feed_id;
101 history_push("ARTICLE:" + id + ":" + feed_id);
107 //setActiveFeedId(feed_id);
109 var query = "backend.php?op=view&id=" + param_escape(id) +
110 "&feed=" + param_escape(feed_id);
112 var date = new Date();
114 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
115 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
119 if (xmlhttp_ready(xmlhttp)) {
121 cleanSelected("headlinesList");
123 var crow = document.getElementById("RROW-" + active_post_id);
124 crow.className = crow.className.replace("Unread", "");
126 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
129 upd_img_pic.src = "images/blank_icon.gif";
132 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
133 markHeadline(active_post_id);
135 var date = new Date();
136 var timestamp = Math.round(date.getTime() / 1000);
137 query = query + "&ts=" + timestamp;
139 notify_progress("Loading, please wait...");
141 xmlhttp.open("GET", query, true);
142 xmlhttp.onreadystatechange=article_callback;
145 debug("xmlhttp busy (@view)");
150 exception_error("view", e);
154 function toggleMark(id) {
156 if (!xmlhttp_ready(xmlhttp_rpc)) {
161 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
163 var mark_img = document.getElementById("FMARKPIC-" + id);
164 var vfeedu = document.getElementById("FEEDU--1");
165 var crow = document.getElementById("RROW-" + id);
167 if (mark_img.alt != "Reset mark") {
168 mark_img.src = "images/mark_set.png";
169 mark_img.alt = "Reset mark";
170 query = query + "&mark=1";
172 if (vfeedu && crow.className.match("Unread")) {
173 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
177 mark_img.src = "images/mark_unset.png";
178 mark_img.alt = "Set mark";
179 query = query + "&mark=0";
181 if (vfeedu && crow.className.match("Unread")) {
182 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
187 var vfeedctr = document.getElementById("FEEDCTR--1");
188 var vfeedr = document.getElementById("FEEDR--1");
190 if (vfeedu && vfeedctr) {
191 if ((+vfeedu.innerHTML) > 0) {
192 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
193 vfeedr.className = vfeedr.className + "Unread";
194 vfeedctr.className = "odd";
197 vfeedctr.className = "invisible";
198 vfeedr.className = vfeedr.className.replace("Unread", "");
202 debug("toggle starred for aid " + id);
204 new Ajax.Request(query);
208 function moveToPost(mode) {
210 // check for combined mode
211 if (!document.getElementById("headlinesList"))
214 var rows = getVisibleHeadlineIds();
219 if (!document.getElementById('RROW-' + active_post_id)) {
220 active_post_id = false;
223 if (active_post_id == false) {
224 next_id = getFirstVisibleHeadlineId();
225 prev_id = getLastVisibleHeadlineId();
227 for (var i = 0; i < rows.length; i++) {
228 if (rows[i] == active_post_id) {
235 if (mode == "next") {
236 if (next_id != undefined) {
237 view(next_id, getActiveFeedId());
241 if (mode == "prev") {
242 if ( prev_id != undefined) {
243 view(prev_id, getActiveFeedId());
248 function toggleUnread(id, cmode) {
250 if (!xmlhttp_ready(xmlhttp_rpc)) {
255 var row = document.getElementById("RROW-" + id);
257 var nc = row.className;
258 nc = nc.replace("Unread", "");
259 nc = nc.replace("Selected", "");
261 if (row.className.match("Unread")) {
264 row.className = nc + "Unread";
267 if (!cmode) cmode = 2;
269 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
270 param_escape(id) + "&cmode=" + param_escape(cmode);
272 notify_progress("Loading, please wait...");
274 xmlhttp_rpc.open("GET", query, true);
275 xmlhttp_rpc.onreadystatechange=all_counters_callback;
276 xmlhttp_rpc.send(null);
282 exception_error("toggleUnread", e);
286 function selectionToggleUnread(cdm_mode, set_state, callback_func) {
288 if (!xmlhttp_ready(xmlhttp_rpc)) {
296 rows = cdmGetSelectedArticles();
298 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
301 for (i = 0; i < rows.length; i++) {
302 var row = document.getElementById("RROW-" + rows[i]);
304 var nc = row.className;
305 nc = nc.replace("Unread", "");
306 nc = nc.replace("Selected", "");
308 if (row.className.match("Unread")) {
309 row.className = nc + "Selected";
311 row.className = nc + "UnreadSelected";
316 if (rows.length > 0) {
320 if (set_state == undefined) {
322 } else if (set_state == true) {
324 } else if (set_state == false) {
328 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
329 param_escape(rows.toString()) + "&cmode=" + cmode;
331 _catchup_callback_func = callback_func;
333 notify_progress("Loading, please wait...");
335 xmlhttp_rpc.open("GET", query, true);
336 xmlhttp_rpc.onreadystatechange=catchup_callback;
337 xmlhttp_rpc.send(null);
342 exception_error("selectionToggleUnread", e);
346 function selectionToggleMarked(cdm_mode) {
348 if (!xmlhttp_ready(xmlhttp_rpc)) {
356 rows = cdmGetSelectedArticles();
358 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
361 for (i = 0; i < rows.length; i++) {
362 var row = document.getElementById("RROW-" + rows[i]);
363 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
365 if (row && mark_img) {
367 if (mark_img.alt == "Set mark") {
368 mark_img.src = "images/mark_set.png";
369 mark_img.alt = "Reset mark";
370 mark_img.setAttribute('onclick',
371 'javascript:toggleMark('+rows[i]+', false)');
374 mark_img.src = "images/mark_unset.png";
375 mark_img.alt = "Set mark";
376 mark_img.setAttribute('onclick',
377 'javascript:toggleMark('+rows[i]+', true)');
382 if (rows.length > 0) {
384 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
385 param_escape(rows.toString()) + "&cmode=2";
387 xmlhttp_rpc.open("GET", query, true);
388 xmlhttp_rpc.onreadystatechange=all_counters_callback;
389 xmlhttp_rpc.send(null);
394 exception_error("selectionToggleMarked", e);
398 function cdmGetSelectedArticles() {
399 var sel_articles = new Array();
400 var container = document.getElementById("headlinesInnerContainer");
402 for (i = 0; i < container.childNodes.length; i++) {
403 var child = container.childNodes[i];
405 if (child.id.match("RROW-") && child.className.match("Selected")) {
406 var c_id = child.id.replace("RROW-", "");
407 sel_articles.push(c_id);
414 // mode = all,none,unread
415 function cdmSelectArticles(mode) {
416 var container = document.getElementById("headlinesInnerContainer");
418 for (i = 0; i < container.childNodes.length; i++) {
419 var child = container.childNodes[i];
421 if (child.id.match("RROW-")) {
422 var aid = child.id.replace("RROW-", "");
424 var cb = document.getElementById("RCHK-" + aid);
427 if (!child.className.match("Selected")) {
428 child.className = child.className + "Selected";
431 } else if (mode == "unread") {
432 if (child.className.match("Unread") && !child.className.match("Selected")) {
433 child.className = child.className + "Selected";
437 child.className = child.className.replace("Selected", "");
444 function catchupPage() {
446 if (document.getElementById("headlinesList")) {
447 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
448 selectionToggleUnread(false, false, 'viewCurrentFeed()');
449 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
451 cdmSelectArticles('all');
452 selectionToggleUnread(true, false, 'viewCurrentFeed()')
453 cdmSelectArticles('none');
457 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
459 if (!xmlhttp_ready(xmlhttp_rpc)) {
463 var title = prompt("Please enter label title:", "");
467 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
468 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
469 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
470 "&title=" + param_escape(title);
472 debug("LFS: " + query);
474 xmlhttp_rpc.open("GET", query, true);
475 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
476 xmlhttp_rpc.send(null);
481 function editArticleTags(id, feed_id, cdm_enabled) {
482 _tag_active_post_id = id;
483 _tag_active_feed_id = feed_id;
484 _tag_active_cdm = cdm_enabled;
486 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
488 displayDlg('editArticleTags', id);
492 function tag_saved_callback() {
493 if (xmlhttp_rpc.readyState == 4) {
495 debug("in tag_saved_callback");
500 if (tagsAreDisplayed()) {
501 _reload_feedlist_after_view = true;
504 if (!_tag_active_cdm) {
505 if (active_post_id == _tag_active_post_id) {
506 debug("reloading current article");
507 view(_tag_active_post_id, _tag_active_feed_id);
510 debug("reloading current feed");
515 exception_error("catchup_callback", e);
520 function editTagsSave() {
522 if (!xmlhttp_ready(xmlhttp_rpc)) {
526 notify_progress("Saving article tags...");
528 var form = document.forms["tag_edit_form"];
530 var query = Form.serialize("tag_edit_form");
532 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);
533 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
534 xmlhttp_rpc.send(null);
538 function editTagsInsert() {
541 var form = document.forms["tag_edit_form"];
543 var found_tags = form.found_tags;
544 var tags_str = form.tags_str;
546 var tag = found_tags[found_tags.selectedIndex].value;
548 if (tags_str.value.length > 0 &&
549 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
551 tags_str.value = tags_str.value + ", ";
554 tags_str.value = tags_str.value + tag + ", ";
556 found_tags.selectedIndex = 0;
559 exception_error(e, "editTagsInsert");
563 function cdmWatchdog() {
567 var ctr = document.getElementById("headlinesInnerContainer");
571 var ids = new Array();
573 var e = ctr.firstChild;
576 if (e.className && e.className == "cdmArticleUnread" && e.id &&
577 e.id.match("RROW-")) {
579 // article fits in viewport OR article is longer than viewport and
580 // its bottom is visible
582 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
583 ctr.scrollTop + ctr.offsetHeight) {
585 // debug(e.id + " is visible " + e.offsetTop + "." +
586 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
587 // (ctr.scrollTop + ctr.offsetHeight));
589 ids.push(e.id.replace("RROW-", ""));
591 } else if (e.offsetHeight > ctr.offsetHeight &&
592 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
593 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
595 ids.push(e.id.replace("RROW-", ""));
599 // method 2: article bottom is visible and is in upper 1/2 of the viewport
601 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
602 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
604 ids.push(e.id.replace("RROW-", ""));
613 debug("cdmWatchdog, ids= " + ids.toString());
615 if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
617 for (var i = 0; i < ids.length; i++) {
618 var e = document.getElementById("RROW-" + ids[i]);
620 e.className = e.className.replace("Unread", "");
624 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
625 param_escape(ids.toString()) + "&cmode=0";
627 xmlhttp_rpc.open("GET", query, true);
628 xmlhttp_rpc.onreadystatechange=all_counters_callback;
629 xmlhttp_rpc.send(null);
633 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
636 exception_error(e, "cdmWatchdog");