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_callback2(xmlhttp_rpc
);
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_callback2(transport
, active_feed_id
, active_feed_is_cat
, feed_cur_page
) {
49 debug("headlines_callback2");
50 var f
= document
.getElementById("headlines-frame");
52 if (feed_cur_page
== 0) {
53 debug("resetting headlines scrollTop");
58 if (transport
.responseXML
) {
59 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
60 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
61 var articles
= transport
.responseXML
.getElementsByTagName("article");
62 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
64 if (feed_cur_page
== 0) {
66 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
68 debug("headlines_callback: returned no data");
69 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
74 debug("adding some more headlines...");
76 var c
= document
.getElementById("headlinesList");
79 c
= document
.getElementById("headlinesInnerContainer");
82 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
84 debug("headlines_callback: returned no data");
85 notify_error("Error while trying to load more headlines");
91 for (var i
= 0; i
< articles
.length
; i
++) {
92 var a_id
= articles
[i
].getAttribute("id");
93 debug("found id: " + a_id
);
94 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
97 debug("no cached articles received");
101 debug("parsing piggybacked counters: " + counters
);
102 parse_counters(counters
, false);
104 debug("counters container not found in reply");
108 debug("parsing runtime info: " + runtime_info
[0]);
109 parse_runtime_info(runtime_info
[0]);
111 debug("counters container not found in reply");
115 debug("headlines_callback: returned no XML object");
116 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
119 if (typeof correctPNG
!= 'undefined') {
123 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
125 if (!document
.getElementById("headlinesList") &&
126 getInitParam("cdm_auto_catchup") == 1) {
127 debug("starting CDM watchdog");
128 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
129 _cdm_wd_vishist
= new Array();
131 debug("not in CDM mode or watchdog disabled");
134 if (_tag_cdm_scroll
) {
136 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
137 _tag_cdm_scroll
= false;
138 debug("resetting headlinesInner scrollTop");
146 function render_article(article
) {
148 var f
= document
.getElementById("content-frame");
153 f
.innerHTML
= article
;
156 exception_error("render_article", e
);
160 function article_callback() {
161 if (xmlhttp
.readyState
== 4) {
162 debug("article_callback");
165 if (xmlhttp
.responseXML
) {
166 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
168 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
170 for (var i
= 0; i
< articles
.length
; i
++) {
171 var a_id
= articles
[i
].getAttribute("id");
173 debug("found id: " + a_id
);
175 if (a_id
== active_post_id
) {
176 debug("active article, rendering...");
177 render_article(articles
[i
].firstChild
.nodeValue
);
180 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
184 debug("article_callback: returned no XML object");
185 var f
= document
.getElementById("content-frame");
186 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
189 exception_error("article_callback", e
);
192 var date
= new Date();
193 last_article_view
= date
.getTime() / 1000;
195 if (typeof correctPNG
!= 'undefined') {
199 if (_reload_feedlist_after_view
) {
200 setTimeout('updateFeedList(false, false)', 50);
201 _reload_feedlist_after_view
= false;
203 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
206 debug("parsing piggybacked counters: " + counters
);
207 parse_counters(counters
, false);
209 debug("counters container not found in reply");
217 function view(id
, feed_id
, skip_history
) {
220 debug("loading article: " + id
+ "/" + feed_id
);
222 active_real_feed_id
= feed_id
;
224 var cached_article
= cache_find(id
);
226 debug("cache check result: " + (cached_article
!= false));
230 //setActiveFeedId(feed_id);
232 var query
= "backend.php?op=view&id=" + param_escape(id
) +
233 "&feed=" + param_escape(feed_id
);
235 var date
= new Date();
237 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
238 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
241 debug("trying alternative reset method for Safari");
242 xmlhttp
= Ajax
.getTransport();
246 if (xmlhttp_ready(xmlhttp
)) {
250 cleanSelected("headlinesList");
252 var crow
= document
.getElementById("RROW-" + active_post_id
);
254 var article_is_unread
= crow
.className
.match("Unread");
255 debug("article is unread: " + article_is_unread
);
257 crow
.className
= crow
.className
.replace("Unread", "");
259 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
262 upd_img_pic
.src
= "images/blank_icon.gif";
265 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
266 markHeadline(active_post_id
);
268 var neighbor_ids
= getRelativePostIds(active_post_id
);
270 /* only request uncached articles */
272 var cids_to_request
= Array();
274 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
275 if (!cache_check(neighbor_ids
[i
])) {
276 cids_to_request
.push(neighbor_ids
[i
]);
280 debug("additional ids: " + cids_to_request
.toString());
282 /* additional info for piggyback counters */
284 if (tagsAreDisplayed()) {
285 query
= query
+ "&omode=lt";
287 query
= query
+ "&omode=flc";
290 var date
= new Date();
291 var timestamp
= Math
.round(date
.getTime() / 1000);
292 query
= query
+ "&ts=" + timestamp
;
294 query
= query
+ "&cids=" + cids_to_request
.toString();
296 if (!cached_article
) {
298 notify_progress("Loading, please wait...");
302 xmlhttp
.open("GET", query
, true);
303 xmlhttp
.onreadystatechange
=article_callback
;
305 } else if (cached_article
&& article_is_unread
) {
307 query
= query
+ "&mode=prefetch";
311 xmlhttp
.open("GET", query
, true);
312 xmlhttp
.onreadystatechange
=article_callback
;
315 render_article(cached_article
);
317 } else if (cached_article
) {
319 query
= query
+ "&mode=prefetch_old";
323 xmlhttp
.open("GET", query
, true);
324 xmlhttp
.onreadystatechange
=article_callback
;
327 render_article(cached_article
);
334 debug("xmlhttp busy (@view)");
339 exception_error("view", e
);
344 return toggleMark(id
);
348 return togglePub(id
);
351 function tMark_afh_off(effect
) {
353 var elem
= effect
.effects
[0].element
;
355 debug("tMark_afh_off : " + elem
.id
);
358 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
359 elem
.alt
= __("Star article");
364 exception_error("tMark_afh_off", e
);
368 function tPub_afh_off(effect
) {
370 var elem
= effect
.effects
[0].element
;
372 debug("tPub_afh_off : " + elem
.id
);
375 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
376 elem
.alt
= __("Publish article");
381 exception_error("tPub_afh_off", e
);
385 function toggleMark(id
, client_only
, no_effects
) {
389 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
391 query
= query
+ "&afid=" + getActiveFeedId();
393 if (tagsAreDisplayed()) {
394 query
= query
+ "&omode=tl";
396 query
= query
+ "&omode=flc";
399 var mark_img
= document
.getElementById("FMPIC-" + id
);
400 var vfeedu
= document
.getElementById("FEEDU--1");
401 var crow
= document
.getElementById("RROW-" + id
);
403 if (mark_img
.src
.match("mark_unset")) {
404 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
405 mark_img
.alt
= __("Unstar article");
406 query
= query
+ "&mark=1";
408 /* if (vfeedu && crow.className.match("Unread")) {
409 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
413 //mark_img.src = "images/mark_unset.png";
414 mark_img
.alt
= __("Please wait...");
415 query
= query
+ "&mark=0";
417 /* if (vfeedu && crow.className.match("Unread")) {
418 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
421 if (document
.getElementById("headlinesList") && !no_effects
) {
422 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
424 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
425 mark_img
.alt
= __("Star article");
429 /* var vfeedctr = document.getElementById("FEEDCTR--1");
430 var vfeedr = document.getElementById("FEEDR--1");
432 if (vfeedu && vfeedctr) {
433 if ((+vfeedu.innerHTML) > 0) {
434 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
435 vfeedr.className = vfeedr.className + "Unread";
436 vfeedctr.className = "odd";
439 vfeedctr.className = "invisible";
440 vfeedr.className = vfeedr.className.replace("Unread", "");
444 debug("toggle starred for aid " + id);
446 //new Ajax.Request(query); */
451 new Ajax
.Request(query
, {
452 onComplete: function(transport
) {
453 all_counters_callback2(transport
);
459 exception_error("toggleMark", e
);
463 function togglePub(id
, client_only
, no_effects
) {
467 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
469 query
= query
+ "&afid=" + getActiveFeedId();
471 if (tagsAreDisplayed()) {
472 query
= query
+ "&omode=tl";
474 query
= query
+ "&omode=flc";
477 var mark_img
= document
.getElementById("FPPIC-" + id
);
478 var vfeedu
= document
.getElementById("FEEDU--2");
479 var crow
= document
.getElementById("RROW-" + id
);
481 if (mark_img
.src
.match("pub_unset")) {
482 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
483 mark_img
.alt
= __("Unpublish article");
484 query
= query
+ "&pub=1";
486 /* if (vfeedu && crow.className.match("Unread")) {
487 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
491 //mark_img.src = "images/pub_unset.png";
492 mark_img
.alt
= __("Please wait...");
493 query
= query
+ "&pub=0";
495 /* if (vfeedu && crow.className.match("Unread")) {
496 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
499 if (document
.getElementById("headlinesList") && !no_effects
) {
500 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
502 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
503 mark_img
.alt
= __("Publish article");
507 /* var vfeedctr = document.getElementById("FEEDCTR--2");
508 var vfeedr = document.getElementById("FEEDR--2");
510 if (vfeedu && vfeedctr) {
511 if ((+vfeedu.innerHTML) > 0) {
512 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
513 vfeedr.className = vfeedr.className + "Unread";
514 vfeedctr.className = "odd";
517 vfeedctr.className = "invisible";
518 vfeedr.className = vfeedr.className.replace("Unread", "");
522 debug("toggle published for aid " + id);
524 new Ajax.Request(query); */
527 new Ajax
.Request(query
, {
528 onComplete: function(transport
) {
529 all_counters_callback2(transport
);
535 exception_error("togglePub", e
);
539 function correctHeadlinesOffset(id
) {
543 var hlist
= document
.getElementById("headlinesList");
544 var container
= document
.getElementById("headlinesInnerContainer");
545 var row
= document
.getElementById("RROW-" + id
);
547 var viewport
= container
.offsetHeight
;
549 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
550 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
552 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
553 debug("Vport: " + viewport
);
555 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
556 container
.scrollTop
= row
.offsetTop
;
557 } else if (rel_offset_bottom
> viewport
) {
559 /* doesn't properly work with Opera in some cases because
560 Opera fucks up element scrolling */
562 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
566 exception_error("correctHeadlinesOffset", e
);
571 function moveToPost(mode
) {
573 // check for combined mode
574 if (!document
.getElementById("headlinesList"))
577 var rows
= getVisibleHeadlineIds();
582 if (!document
.getElementById('RROW-' + active_post_id
)) {
583 active_post_id
= false;
586 if (active_post_id
== false) {
587 next_id
= getFirstVisibleHeadlineId();
588 prev_id
= getLastVisibleHeadlineId();
590 for (var i
= 0; i
< rows
.length
; i
++) {
591 if (rows
[i
] == active_post_id
) {
598 if (mode
== "next") {
600 correctHeadlinesOffset(next_id
);
601 view(next_id
, getActiveFeedId());
605 if (mode
== "prev") {
607 correctHeadlinesOffset(prev_id
);
608 view(prev_id
, getActiveFeedId());
613 function toggleUnread(id
, cmode
) {
616 var row
= document
.getElementById("RROW-" + id
);
618 var nc
= row
.className
;
619 nc
= nc
.replace("Unread", "");
620 nc
= nc
.replace("Selected", "");
622 if (row
.className
.match("Unread")) {
625 row
.className
= nc
+ "Unread";
628 if (!cmode
) cmode
= 2;
630 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
631 param_escape(id
) + "&cmode=" + param_escape(cmode
);
633 // notify_progress("Loading, please wait...");
635 new Ajax
.Request(query
, {
636 onComplete: function(transport
) {
637 all_counters_callback2(transport
);
644 exception_error("toggleUnread", e
);
648 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
650 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
658 rows
= cdmGetSelectedArticles();
660 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
663 if (rows
.length
== 0 && !no_error
) {
664 alert(__("No articles are selected."));
668 for (i
= 0; i
< rows
.length
; i
++) {
669 var row
= document
.getElementById("RROW-" + rows
[i
]);
671 var nc
= row
.className
;
672 nc
= nc
.replace("Unread", "");
673 nc
= nc
.replace("Selected", "");
675 if (set_state
== undefined) {
676 if (row
.className
.match("Unread")) {
677 row
.className
= nc
+ "Selected";
679 row
.className
= nc
+ "UnreadSelected";
683 if (set_state
== false) {
684 row
.className
= nc
+ "Selected";
687 if (set_state
== true) {
688 row
.className
= nc
+ "UnreadSelected";
693 if (rows
.length
> 0) {
697 if (set_state
== undefined) {
699 } else if (set_state
== true) {
701 } else if (set_state
== false) {
705 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
706 param_escape(rows
.toString()) + "&cmode=" + cmode
;
708 // _catchup_callback_func = callback_func;
710 debug(callback_func
);
712 notify_progress("Loading, please wait...");
714 /* xmlhttp_rpc.open("GET", query, true);
715 xmlhttp_rpc.onreadystatechange=catchup_callback;
716 xmlhttp_rpc.send(null); */
718 new Ajax
.Request(query
, {
719 onComplete: function(transport
) {
720 catchup_callback2(transport
, callback_func
);
726 exception_error("selectionToggleUnread", e
);
730 function selectionToggleMarked(cdm_mode
) {
736 rows
= cdmGetSelectedArticles();
738 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
741 if (rows
.length
== 0) {
742 alert(__("No articles are selected."));
746 for (i
= 0; i
< rows
.length
; i
++) {
747 toggleMark(rows
[i
], true, true);
750 if (rows
.length
> 0) {
752 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
753 param_escape(rows
.toString()) + "&cmode=2";
755 query
= query
+ "&afid=" + getActiveFeedId();
757 /* if (tagsAreDisplayed()) {
758 query = query + "&omode=tl";
760 query = query + "&omode=flc";
763 query
= query
+ "&omode=lc";
765 new Ajax
.Request(query
, {
766 onComplete: function(transport
) {
767 all_counters_callback2(transport
);
773 exception_error("selectionToggleMarked", e
);
777 function selectionTogglePublished(cdm_mode
) {
783 rows
= cdmGetSelectedArticles();
785 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
788 if (rows
.length
== 0) {
789 alert(__("No articles are selected."));
793 for (i
= 0; i
< rows
.length
; i
++) {
794 togglePub(rows
[i
], true, true);
797 if (rows
.length
> 0) {
799 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
800 param_escape(rows
.toString()) + "&cmode=2";
802 query
= query
+ "&afid=" + getActiveFeedId();
804 /* if (tagsAreDisplayed()) {
805 query = query + "&omode=tl";
807 query = query + "&omode=flc";
810 query
= query
+ "&omode=lc";
812 new Ajax
.Request(query
, {
813 onComplete: function(transport
) {
814 all_counters_callback2(transport
);
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 function cdmGetVisibleArticles() {
841 var sel_articles
= new Array();
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 c_id
= child
.id
.replace("RROW-", "");
849 sel_articles
.push(c_id
);
856 function cdmGetUnreadArticles() {
857 var sel_articles
= new Array();
858 var container
= document
.getElementById("headlinesInnerContainer");
860 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
861 var child
= container
.childNodes
[i
];
863 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
864 var c_id
= child
.id
.replace("RROW-", "");
865 sel_articles
.push(c_id
);
873 // mode = all,none,unread
874 function cdmSelectArticles(mode
) {
875 var container
= document
.getElementById("headlinesInnerContainer");
877 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
878 var child
= container
.childNodes
[i
];
880 if (child
.id
.match("RROW-")) {
881 var aid
= child
.id
.replace("RROW-", "");
883 var cb
= document
.getElementById("RCHK-" + aid
);
886 if (!child
.className
.match("Selected")) {
887 child
.className
= child
.className
+ "Selected";
890 } else if (mode
== "unread") {
891 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
892 child
.className
= child
.className
+ "Selected";
896 child
.className
= child
.className
.replace("Selected", "");
903 function catchupPage() {
905 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
907 var str
= __("Mark all visible articles in %s as read?");
909 str
= str
.replace("%s", fn
);
911 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
915 if (document
.getElementById("headlinesList")) {
916 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
917 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
918 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
920 cdmSelectArticles('all');
921 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
922 cdmSelectArticles('none');
926 function catchupSelection() {
932 if (document
.getElementById("headlinesList")) {
933 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
935 rows
= cdmGetSelectedArticles();
938 if (rows
.length
== 0) {
939 alert(__("No articles are selected."));
944 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
946 var str
= __("Mark all selected articles in %s as read?");
948 str
= str
.replace("%s", fn
);
950 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
954 if (document
.getElementById("headlinesList")) {
955 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
956 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
958 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
959 // cdmSelectArticles('none');
963 exception_error("catchupSelection", e
);
968 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
970 if (!xmlhttp_ready(xmlhttp_rpc
)) {
974 var title
= prompt(__("Please enter label title:"), "");
978 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
979 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
980 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
981 "&title=" + param_escape(title
);
983 debug("LFS: " + query
);
985 xmlhttp_rpc
.open("GET", query
, true);
986 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
987 xmlhttp_rpc
.send(null);
992 function editArticleTags(id
, feed_id
, cdm_enabled
) {
993 _tag_active_post_id
= id
;
994 _tag_active_feed_id
= feed_id
;
995 _tag_active_cdm
= cdm_enabled
;
997 cache_invalidate(id
);
1000 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1002 displayDlg('editArticleTags', id
);
1006 function tag_saved_callback() {
1007 if (xmlhttp_rpc
.readyState
== 4) {
1009 debug("in tag_saved_callback");
1014 if (tagsAreDisplayed()) {
1015 _reload_feedlist_after_view
= true;
1018 if (!_tag_active_cdm
) {
1019 if (active_post_id
== _tag_active_post_id
) {
1020 debug("reloading current article");
1021 view(_tag_active_post_id
, _tag_active_feed_id
);
1024 debug("reloading current feed");
1029 exception_error("catchup_callback", e
);
1034 function editTagsSave() {
1036 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1037 printLockingError();
1040 notify_progress("Saving article tags...");
1042 var form
= document
.forms
["tag_edit_form"];
1044 var query
= Form
.serialize("tag_edit_form");
1046 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1050 xmlhttp_rpc
.open("GET", query
, true);
1051 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1052 xmlhttp_rpc
.send(null);
1056 function editTagsInsert() {
1059 var form
= document
.forms
["tag_edit_form"];
1061 var found_tags
= form
.found_tags
;
1062 var tags_str
= form
.tags_str
;
1064 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1066 if (tags_str
.value
.length
> 0 &&
1067 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1069 tags_str
.value
= tags_str
.value
+ ", ";
1072 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1074 found_tags
.selectedIndex
= 0;
1077 exception_error(e
, "editTagsInsert");
1081 function cdmWatchdog() {
1085 var ctr
= document
.getElementById("headlinesInnerContainer");
1089 var ids
= new Array();
1091 var e
= ctr
.firstChild
;
1094 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1095 e
.id
.match("RROW-")) {
1097 // article fits in viewport OR article is longer than viewport and
1098 // its bottom is visible
1100 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1101 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1103 // debug(e.id + " is visible " + e.offsetTop + "." +
1104 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1105 // (ctr.scrollTop + ctr.offsetHeight));
1107 ids
.push(e
.id
.replace("RROW-", ""));
1109 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1110 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1111 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1113 ids
.push(e
.id
.replace("RROW-", ""));
1117 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1119 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1120 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1122 ids.push(e.id.replace("RROW-", ""));
1131 debug("cdmWatchdog, ids= " + ids
.toString());
1133 if (ids
.length
> 0) {
1135 for (var i
= 0; i
< ids
.length
; i
++) {
1136 var e
= document
.getElementById("RROW-" + ids
[i
]);
1138 e
.className
= e
.className
.replace("Unread", "");
1142 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1143 param_escape(ids
.toString()) + "&cmode=0";
1145 new Ajax
.Request(query
, {
1146 onComplete: function(transport
) {
1147 all_counters_callback2(transport
);
1152 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1155 exception_error(e
, "cdmWatchdog");
1161 function cache_inject(id
, article
) {
1162 if (!cache_check(id
)) {
1163 debug("cache_article: miss: " + id
);
1165 var cache_obj
= new Array();
1167 cache_obj
["id"] = id
;
1168 cache_obj
["data"] = article
;
1170 article_cache
.push(cache_obj
);
1173 debug("cache_article: hit: " + id
);
1177 function cache_find(id
) {
1178 for (var i
= 0; i
< article_cache
.length
; i
++) {
1179 if (article_cache
[i
]["id"] == id
) {
1180 return article_cache
[i
]["data"];
1186 function cache_check(id
) {
1187 for (var i
= 0; i
< article_cache
.length
; i
++) {
1188 if (article_cache
[i
]["id"] == id
) {
1195 function cache_expire() {
1196 while (article_cache
.length
> 20) {
1197 article_cache
.shift();
1201 function cache_invalidate(id
) {
1206 while (i
< article_cache
.length
) {
1207 if (article_cache
[i
]["id"] == id
) {
1208 debug("cache_invalidate: removed id " + id
);
1209 article_cache
.splice(i
, 1);
1214 debug("cache_invalidate: id not found: " + id
);
1217 exception_error("cache_invalidate", e
);
1221 function getActiveArticleId() {
1222 return active_post_id
;
1225 function cdmMouseIn(elem
) {
1227 if (elem
.id
&& elem
.id
.match("RROW-")) {
1228 var id
= elem
.id
.replace("RROW-", "");
1229 active_post_id
= id
;
1232 exception_error("cdmMouseIn", e
);
1237 function cdmMouseOut(elem
) {
1238 active_post_id
= false;
1241 function headlines_scroll_handler() {
1244 var e
= document
.getElementById("headlinesInnerContainer");
1246 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1247 debug("more cowbell!");
1253 exception_error("headlines_scroll_handler", e
);
1257 function catchupRelativeToArticle(below
) {
1261 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1262 printLockingError();
1265 if (!getActiveArticleId()) {
1266 alert(__("No article is selected."));
1272 if (document
.getElementById("headlinesList")) {
1273 visible_ids
= getVisibleHeadlineIds();
1275 visible_ids
= cdmGetVisibleArticles();
1278 var ids_to_mark
= new Array();
1281 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1282 if (visible_ids
[i
] != getActiveArticleId()) {
1283 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1285 if (e
&& e
.className
.match("Unread")) {
1286 ids_to_mark
.push(visible_ids
[i
]);
1293 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1294 if (visible_ids
[i
] != getActiveArticleId()) {
1295 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1297 if (e
&& e
.className
.match("Unread")) {
1298 ids_to_mark
.push(visible_ids
[i
]);
1306 if (ids_to_mark
.length
== 0) {
1307 alert(__("No articles found to mark"));
1309 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1313 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1314 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1315 e
.className
= e
.className
.replace("Unread", "");
1318 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1319 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1321 xmlhttp_rpc
.open("GET", query
, true);
1322 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1323 xmlhttp_rpc
.send(null);
1329 exception_error("catchupRelativeToArticle", e
);