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);
26 all_counters_callback();
28 exception_error("catchup_callback", e);
33 function headlines_callback() {
34 if (xmlhttp.readyState == 4) {
35 debug("headlines_callback");
36 var f = document.getElementById("headlines-frame");
40 f.innerHTML = xmlhttp.responseText;
41 update_all_counters();
42 if (typeof correctPNG != 'undefined') {
46 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
48 if (!document.getElementById("headlinesList")) {
49 debug("starting CDM watchdog");
50 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
51 _cdm_wd_vishist = new Array();
54 if (_tag_cdm_scroll) {
56 document.getElementById("headlinesInnerContainer").scrollTop = _tag_cdm_scroll;
57 _tag_cdm_scroll = false;
65 function article_callback() {
66 if (xmlhttp.readyState == 4) {
67 debug("article_callback");
68 var f = document.getElementById("content-frame");
72 f.innerHTML = xmlhttp.responseText;
74 var date = new Date();
75 last_article_view = date.getTime() / 1000;
77 if (typeof correctPNG != 'undefined') {
81 if (_reload_feedlist_after_view) {
82 setTimeout('updateFeedList(false, false)', 50);
83 _reload_feedlist_after_view = false;
85 update_all_counters();
90 function view(id, feed_id, skip_history) {
93 debug("loading article: " + id + "/" + feed_id);
95 active_real_feed_id = feed_id;
98 history_push("ARTICLE:" + id + ":" + feed_id);
104 //setActiveFeedId(feed_id);
106 var query = "backend.php?op=view&id=" + param_escape(id) +
107 "&feed=" + param_escape(feed_id);
109 var date = new Date();
111 if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
112 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
116 if (xmlhttp_ready(xmlhttp)) {
118 cleanSelected("headlinesList");
120 var crow = document.getElementById("RROW-" + active_post_id);
121 crow.className = crow.className.replace("Unread", "");
123 var upd_img_pic = document.getElementById("FUPDPIC-" + active_post_id);
126 upd_img_pic.src = "images/blank_icon.gif";
129 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
130 markHeadline(active_post_id);
132 xmlhttp.open("GET", query, true);
133 xmlhttp.onreadystatechange=article_callback;
136 debug("xmlhttp busy (@view)");
141 exception_error("view", e);
145 function toggleMark(id) {
147 if (!xmlhttp_ready(xmlhttp_rpc)) {
152 var query = "backend.php?op=rpc&id=" + id + "&subop=mark";
154 var mark_img = document.getElementById("FMARKPIC-" + id);
155 var vfeedu = document.getElementById("FEEDU--1");
156 var crow = document.getElementById("RROW-" + id);
158 if (mark_img.alt != "Reset mark") {
159 mark_img.src = "images/mark_set.png";
160 mark_img.alt = "Reset mark";
161 query = query + "&mark=1";
163 if (vfeedu && crow.className.match("Unread")) {
164 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
168 mark_img.src = "images/mark_unset.png";
169 mark_img.alt = "Set mark";
170 query = query + "&mark=0";
172 if (vfeedu && crow.className.match("Unread")) {
173 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
178 var vfeedctr = document.getElementById("FEEDCTR--1");
179 var vfeedr = document.getElementById("FEEDR--1");
181 if (vfeedu && vfeedctr) {
182 if ((+vfeedu.innerHTML) > 0) {
183 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
184 vfeedr.className = vfeedr.className + "Unread";
185 vfeedctr.className = "odd";
188 vfeedctr.className = "invisible";
189 vfeedr.className = vfeedr.className.replace("Unread", "");
193 debug("toggle starred for aid " + id);
195 new Ajax.Request(query);
199 function moveToPost(mode) {
201 // check for combined mode
202 if (!document.getElementById("headlinesList"))
205 var rows = getVisibleHeadlineIds();
210 if (!document.getElementById('RROW-' + active_post_id)) {
211 active_post_id = false;
214 if (active_post_id == false) {
215 next_id = getFirstVisibleHeadlineId();
216 prev_id = getLastVisibleHeadlineId();
218 for (var i = 0; i < rows.length; i++) {
219 if (rows[i] == active_post_id) {
226 if (mode == "next") {
227 if (next_id != undefined) {
228 view(next_id, getActiveFeedId());
232 if (mode == "prev") {
233 if ( prev_id != undefined) {
234 view(prev_id, getActiveFeedId());
239 function toggleUnread(id, cmode) {
241 if (!xmlhttp_ready(xmlhttp_rpc)) {
246 var row = document.getElementById("RROW-" + id);
248 var nc = row.className;
249 nc = nc.replace("Unread", "");
250 nc = nc.replace("Selected", "");
252 if (row.className.match("Unread")) {
255 row.className = nc + "Unread";
258 if (!cmode) cmode = 2;
260 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
261 param_escape(id) + "&cmode=" + param_escape(cmode);
263 xmlhttp_rpc.open("GET", query, true);
264 xmlhttp_rpc.onreadystatechange=all_counters_callback;
265 xmlhttp_rpc.send(null);
271 exception_error("toggleUnread", e);
275 function selectionToggleUnread(cdm_mode, set_state, callback_func) {
277 if (!xmlhttp_ready(xmlhttp_rpc)) {
285 rows = cdmGetSelectedArticles();
287 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
290 for (i = 0; i < rows.length; i++) {
291 var row = document.getElementById("RROW-" + rows[i]);
293 var nc = row.className;
294 nc = nc.replace("Unread", "");
295 nc = nc.replace("Selected", "");
297 if (row.className.match("Unread")) {
298 row.className = nc + "Selected";
300 row.className = nc + "UnreadSelected";
305 if (rows.length > 0) {
309 if (set_state == undefined) {
311 } else if (set_state == true) {
313 } else if (set_state == false) {
317 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
318 param_escape(rows.toString()) + "&cmode=" + cmode;
320 _catchup_callback_func = callback_func;
322 xmlhttp_rpc.open("GET", query, true);
323 xmlhttp_rpc.onreadystatechange=catchup_callback;
324 xmlhttp_rpc.send(null);
329 exception_error("selectionToggleUnread", e);
333 function selectionToggleMarked(cdm_mode) {
335 if (!xmlhttp_ready(xmlhttp_rpc)) {
343 rows = cdmGetSelectedArticles();
345 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
348 for (i = 0; i < rows.length; i++) {
349 var row = document.getElementById("RROW-" + rows[i]);
350 var mark_img = document.getElementById("FMARKPIC-" + rows[i]);
352 if (row && mark_img) {
354 if (mark_img.alt == "Set mark") {
355 mark_img.src = "images/mark_set.png";
356 mark_img.alt = "Reset mark";
357 mark_img.setAttribute('onclick',
358 'javascript:toggleMark('+rows[i]+', false)');
361 mark_img.src = "images/mark_unset.png";
362 mark_img.alt = "Set mark";
363 mark_img.setAttribute('onclick',
364 'javascript:toggleMark('+rows[i]+', true)');
369 if (rows.length > 0) {
371 var query = "backend.php?op=rpc&subop=markSelected&ids=" +
372 param_escape(rows.toString()) + "&cmode=2";
374 xmlhttp_rpc.open("GET", query, true);
375 xmlhttp_rpc.onreadystatechange=all_counters_callback;
376 xmlhttp_rpc.send(null);
381 exception_error("selectionToggleMarked", e);
385 function cdmGetSelectedArticles() {
386 var sel_articles = new Array();
387 var container = document.getElementById("headlinesInnerContainer");
389 for (i = 0; i < container.childNodes.length; i++) {
390 var child = container.childNodes[i];
392 if (child.id.match("RROW-") && child.className.match("Selected")) {
393 var c_id = child.id.replace("RROW-", "");
394 sel_articles.push(c_id);
401 // mode = all,none,unread
402 function cdmSelectArticles(mode) {
403 var container = document.getElementById("headlinesInnerContainer");
405 for (i = 0; i < container.childNodes.length; i++) {
406 var child = container.childNodes[i];
408 if (child.id.match("RROW-")) {
409 var aid = child.id.replace("RROW-", "");
411 var cb = document.getElementById("RCHK-" + aid);
414 if (!child.className.match("Selected")) {
415 child.className = child.className + "Selected";
418 } else if (mode == "unread") {
419 if (child.className.match("Unread") && !child.className.match("Selected")) {
420 child.className = child.className + "Selected";
424 child.className = child.className.replace("Selected", "");
431 function catchupPage() {
433 if (document.getElementById("headlinesList")) {
434 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
435 selectionToggleUnread(false, false, 'viewCurrentFeed()');
436 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
438 cdmSelectArticles('all');
439 selectionToggleUnread(true, false, 'viewCurrentFeed()')
440 cdmSelectArticles('none');
444 function labelFromSearch(search, search_mode, match_on, feed_id, is_cat) {
446 if (!xmlhttp_ready(xmlhttp_rpc)) {
450 var title = prompt("Please enter label title:", "");
454 var query = "backend.php?op=labelFromSearch&search=" + param_escape(search) +
455 "&smode=" + param_escape(search_mode) + "&match=" + param_escape(match_on) +
456 "&feed=" + param_escape(feed_id) + "&is_cat=" + param_escape(is_cat) +
457 "&title=" + param_escape(title);
459 debug("LFS: " + query);
461 xmlhttp_rpc.open("GET", query, true);
462 xmlhttp_rpc.onreadystatechange=dlg_frefresh_callback;
463 xmlhttp_rpc.send(null);
468 function editArticleTags(id, feed_id, cdm_enabled) {
469 _tag_active_post_id = id;
470 _tag_active_feed_id = feed_id;
471 _tag_active_cdm = cdm_enabled;
473 _tag_cdm_scroll = document.getElementById("headlinesInnerContainer").scrollTop;
475 displayDlg('editArticleTags', id);
479 function tag_saved_callback() {
480 if (xmlhttp_rpc.readyState == 4) {
482 debug("in tag_saved_callback");
487 if (tagsAreDisplayed()) {
488 _reload_feedlist_after_view = true;
491 if (!_tag_active_cdm) {
492 if (active_post_id == _tag_active_post_id) {
493 debug("reloading current article");
494 view(_tag_active_post_id, _tag_active_feed_id);
497 debug("reloading current feed");
502 exception_error("catchup_callback", e);
507 function editTagsSave() {
509 if (!xmlhttp_ready(xmlhttp_rpc)) {
513 notify("Saving article tags...");
515 var form = document.forms["tag_edit_form"];
517 var query = Form.serialize("tag_edit_form");
519 xmlhttp_rpc.open("GET", "backend.php?op=rpc&subop=setArticleTags&" + query, true);
520 xmlhttp_rpc.onreadystatechange=tag_saved_callback;
521 xmlhttp_rpc.send(null);
525 function editTagsInsert() {
528 var form = document.forms["tag_edit_form"];
530 var found_tags = form.found_tags;
531 var tags_str = form.tags_str;
533 var tag = found_tags[found_tags.selectedIndex].value;
535 if (tags_str.value.length > 0 &&
536 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
538 tags_str.value = tags_str.value + ", ";
541 tags_str.value = tags_str.value + tag + ", ";
543 found_tags.selectedIndex = 0;
546 exception_error(e, "editTagsInsert");
550 function cdmWatchdog() {
554 var ctr = document.getElementById("headlinesInnerContainer");
556 if (!ctr.hasChildNodes()) return;
558 var ids = new Array();
560 var e = ctr.firstChild;
563 if (e.className && e.className == "cdmArticleUnread" && e.id &&
564 e.id.match("RROW-")) {
566 // article fits in viewport OR article is longer than viewport and
567 // its bottom is visible
569 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
570 ctr.scrollTop + ctr.offsetHeight) {
572 // debug(e.id + " is visible " + e.offsetTop + "." +
573 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
574 // (ctr.scrollTop + ctr.offsetHeight));
576 ids.push(e.id.replace("RROW-", ""));
578 } else if (e.offsetHeight > ctr.offsetHeight &&
579 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
580 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
582 ids.push(e.id.replace("RROW-", ""));
591 debug("cdmWatchdog, ids= " + ids.toString());
593 if (ids.length > 0 && xmlhttp_ready(xmlhttp_rpc)) {
595 for (var i = 0; i < ids.length; i++) {
596 var e = document.getElementById("RROW-" + ids[i]);
598 e.className = e.className.replace("Unread", "");
602 var query = "backend.php?op=rpc&subop=catchupSelected&ids=" +
603 param_escape(ids.toString()) + "&cmode=0";
605 xmlhttp_rpc.open("GET", query, true);
606 xmlhttp_rpc.onreadystatechange=all_counters_callback;
607 xmlhttp_rpc.send(null);
611 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
614 exception_error(e, "cdmWatchdog");