1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _tag_active_post_id
= false;
6 var _tag_active_feed_id
= false;
7 var _tag_active_cdm
= false;
9 // FIXME: kludge, to restore scrollTop after tag editor terminates
10 var _tag_cdm_scroll
= false;
12 // FIXME: kludges, needs proper implementation
13 var _reload_feedlist_after_view
= false;
15 var _cdm_wd_timeout
= false;
16 var _cdm_wd_vishist
= new Array();
18 var article_cache
= new Array();
20 function catchup_callback() {
21 if (xmlhttp_rpc
.readyState
== 4) {
23 debug("catchup_callback");
25 all_counters_callback();
26 if (_catchup_callback_func
) {
27 setTimeout(_catchup_callback_func
, 10);
30 exception_error("catchup_callback", e
);
35 function catchup_callback2(transport
, callback
) {
37 debug("catchup_callback2 " + transport
+ ", " + callback
);
39 all_counters_callback2(transport
);
41 setTimeout(callback
, 10);
44 exception_error("catchup_callback2", e
);
48 function headlines_callback() {
49 if (xmlhttp
.readyState
== 4) {
50 debug("headlines_callback");
51 var f
= document
.getElementById("headlines-frame");
53 if (feed_cur_page
== 0) {
54 debug("resetting headlines scrollTop");
59 if (xmlhttp
.responseXML
) {
60 var headlines
= xmlhttp
.responseXML
.getElementsByTagName("headlines")[0];
61 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
62 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
63 var runtime_info
= xmlhttp
.responseXML
.getElementsByTagName("runtime-info");
65 if (feed_cur_page
== 0) {
67 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
69 debug("headlines_callback: returned no data");
70 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
75 debug("adding some more headlines...");
77 var c
= document
.getElementById("headlinesList");
80 c
= document
.getElementById("headlinesInnerContainer");
83 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
85 debug("headlines_callback: returned no data");
86 notify_error("Error while trying to load more headlines");
92 for (var i
= 0; i
< articles
.length
; i
++) {
93 var a_id
= articles
[i
].getAttribute("id");
94 debug("found id: " + a_id
);
95 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
98 debug("no cached articles received");
102 debug("parsing piggybacked counters: " + counters
);
103 parse_counters(counters
, false);
105 debug("counters container not found in reply");
109 debug("parsing runtime info: " + runtime_info
[0]);
110 parse_runtime_info(runtime_info
[0]);
112 debug("counters container not found in reply");
116 debug("headlines_callback: returned no XML object");
117 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
120 if (typeof correctPNG
!= 'undefined') {
124 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
126 if (!document
.getElementById("headlinesList") &&
127 getInitParam("cdm_auto_catchup") == 1) {
128 debug("starting CDM watchdog");
129 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
130 _cdm_wd_vishist
= new Array();
132 debug("not in CDM mode or watchdog disabled");
135 if (_tag_cdm_scroll
) {
137 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
138 _tag_cdm_scroll
= false;
139 debug("resetting headlinesInner scrollTop");
148 function render_article(article
) {
150 var f
= document
.getElementById("content-frame");
155 f
.innerHTML
= article
;
158 exception_error("render_article", e
);
162 function article_callback() {
163 if (xmlhttp
.readyState
== 4) {
164 debug("article_callback");
167 if (xmlhttp
.responseXML
) {
168 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
170 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
172 for (var i
= 0; i
< articles
.length
; i
++) {
173 var a_id
= articles
[i
].getAttribute("id");
175 debug("found id: " + a_id
);
177 if (a_id
== active_post_id
) {
178 debug("active article, rendering...");
179 render_article(articles
[i
].firstChild
.nodeValue
);
182 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
186 debug("article_callback: returned no XML object");
187 var f
= document
.getElementById("content-frame");
188 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
191 exception_error("article_callback", e
);
194 var date
= new Date();
195 last_article_view
= date
.getTime() / 1000;
197 if (typeof correctPNG
!= 'undefined') {
201 if (_reload_feedlist_after_view
) {
202 setTimeout('updateFeedList(false, false)', 50);
203 _reload_feedlist_after_view
= false;
205 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
208 debug("parsing piggybacked counters: " + counters
);
209 parse_counters(counters
, false);
211 debug("counters container not found in reply");
219 function view(id
, feed_id
, skip_history
) {
222 debug("loading article: " + id
+ "/" + feed_id
);
224 active_real_feed_id
= feed_id
;
226 var cached_article
= cache_find(id
);
228 debug("cache check result: " + (cached_article
!= false));
232 //setActiveFeedId(feed_id);
234 var query
= "backend.php?op=view&id=" + param_escape(id
) +
235 "&feed=" + param_escape(feed_id
);
237 var date
= new Date();
239 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
240 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
243 debug("trying alternative reset method for Safari");
244 xmlhttp
= Ajax
.getTransport();
248 if (xmlhttp_ready(xmlhttp
)) {
252 cleanSelected("headlinesList");
254 var crow
= document
.getElementById("RROW-" + active_post_id
);
256 var article_is_unread
= crow
.className
.match("Unread");
257 debug("article is unread: " + article_is_unread
);
259 crow
.className
= crow
.className
.replace("Unread", "");
261 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
264 upd_img_pic
.src
= "images/blank_icon.gif";
267 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
268 markHeadline(active_post_id
);
270 var neighbor_ids
= getRelativePostIds(active_post_id
);
272 /* only request uncached articles */
274 var cids_to_request
= Array();
276 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
277 if (!cache_check(neighbor_ids
[i
])) {
278 cids_to_request
.push(neighbor_ids
[i
]);
282 debug("additional ids: " + cids_to_request
.toString());
284 /* additional info for piggyback counters */
286 if (tagsAreDisplayed()) {
287 query
= query
+ "&omode=lt";
289 query
= query
+ "&omode=flc";
292 var date
= new Date();
293 var timestamp
= Math
.round(date
.getTime() / 1000);
294 query
= query
+ "&ts=" + timestamp
;
296 query
= query
+ "&cids=" + cids_to_request
.toString();
298 if (!cached_article
) {
300 notify_progress("Loading, please wait...");
304 xmlhttp
.open("GET", query
, true);
305 xmlhttp
.onreadystatechange
=article_callback
;
307 } else if (cached_article
&& article_is_unread
) {
309 query
= query
+ "&mode=prefetch";
313 xmlhttp
.open("GET", query
, true);
314 xmlhttp
.onreadystatechange
=article_callback
;
317 render_article(cached_article
);
319 } else if (cached_article
) {
321 query
= query
+ "&mode=prefetch_old";
325 xmlhttp
.open("GET", query
, true);
326 xmlhttp
.onreadystatechange
=article_callback
;
329 render_article(cached_article
);
336 debug("xmlhttp busy (@view)");
341 exception_error("view", e
);
346 return toggleMark(id
);
350 return togglePub(id
);
353 function tMark_afh_off(effect
) {
355 var elem
= effect
.effects
[0].element
;
357 debug("tMark_afh_off : " + elem
.id
);
360 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
361 elem
.alt
= __("Star article");
366 exception_error("tMark_afh_off", e
);
370 function tPub_afh_off(effect
) {
372 var elem
= effect
.effects
[0].element
;
374 debug("tPub_afh_off : " + elem
.id
);
377 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
378 elem
.alt
= __("Publish article");
383 exception_error("tPub_afh_off", e
);
387 function toggleMark(id
, client_only
, no_effects
) {
391 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
393 query
= query
+ "&afid=" + getActiveFeedId();
395 if (tagsAreDisplayed()) {
396 query
= query
+ "&omode=tl";
398 query
= query
+ "&omode=flc";
401 var mark_img
= document
.getElementById("FMPIC-" + id
);
402 var vfeedu
= document
.getElementById("FEEDU--1");
403 var crow
= document
.getElementById("RROW-" + id
);
405 if (mark_img
.src
.match("mark_unset")) {
406 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
407 mark_img
.alt
= __("Unstar article");
408 query
= query
+ "&mark=1";
410 /* if (vfeedu && crow.className.match("Unread")) {
411 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
415 //mark_img.src = "images/mark_unset.png";
416 mark_img
.alt
= __("Please wait...");
417 query
= query
+ "&mark=0";
419 /* if (vfeedu && crow.className.match("Unread")) {
420 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
423 if (document
.getElementById("headlinesList") && !no_effects
) {
424 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
426 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
427 mark_img
.alt
= __("Star article");
431 /* var vfeedctr = document.getElementById("FEEDCTR--1");
432 var vfeedr = document.getElementById("FEEDR--1");
434 if (vfeedu && vfeedctr) {
435 if ((+vfeedu.innerHTML) > 0) {
436 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
437 vfeedr.className = vfeedr.className + "Unread";
438 vfeedctr.className = "odd";
441 vfeedctr.className = "invisible";
442 vfeedr.className = vfeedr.className.replace("Unread", "");
446 debug("toggle starred for aid " + id);
448 //new Ajax.Request(query); */
453 // xmlhttp_rpc.open("GET", query, true);
454 // xmlhttp_rpc.onreadystatechange=all_counters_callback;
455 // xmlhttp_rpc.send(null);
457 new Ajax
.Request(query
, {
458 onComplete: function(transport
) {
459 all_counters_callback2(transport
);
465 exception_error("toggleMark", e
);
469 function togglePub(id
, client_only
, no_effects
) {
473 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
475 query
= query
+ "&afid=" + getActiveFeedId();
477 if (tagsAreDisplayed()) {
478 query
= query
+ "&omode=tl";
480 query
= query
+ "&omode=flc";
483 var mark_img
= document
.getElementById("FPPIC-" + id
);
484 var vfeedu
= document
.getElementById("FEEDU--2");
485 var crow
= document
.getElementById("RROW-" + id
);
487 if (mark_img
.src
.match("pub_unset")) {
488 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
489 mark_img
.alt
= __("Unpublish article");
490 query
= query
+ "&pub=1";
492 /* if (vfeedu && crow.className.match("Unread")) {
493 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
497 //mark_img.src = "images/pub_unset.png";
498 mark_img
.alt
= __("Please wait...");
499 query
= query
+ "&pub=0";
501 /* if (vfeedu && crow.className.match("Unread")) {
502 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
505 if (document
.getElementById("headlinesList") && !no_effects
) {
506 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
508 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
509 mark_img
.alt
= __("Publish article");
513 /* var vfeedctr = document.getElementById("FEEDCTR--2");
514 var vfeedr = document.getElementById("FEEDR--2");
516 if (vfeedu && vfeedctr) {
517 if ((+vfeedu.innerHTML) > 0) {
518 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
519 vfeedr.className = vfeedr.className + "Unread";
520 vfeedctr.className = "odd";
523 vfeedctr.className = "invisible";
524 vfeedr.className = vfeedr.className.replace("Unread", "");
528 debug("toggle published for aid " + id);
530 new Ajax.Request(query); */
533 new Ajax
.Request(query
, {
534 onComplete: function(transport
) {
535 all_counters_callback2(transport
);
541 exception_error("togglePub", e
);
545 function correctHeadlinesOffset(id
) {
549 var hlist
= document
.getElementById("headlinesList");
550 var container
= document
.getElementById("headlinesInnerContainer");
551 var row
= document
.getElementById("RROW-" + id
);
553 var viewport
= container
.offsetHeight
;
555 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
556 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
558 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
559 debug("Vport: " + viewport
);
561 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
562 container
.scrollTop
= row
.offsetTop
;
563 } else if (rel_offset_bottom
> viewport
) {
565 /* doesn't properly work with Opera in some cases because
566 Opera fucks up element scrolling */
568 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
572 exception_error("correctHeadlinesOffset", e
);
577 function moveToPost(mode
) {
579 // check for combined mode
580 if (!document
.getElementById("headlinesList"))
583 var rows
= getVisibleHeadlineIds();
588 if (!document
.getElementById('RROW-' + active_post_id
)) {
589 active_post_id
= false;
592 if (active_post_id
== false) {
593 next_id
= getFirstVisibleHeadlineId();
594 prev_id
= getLastVisibleHeadlineId();
596 for (var i
= 0; i
< rows
.length
; i
++) {
597 if (rows
[i
] == active_post_id
) {
604 if (mode
== "next") {
606 correctHeadlinesOffset(next_id
);
607 view(next_id
, getActiveFeedId());
611 if (mode
== "prev") {
613 correctHeadlinesOffset(prev_id
);
614 view(prev_id
, getActiveFeedId());
619 function toggleUnread(id
, cmode
) {
622 var row
= document
.getElementById("RROW-" + id
);
624 var nc
= row
.className
;
625 nc
= nc
.replace("Unread", "");
626 nc
= nc
.replace("Selected", "");
628 if (row
.className
.match("Unread")) {
631 row
.className
= nc
+ "Unread";
634 if (!cmode
) cmode
= 2;
636 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
637 param_escape(id
) + "&cmode=" + param_escape(cmode
);
639 // notify_progress("Loading, please wait...");
641 new Ajax
.Request(query
, {
642 onComplete: function(transport
) {
643 all_counters_callback2(transport
);
650 exception_error("toggleUnread", e
);
654 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
656 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
664 rows
= cdmGetSelectedArticles();
666 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
669 if (rows
.length
== 0 && !no_error
) {
670 alert(__("No articles are selected."));
674 for (i
= 0; i
< rows
.length
; i
++) {
675 var row
= document
.getElementById("RROW-" + rows
[i
]);
677 var nc
= row
.className
;
678 nc
= nc
.replace("Unread", "");
679 nc
= nc
.replace("Selected", "");
681 if (set_state
== undefined) {
682 if (row
.className
.match("Unread")) {
683 row
.className
= nc
+ "Selected";
685 row
.className
= nc
+ "UnreadSelected";
689 if (set_state
== false) {
690 row
.className
= nc
+ "Selected";
693 if (set_state
== true) {
694 row
.className
= nc
+ "UnreadSelected";
699 if (rows
.length
> 0) {
703 if (set_state
== undefined) {
705 } else if (set_state
== true) {
707 } else if (set_state
== false) {
711 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
712 param_escape(rows
.toString()) + "&cmode=" + cmode
;
714 // _catchup_callback_func = callback_func;
716 debug(callback_func
);
718 notify_progress("Loading, please wait...");
720 /* xmlhttp_rpc.open("GET", query, true);
721 xmlhttp_rpc.onreadystatechange=catchup_callback;
722 xmlhttp_rpc.send(null); */
724 new Ajax
.Request(query
, {
725 onComplete: function(transport
) {
726 catchup_callback2(transport
, callback_func
);
732 exception_error("selectionToggleUnread", e
);
736 function selectionToggleMarked(cdm_mode
) {
742 rows
= cdmGetSelectedArticles();
744 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
747 if (rows
.length
== 0) {
748 alert(__("No articles are selected."));
752 for (i
= 0; i
< rows
.length
; i
++) {
753 toggleMark(rows
[i
], true, true);
756 if (rows
.length
> 0) {
758 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
759 param_escape(rows
.toString()) + "&cmode=2";
761 query
= query
+ "&afid=" + getActiveFeedId();
763 /* if (tagsAreDisplayed()) {
764 query = query + "&omode=tl";
766 query = query + "&omode=flc";
769 query
= query
+ "&omode=lc";
771 new Ajax
.Request(query
, {
772 onComplete: function(transport
) {
773 all_counters_callback2(transport
);
779 exception_error("selectionToggleMarked", e
);
783 function selectionTogglePublished(cdm_mode
) {
789 rows
= cdmGetSelectedArticles();
791 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
794 if (rows
.length
== 0) {
795 alert(__("No articles are selected."));
799 for (i
= 0; i
< rows
.length
; i
++) {
800 togglePub(rows
[i
], true, true);
803 if (rows
.length
> 0) {
805 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
806 param_escape(rows
.toString()) + "&cmode=2";
808 query
= query
+ "&afid=" + getActiveFeedId();
810 /* if (tagsAreDisplayed()) {
811 query = query + "&omode=tl";
813 query = query + "&omode=flc";
816 query
= query
+ "&omode=lc";
818 new Ajax
.Request(query
, {
819 onComplete: function(transport
) {
820 all_counters_callback2(transport
);
826 exception_error("selectionToggleMarked", e
);
830 function cdmGetSelectedArticles() {
831 var sel_articles
= new Array();
832 var container
= document
.getElementById("headlinesInnerContainer");
834 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
835 var child
= container
.childNodes
[i
];
837 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
838 var c_id
= child
.id
.replace("RROW-", "");
839 sel_articles
.push(c_id
);
846 function cdmGetVisibleArticles() {
847 var sel_articles
= new Array();
848 var container
= document
.getElementById("headlinesInnerContainer");
850 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
851 var child
= container
.childNodes
[i
];
853 if (child
.id
.match("RROW-")) {
854 var c_id
= child
.id
.replace("RROW-", "");
855 sel_articles
.push(c_id
);
862 function cdmGetUnreadArticles() {
863 var sel_articles
= new Array();
864 var container
= document
.getElementById("headlinesInnerContainer");
866 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
867 var child
= container
.childNodes
[i
];
869 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
870 var c_id
= child
.id
.replace("RROW-", "");
871 sel_articles
.push(c_id
);
879 // mode = all,none,unread
880 function cdmSelectArticles(mode
) {
881 var container
= document
.getElementById("headlinesInnerContainer");
883 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
884 var child
= container
.childNodes
[i
];
886 if (child
.id
.match("RROW-")) {
887 var aid
= child
.id
.replace("RROW-", "");
889 var cb
= document
.getElementById("RCHK-" + aid
);
892 if (!child
.className
.match("Selected")) {
893 child
.className
= child
.className
+ "Selected";
896 } else if (mode
== "unread") {
897 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
898 child
.className
= child
.className
+ "Selected";
902 child
.className
= child
.className
.replace("Selected", "");
909 function catchupPage() {
911 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
913 var str
= __("Mark all visible articles in %s as read?");
915 str
= str
.replace("%s", fn
);
917 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
921 if (document
.getElementById("headlinesList")) {
922 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
923 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
924 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
926 cdmSelectArticles('all');
927 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
928 cdmSelectArticles('none');
932 function catchupSelection() {
938 if (document
.getElementById("headlinesList")) {
939 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
941 rows
= cdmGetSelectedArticles();
944 if (rows
.length
== 0) {
945 alert(__("No articles are selected."));
950 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
952 var str
= __("Mark all selected articles in %s as read?");
954 str
= str
.replace("%s", fn
);
956 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
960 if (document
.getElementById("headlinesList")) {
961 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
962 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
964 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
965 // cdmSelectArticles('none');
969 exception_error("catchupSelection", e
);
974 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
976 if (!xmlhttp_ready(xmlhttp_rpc
)) {
980 var title
= prompt(__("Please enter label title:"), "");
984 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
985 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
986 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
987 "&title=" + param_escape(title
);
989 debug("LFS: " + query
);
991 xmlhttp_rpc
.open("GET", query
, true);
992 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
993 xmlhttp_rpc
.send(null);
998 function editArticleTags(id
, feed_id
, cdm_enabled
) {
999 _tag_active_post_id
= id
;
1000 _tag_active_feed_id
= feed_id
;
1001 _tag_active_cdm
= cdm_enabled
;
1003 cache_invalidate(id
);
1006 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1008 displayDlg('editArticleTags', id
);
1012 function tag_saved_callback() {
1013 if (xmlhttp_rpc
.readyState
== 4) {
1015 debug("in tag_saved_callback");
1020 if (tagsAreDisplayed()) {
1021 _reload_feedlist_after_view
= true;
1024 if (!_tag_active_cdm
) {
1025 if (active_post_id
== _tag_active_post_id
) {
1026 debug("reloading current article");
1027 view(_tag_active_post_id
, _tag_active_feed_id
);
1030 debug("reloading current feed");
1035 exception_error("catchup_callback", e
);
1040 function editTagsSave() {
1042 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1043 printLockingError();
1046 notify_progress("Saving article tags...");
1048 var form
= document
.forms
["tag_edit_form"];
1050 var query
= Form
.serialize("tag_edit_form");
1052 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1056 xmlhttp_rpc
.open("GET", query
, true);
1057 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1058 xmlhttp_rpc
.send(null);
1062 function editTagsInsert() {
1065 var form
= document
.forms
["tag_edit_form"];
1067 var found_tags
= form
.found_tags
;
1068 var tags_str
= form
.tags_str
;
1070 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1072 if (tags_str
.value
.length
> 0 &&
1073 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1075 tags_str
.value
= tags_str
.value
+ ", ";
1078 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1080 found_tags
.selectedIndex
= 0;
1083 exception_error(e
, "editTagsInsert");
1087 function cdmWatchdog() {
1091 var ctr
= document
.getElementById("headlinesInnerContainer");
1095 var ids
= new Array();
1097 var e
= ctr
.firstChild
;
1100 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1101 e
.id
.match("RROW-")) {
1103 // article fits in viewport OR article is longer than viewport and
1104 // its bottom is visible
1106 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1107 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1109 // debug(e.id + " is visible " + e.offsetTop + "." +
1110 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1111 // (ctr.scrollTop + ctr.offsetHeight));
1113 ids
.push(e
.id
.replace("RROW-", ""));
1115 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1116 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1117 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1119 ids
.push(e
.id
.replace("RROW-", ""));
1123 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1125 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1126 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1128 ids.push(e.id.replace("RROW-", ""));
1137 debug("cdmWatchdog, ids= " + ids
.toString());
1139 if (ids
.length
> 0) {
1141 for (var i
= 0; i
< ids
.length
; i
++) {
1142 var e
= document
.getElementById("RROW-" + ids
[i
]);
1144 e
.className
= e
.className
.replace("Unread", "");
1148 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1149 param_escape(ids
.toString()) + "&cmode=0";
1151 new Ajax
.Request(query
, {
1152 onComplete: function(transport
) {
1153 all_counters_callback2(transport
);
1158 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1161 exception_error(e
, "cdmWatchdog");
1167 function cache_inject(id
, article
) {
1168 if (!cache_check(id
)) {
1169 debug("cache_article: miss: " + id
);
1171 var cache_obj
= new Array();
1173 cache_obj
["id"] = id
;
1174 cache_obj
["data"] = article
;
1176 article_cache
.push(cache_obj
);
1179 debug("cache_article: hit: " + id
);
1183 function cache_find(id
) {
1184 for (var i
= 0; i
< article_cache
.length
; i
++) {
1185 if (article_cache
[i
]["id"] == id
) {
1186 return article_cache
[i
]["data"];
1192 function cache_check(id
) {
1193 for (var i
= 0; i
< article_cache
.length
; i
++) {
1194 if (article_cache
[i
]["id"] == id
) {
1201 function cache_expire() {
1202 while (article_cache
.length
> 20) {
1203 article_cache
.shift();
1207 function cache_invalidate(id
) {
1212 while (i
< article_cache
.length
) {
1213 if (article_cache
[i
]["id"] == id
) {
1214 debug("cache_invalidate: removed id " + id
);
1215 article_cache
.splice(i
, 1);
1220 debug("cache_invalidate: id not found: " + id
);
1223 exception_error("cache_invalidate", e
);
1227 function getActiveArticleId() {
1228 return active_post_id
;
1231 function cdmMouseIn(elem
) {
1233 if (elem
.id
&& elem
.id
.match("RROW-")) {
1234 var id
= elem
.id
.replace("RROW-", "");
1235 active_post_id
= id
;
1238 exception_error("cdmMouseIn", e
);
1243 function cdmMouseOut(elem
) {
1244 active_post_id
= false;
1247 function headlines_scroll_handler() {
1250 var e
= document
.getElementById("headlinesInnerContainer");
1252 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1253 debug("more cowbell!");
1259 exception_error("headlines_scroll_handler", e
);
1263 function catchupRelativeToArticle(below
) {
1267 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1268 printLockingError();
1271 if (!getActiveArticleId()) {
1272 alert(__("No article is selected."));
1278 if (document
.getElementById("headlinesList")) {
1279 visible_ids
= getVisibleHeadlineIds();
1281 visible_ids
= cdmGetVisibleArticles();
1284 var ids_to_mark
= new Array();
1287 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1288 if (visible_ids
[i
] != getActiveArticleId()) {
1289 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1291 if (e
&& e
.className
.match("Unread")) {
1292 ids_to_mark
.push(visible_ids
[i
]);
1299 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1300 if (visible_ids
[i
] != getActiveArticleId()) {
1301 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1303 if (e
&& e
.className
.match("Unread")) {
1304 ids_to_mark
.push(visible_ids
[i
]);
1312 if (ids_to_mark
.length
== 0) {
1313 alert(__("No articles found to mark"));
1315 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1319 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1320 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1321 e
.className
= e
.className
.replace("Unread", "");
1324 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1325 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1327 xmlhttp_rpc
.open("GET", query
, true);
1328 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1329 xmlhttp_rpc
.send(null);
1335 exception_error("catchupRelativeToArticle", e
);