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 var article_cache
= new Array();
21 function catchup_callback() {
22 if (xmlhttp_rpc
.readyState
== 4) {
24 debug("catchup_callback");
26 all_counters_callback();
27 if (_catchup_callback_func
) {
28 setTimeout(_catchup_callback_func
, 10);
31 exception_error("catchup_callback", e
);
36 function headlines_callback() {
37 if (xmlhttp
.readyState
== 4) {
38 debug("headlines_callback");
39 var f
= document
.getElementById("headlines-frame");
41 if (feed_cur_page
== 0) {
42 debug("resetting headlines scrollTop");
47 if (xmlhttp
.responseXML
) {
48 var headlines
= xmlhttp
.responseXML
.getElementsByTagName("headlines")[0];
49 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
50 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
51 var runtime_info
= xmlhttp
.responseXML
.getElementsByTagName("runtime-info");
53 if (feed_cur_page
== 0) {
55 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
57 debug("headlines_callback: returned no data");
58 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
63 debug("adding some more headlines...");
65 var c
= document
.getElementById("headlinesList");
68 c
= document
.getElementById("headlinesInnerContainer");
71 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
73 debug("headlines_callback: returned no data");
74 notify_error("Error while trying to load more headlines");
80 for (var i
= 0; i
< articles
.length
; i
++) {
81 var a_id
= articles
[i
].getAttribute("id");
82 debug("found id: " + a_id
);
83 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
86 debug("no cached articles received");
90 debug("parsing piggybacked counters: " + counters
);
91 parse_counters(counters
, false);
93 debug("counters container not found in reply");
97 debug("parsing runtime info: " + runtime_info
[0]);
98 parse_runtime_info(runtime_info
[0]);
100 debug("counters container not found in reply");
104 debug("headlines_callback: returned no XML object");
105 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
108 if (typeof correctPNG
!= 'undefined') {
112 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
114 if (!document
.getElementById("headlinesList") &&
115 getInitParam("cdm_auto_catchup") == 1) {
116 debug("starting CDM watchdog");
117 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
118 _cdm_wd_vishist
= new Array();
120 debug("not in CDM mode or watchdog disabled");
123 if (_tag_cdm_scroll
) {
125 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
126 _tag_cdm_scroll
= false;
127 debug("resetting headlinesInner scrollTop");
136 function render_article(article
) {
138 var f
= document
.getElementById("content-frame");
143 f
.innerHTML
= article
;
146 exception_error("render_article", e
);
150 function article_callback() {
151 if (xmlhttp
.readyState
== 4) {
152 debug("article_callback");
155 if (xmlhttp
.responseXML
) {
156 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
158 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
160 for (var i
= 0; i
< articles
.length
; i
++) {
161 var a_id
= articles
[i
].getAttribute("id");
163 debug("found id: " + a_id
);
165 if (a_id
== active_post_id
) {
166 debug("active article, rendering...");
167 render_article(articles
[i
].firstChild
.nodeValue
);
170 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
174 debug("article_callback: returned no XML object");
175 var f
= document
.getElementById("content-frame");
176 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
179 exception_error("article_callback", e
);
182 var date
= new Date();
183 last_article_view
= date
.getTime() / 1000;
185 if (typeof correctPNG
!= 'undefined') {
189 if (_reload_feedlist_after_view
) {
190 setTimeout('updateFeedList(false, false)', 50);
191 _reload_feedlist_after_view
= false;
193 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
196 debug("parsing piggybacked counters: " + counters
);
197 parse_counters(counters
, false);
199 debug("counters container not found in reply");
207 function view(id
, feed_id
, skip_history
) {
210 debug("loading article: " + id
+ "/" + feed_id
);
212 active_real_feed_id
= feed_id
;
214 var cached_article
= cache_find(id
);
216 debug("cache check result: " + (cached_article
!= false));
220 //setActiveFeedId(feed_id);
222 var query
= "backend.php?op=view&id=" + param_escape(id
) +
223 "&feed=" + param_escape(feed_id
);
225 var date
= new Date();
227 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
228 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
231 debug("trying alternative reset method for Safari");
232 xmlhttp
= Ajax
.getTransport();
236 if (xmlhttp_ready(xmlhttp
)) {
240 cleanSelected("headlinesList");
242 var crow
= document
.getElementById("RROW-" + active_post_id
);
244 var article_is_unread
= crow
.className
.match("Unread");
245 debug("article is unread: " + article_is_unread
);
247 crow
.className
= crow
.className
.replace("Unread", "");
249 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
252 upd_img_pic
.src
= "images/blank_icon.gif";
255 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
256 markHeadline(active_post_id
);
258 var neighbor_ids
= getRelativePostIds(active_post_id
);
260 /* only request uncached articles */
262 var cids_to_request
= Array();
264 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
265 if (!cache_check(neighbor_ids
[i
])) {
266 cids_to_request
.push(neighbor_ids
[i
]);
270 debug("additional ids: " + cids_to_request
.toString());
272 /* additional info for piggyback counters */
274 if (tagsAreDisplayed()) {
275 query
= query
+ "&omode=lt";
277 query
= query
+ "&omode=flc";
280 var date
= new Date();
281 var timestamp
= Math
.round(date
.getTime() / 1000);
282 query
= query
+ "&ts=" + timestamp
;
284 query
= query
+ "&cids=" + cids_to_request
.toString();
286 if (!cached_article
) {
288 notify_progress("Loading, please wait...");
292 xmlhttp
.open("GET", query
, true);
293 xmlhttp
.onreadystatechange
=article_callback
;
295 } else if (cached_article
&& article_is_unread
) {
297 query
= query
+ "&mode=prefetch";
301 xmlhttp
.open("GET", query
, true);
302 xmlhttp
.onreadystatechange
=article_callback
;
305 render_article(cached_article
);
307 } else if (cached_article
) {
309 query
= query
+ "&mode=prefetch_old";
313 xmlhttp
.open("GET", query
, true);
314 xmlhttp
.onreadystatechange
=article_callback
;
317 render_article(cached_article
);
324 debug("xmlhttp busy (@view)");
329 exception_error("view", e
);
334 return toggleMark(id
);
338 return togglePub(id
);
341 function tMark_afh_off(effect
) {
343 var elem
= effect
.effects
[0].element
;
345 debug("tMark_afh_off : " + elem
.id
);
348 elem
.src
= "images/mark_unset.png";
349 elem
.alt
= "Set mark";
354 exception_error("tMark_afh_off", e
);
358 function tPub_afh_off(effect
) {
360 var elem
= effect
.effects
[0].element
;
362 debug("tPub_afh_off : " + elem
.id
);
365 elem
.src
= "images/pub_unset.png";
366 elem
.alt
= "Publish";
371 exception_error("tPub_afh_off", e
);
375 function toggleMark(id
) {
377 if (!xmlhttp_ready(xmlhttp_rpc
)) {
382 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
384 query
= query
+ "&afid=" + getActiveFeedId();
386 if (tagsAreDisplayed()) {
387 query
= query
+ "&omode=tl";
389 query
= query
+ "&omode=flc";
392 var mark_img
= document
.getElementById("FMPIC-" + id
);
393 var vfeedu
= document
.getElementById("FEEDU--1");
394 var crow
= document
.getElementById("RROW-" + id
);
396 if (mark_img
.alt
!= "Reset mark") {
397 mark_img
.src
= "images/mark_set.png";
398 mark_img
.alt
= "Reset mark";
399 query
= query
+ "&mark=1";
401 if (vfeedu
&& crow
.className
.match("Unread")) {
402 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) + 1;
406 //mark_img.src = "images/mark_unset.png";
407 mark_img
.alt
= "Please wait...";
408 query
= query
+ "&mark=0";
410 if (vfeedu
&& crow
.className
.match("Unread")) {
411 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) - 1;
414 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
418 var vfeedctr
= document
.getElementById("FEEDCTR--1");
419 var vfeedr
= document
.getElementById("FEEDR--1");
421 if (vfeedu
&& vfeedctr
) {
422 if ((+vfeedu
.innerHTML
) > 0) {
423 if (crow
.className
.match("Unread") && !vfeedr
.className
.match("Unread")) {
424 vfeedr
.className
= vfeedr
.className
+ "Unread";
425 vfeedctr
.className
= "odd";
428 vfeedctr
.className
= "invisible";
429 vfeedr
.className
= vfeedr
.className
.replace("Unread", "");
433 debug("toggle starred for aid " + id
);
435 new Ajax
.Request(query
);
439 function togglePub(id
) {
443 if (!xmlhttp_ready(xmlhttp_rpc
)) {
448 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
450 query
= query
+ "&afid=" + getActiveFeedId();
452 if (tagsAreDisplayed()) {
453 query
= query
+ "&omode=tl";
455 query
= query
+ "&omode=flc";
458 var mark_img
= document
.getElementById("FPPIC-" + id
);
459 var vfeedu
= document
.getElementById("FEEDU--2");
460 var crow
= document
.getElementById("RROW-" + id
);
462 if (mark_img
.alt
!= "Unpublish") {
463 mark_img
.src
= "images/pub_set.png";
464 mark_img
.alt
= "Unpublish";
465 query
= query
+ "&pub=1";
467 if (vfeedu
&& crow
.className
.match("Unread")) {
468 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) + 1;
472 //mark_img.src = "images/pub_unset.png";
473 mark_img
.alt
= "Please wait...";
474 query
= query
+ "&pub=0";
476 if (vfeedu
&& crow
.className
.match("Unread")) {
477 vfeedu
.innerHTML
= (+vfeedu
.innerHTML
) - 1;
480 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
484 var vfeedctr
= document
.getElementById("FEEDCTR--2");
485 var vfeedr
= document
.getElementById("FEEDR--2");
487 if (vfeedu
&& vfeedctr
) {
488 if ((+vfeedu
.innerHTML
) > 0) {
489 if (crow
.className
.match("Unread") && !vfeedr
.className
.match("Unread")) {
490 vfeedr
.className
= vfeedr
.className
+ "Unread";
491 vfeedctr
.className
= "odd";
494 vfeedctr
.className
= "invisible";
495 vfeedr
.className
= vfeedr
.className
.replace("Unread", "");
499 debug("toggle published for aid " + id
);
501 new Ajax
.Request(query
);
504 exception_error("togglePub", e
);
508 function correctHeadlinesOffset(id
) {
512 var hlist
= document
.getElementById("headlinesList");
513 var container
= document
.getElementById("headlinesInnerContainer");
514 var row
= document
.getElementById("RROW-" + id
);
516 var viewport
= container
.offsetHeight
;
518 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
519 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
521 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
522 debug("Vport: " + viewport
);
524 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
525 container
.scrollTop
= row
.offsetTop
;
526 } else if (rel_offset_bottom
> viewport
) {
528 /* doesn't properly work with Opera in some cases because
529 Opera fucks up element scrolling */
531 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
535 exception_error("correctHeadlinesOffset", e
);
540 function moveToPost(mode
) {
542 // check for combined mode
543 if (!document
.getElementById("headlinesList"))
546 var rows
= getVisibleHeadlineIds();
551 if (!document
.getElementById('RROW-' + active_post_id
)) {
552 active_post_id
= false;
555 if (active_post_id
== false) {
556 next_id
= getFirstVisibleHeadlineId();
557 prev_id
= getLastVisibleHeadlineId();
559 for (var i
= 0; i
< rows
.length
; i
++) {
560 if (rows
[i
] == active_post_id
) {
567 if (mode
== "next") {
569 correctHeadlinesOffset(next_id
);
570 view(next_id
, getActiveFeedId());
574 if (mode
== "prev") {
576 correctHeadlinesOffset(prev_id
);
577 view(prev_id
, getActiveFeedId());
582 function toggleUnread(id
, cmode
) {
584 if (!xmlhttp_ready(xmlhttp_rpc
)) {
589 var row
= document
.getElementById("RROW-" + id
);
591 var nc
= row
.className
;
592 nc
= nc
.replace("Unread", "");
593 nc
= nc
.replace("Selected", "");
595 if (row
.className
.match("Unread")) {
598 row
.className
= nc
+ "Unread";
601 if (!cmode
) cmode
= 2;
603 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
604 param_escape(id
) + "&cmode=" + param_escape(cmode
);
606 notify_progress("Loading, please wait...");
608 xmlhttp_rpc
.open("GET", query
, true);
609 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
610 xmlhttp_rpc
.send(null);
616 exception_error("toggleUnread", e
);
620 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
622 if (!xmlhttp_ready(xmlhttp_rpc
)) {
630 rows
= cdmGetSelectedArticles();
632 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
635 if (rows
.length
== 0 && !no_error
) {
636 alert(__("No articles are selected."));
640 for (i
= 0; i
< rows
.length
; i
++) {
641 var row
= document
.getElementById("RROW-" + rows
[i
]);
643 var nc
= row
.className
;
644 nc
= nc
.replace("Unread", "");
645 nc
= nc
.replace("Selected", "");
647 if (row
.className
.match("Unread")) {
648 row
.className
= nc
+ "Selected";
650 row
.className
= nc
+ "UnreadSelected";
655 if (rows
.length
> 0) {
659 if (set_state
== undefined) {
661 } else if (set_state
== true) {
663 } else if (set_state
== false) {
667 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
668 param_escape(rows
.toString()) + "&cmode=" + cmode
;
670 _catchup_callback_func
= callback_func
;
672 notify_progress("Loading, please wait...");
674 xmlhttp_rpc
.open("GET", query
, true);
675 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
676 xmlhttp_rpc
.send(null);
681 exception_error("selectionToggleUnread", e
);
685 function selectionToggleMarked(cdm_mode
) {
687 if (!xmlhttp_ready(xmlhttp_rpc
)) {
695 rows
= cdmGetSelectedArticles();
697 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
700 if (rows
.length
== 0) {
701 alert(__("No articles are selected."));
705 for (i
= 0; i
< rows
.length
; i
++) {
706 var row
= document
.getElementById("RROW-" + rows
[i
]);
707 var mark_img
= document
.getElementById("FMPIC-" + rows
[i
]);
709 if (row
&& mark_img
) {
711 if (mark_img
.alt
== "Set mark") {
712 mark_img
.src
= "images/mark_set.png";
713 mark_img
.alt
= "Reset mark";
714 //mark_img.setAttribute('onclick',
715 // 'javascript:toggleMark('+rows[i]+', false)');
718 mark_img
.src
= "images/mark_unset.png";
719 mark_img
.alt
= "Set mark";
721 //mark_img.alt = "Please wait...";
723 //mark_img.setAttribute('onclick',
724 // 'javascript:toggleMark('+rows[i]+', true)');
726 //Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
732 if (rows
.length
> 0) {
734 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
735 param_escape(rows
.toString()) + "&cmode=2";
737 query
= query
+ "&afid=" + getActiveFeedId();
739 if (tagsAreDisplayed()) {
740 query
= query
+ "&omode=tl";
742 query
= query
+ "&omode=flc";
745 xmlhttp_rpc
.open("GET", query
, true);
746 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
747 xmlhttp_rpc
.send(null);
752 exception_error("selectionToggleMarked", e
);
756 function selectionTogglePublished(cdm_mode
) {
758 if (!xmlhttp_ready(xmlhttp_rpc
)) {
766 rows
= cdmGetSelectedArticles();
768 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
771 if (rows
.length
== 0) {
772 alert(__("No articles are selected."));
776 for (i
= 0; i
< rows
.length
; i
++) {
777 var row
= document
.getElementById("RROW-" + rows
[i
]);
778 var mark_img
= document
.getElementById("FPPIC-" + rows
[i
]);
780 if (row
&& mark_img
) {
782 if (mark_img
.alt
== "Publish") {
783 mark_img
.src
= "images/pub_set.png";
784 mark_img
.alt
= "Unpublish";
785 // mark_img.setAttribute('onclick',
786 // 'javascript:togglePub('+rows[i]+', false)');
789 mark_img
.src
= "images/pub_unset.png";
790 mark_img
.alt
= "Publish";
791 // mark_img.setAttribute('onclick',
792 // 'javascript:togglePub('+rows[i]+', true)');
794 // Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
800 if (rows
.length
> 0) {
802 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
803 param_escape(rows
.toString()) + "&cmode=2";
805 query
= query
+ "&afid=" + getActiveFeedId();
807 if (tagsAreDisplayed()) {
808 query
= query
+ "&omode=tl";
810 query
= query
+ "&omode=flc";
813 xmlhttp_rpc
.open("GET", query
, true);
814 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
815 xmlhttp_rpc
.send(null);
820 exception_error("selectionToggleMarked", e
);
824 function cdmGetSelectedArticles() {
825 var sel_articles
= new Array();
826 var container
= document
.getElementById("headlinesInnerContainer");
828 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
829 var child
= container
.childNodes
[i
];
831 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
832 var c_id
= child
.id
.replace("RROW-", "");
833 sel_articles
.push(c_id
);
840 // mode = all,none,unread
841 function cdmSelectArticles(mode
) {
842 var container
= document
.getElementById("headlinesInnerContainer");
844 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
845 var child
= container
.childNodes
[i
];
847 if (child
.id
.match("RROW-")) {
848 var aid
= child
.id
.replace("RROW-", "");
850 var cb
= document
.getElementById("RCHK-" + aid
);
853 if (!child
.className
.match("Selected")) {
854 child
.className
= child
.className
+ "Selected";
857 } else if (mode
== "unread") {
858 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
859 child
.className
= child
.className
+ "Selected";
863 child
.className
= child
.className
.replace("Selected", "");
870 function catchupPage() {
872 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
874 var str
= "Mark all visible articles in " + fn
+ " as read?";
876 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
880 if (document
.getElementById("headlinesList")) {
881 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
882 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
883 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
885 cdmSelectArticles('all');
886 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
887 cdmSelectArticles('none');
891 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
893 if (!xmlhttp_ready(xmlhttp_rpc
)) {
897 var title
= prompt("Please enter label title:", "");
901 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
902 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
903 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
904 "&title=" + param_escape(title
);
906 debug("LFS: " + query
);
908 xmlhttp_rpc
.open("GET", query
, true);
909 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
910 xmlhttp_rpc
.send(null);
915 function editArticleTags(id
, feed_id
, cdm_enabled
) {
916 _tag_active_post_id
= id
;
917 _tag_active_feed_id
= feed_id
;
918 _tag_active_cdm
= cdm_enabled
;
920 cache_invalidate(id
);
923 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
925 displayDlg('editArticleTags', id
);
929 function tag_saved_callback() {
930 if (xmlhttp_rpc
.readyState
== 4) {
932 debug("in tag_saved_callback");
937 if (tagsAreDisplayed()) {
938 _reload_feedlist_after_view
= true;
941 if (!_tag_active_cdm
) {
942 if (active_post_id
== _tag_active_post_id
) {
943 debug("reloading current article");
944 view(_tag_active_post_id
, _tag_active_feed_id
);
947 debug("reloading current feed");
952 exception_error("catchup_callback", e
);
957 function editTagsSave() {
959 if (!xmlhttp_ready(xmlhttp_rpc
)) {
963 notify_progress("Saving article tags...");
965 var form
= document
.forms
["tag_edit_form"];
967 var query
= Form
.serialize("tag_edit_form");
969 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
973 xmlhttp_rpc
.open("GET", query
, true);
974 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
975 xmlhttp_rpc
.send(null);
979 function editTagsInsert() {
982 var form
= document
.forms
["tag_edit_form"];
984 var found_tags
= form
.found_tags
;
985 var tags_str
= form
.tags_str
;
987 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
989 if (tags_str
.value
.length
> 0 &&
990 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
992 tags_str
.value
= tags_str
.value
+ ", ";
995 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
997 found_tags
.selectedIndex
= 0;
1000 exception_error(e
, "editTagsInsert");
1004 function cdmWatchdog() {
1008 var ctr
= document
.getElementById("headlinesInnerContainer");
1012 var ids
= new Array();
1014 var e
= ctr
.firstChild
;
1017 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1018 e
.id
.match("RROW-")) {
1020 // article fits in viewport OR article is longer than viewport and
1021 // its bottom is visible
1023 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1024 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1026 // debug(e.id + " is visible " + e.offsetTop + "." +
1027 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1028 // (ctr.scrollTop + ctr.offsetHeight));
1030 ids
.push(e
.id
.replace("RROW-", ""));
1032 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1033 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1034 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1036 ids
.push(e
.id
.replace("RROW-", ""));
1040 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1042 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1043 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1045 ids.push(e.id.replace("RROW-", ""));
1054 debug("cdmWatchdog, ids= " + ids
.toString());
1056 if (ids
.length
> 0 && xmlhttp_ready(xmlhttp_rpc
)) {
1058 for (var i
= 0; i
< ids
.length
; i
++) {
1059 var e
= document
.getElementById("RROW-" + ids
[i
]);
1061 e
.className
= e
.className
.replace("Unread", "");
1065 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1066 param_escape(ids
.toString()) + "&cmode=0";
1068 xmlhttp_rpc
.open("GET", query
, true);
1069 xmlhttp_rpc
.onreadystatechange
=all_counters_callback
;
1070 xmlhttp_rpc
.send(null);
1074 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1077 exception_error(e
, "cdmWatchdog");
1083 function cache_inject(id
, article
) {
1084 if (!cache_check(id
)) {
1085 debug("cache_article: miss: " + id
);
1087 var cache_obj
= new Array();
1089 cache_obj
["id"] = id
;
1090 cache_obj
["data"] = article
;
1092 article_cache
.push(cache_obj
);
1095 debug("cache_article: hit: " + id
);
1099 function cache_find(id
) {
1100 for (var i
= 0; i
< article_cache
.length
; i
++) {
1101 if (article_cache
[i
]["id"] == id
) {
1102 return article_cache
[i
]["data"];
1108 function cache_check(id
) {
1109 for (var i
= 0; i
< article_cache
.length
; i
++) {
1110 if (article_cache
[i
]["id"] == id
) {
1117 function cache_expire() {
1118 while (article_cache
.length
> 20) {
1119 article_cache
.shift();
1123 function cache_invalidate(id
) {
1128 while (i
< article_cache
.length
) {
1129 if (article_cache
[i
]["id"] == id
) {
1130 debug("cache_invalidate: removed id " + id
);
1131 article_cache
.splice(i
, 1);
1136 debug("cache_invalidate: id not found: " + id
);
1139 exception_error("cache_invalidate", e
);
1143 function getActiveArticleId() {
1144 return active_post_id
;
1147 function cdmMouseIn(elem
) {
1149 if (elem
.id
&& elem
.id
.match("RROW-")) {
1150 var id
= elem
.id
.replace("RROW-", "");
1151 active_post_id
= id
;
1154 exception_error("cdmMouseIn", e
);
1159 function cdmMouseOut(elem
) {
1160 active_post_id
= false;
1163 function headlines_scroll_handler() {
1166 var e
= document
.getElementById("headlinesInnerContainer");
1168 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1169 debug("more cowbell!");
1175 exception_error("headlines_scroll_handler", e
);