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 [page=" + feed_cur_page
+ "]");
51 var f
= document
.getElementById("headlines-frame");
53 if (feed_cur_page
== 0) {
54 debug("resetting headlines scrollTop");
59 if (transport
.responseXML
) {
60 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
61 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
63 var headlines_count
= headlines_count_obj
.getAttribute("value");
65 if (headlines_count
== 0) _infscroll_disable
= 1;
67 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
68 var articles
= transport
.responseXML
.getElementsByTagName("article");
69 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
71 if (feed_cur_page
== 0) {
73 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
75 debug("headlines_callback: returned no data");
76 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
81 if (headlines_count
> 0) {
82 debug("adding some more headlines...");
84 var c
= document
.getElementById("headlinesList");
87 c
= document
.getElementById("headlinesInnerContainer");
90 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
92 debug("no new headlines received");
95 debug("headlines_callback: returned no data");
96 notify_error("Error while trying to load more headlines");
102 for (var i
= 0; i
< articles
.length
; i
++) {
103 var a_id
= articles
[i
].getAttribute("id");
104 debug("found id: " + a_id
);
105 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
108 debug("no cached articles received");
112 debug("parsing piggybacked counters: " + counters
);
113 parse_counters(counters
, false);
115 debug("counters container not found in reply");
119 debug("parsing runtime info: " + runtime_info
[0]);
120 parse_runtime_info(runtime_info
[0]);
122 debug("counters container not found in reply");
126 debug("headlines_callback: returned no XML object");
127 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
130 if (typeof correctPNG
!= 'undefined') {
134 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
136 if (!document
.getElementById("headlinesList") &&
137 getInitParam("cdm_auto_catchup") == 1) {
138 debug("starting CDM watchdog");
139 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
140 _cdm_wd_vishist
= new Array();
142 debug("not in CDM mode or watchdog disabled");
145 if (_tag_cdm_scroll
) {
147 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
148 _tag_cdm_scroll
= false;
149 debug("resetting headlinesInner scrollTop");
154 _feed_cur_page
= feed_cur_page
;
159 function render_article(article
) {
161 var f
= document
.getElementById("content-frame");
166 f
.innerHTML
= article
;
169 exception_error("render_article", e
);
173 function article_callback() {
174 if (xmlhttp
.readyState
== 4) {
175 debug("article_callback");
178 if (xmlhttp
.responseXML
) {
179 var reply
= xmlhttp
.responseXML
.firstChild
.firstChild
;
181 var articles
= xmlhttp
.responseXML
.getElementsByTagName("article");
183 for (var i
= 0; i
< articles
.length
; i
++) {
184 var a_id
= articles
[i
].getAttribute("id");
186 debug("found id: " + a_id
);
188 if (a_id
== active_post_id
) {
189 debug("active article, rendering...");
190 render_article(articles
[i
].firstChild
.nodeValue
);
193 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
197 debug("article_callback: returned no XML object");
198 var f
= document
.getElementById("content-frame");
199 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
202 exception_error("article_callback", e
);
205 var date
= new Date();
206 last_article_view
= date
.getTime() / 1000;
208 if (typeof correctPNG
!= 'undefined') {
212 if (_reload_feedlist_after_view
) {
213 setTimeout('updateFeedList(false, false)', 50);
214 _reload_feedlist_after_view
= false;
216 var counters
= xmlhttp
.responseXML
.getElementsByTagName("counters")[0];
219 debug("parsing piggybacked counters: " + counters
);
220 parse_counters(counters
, false);
222 debug("counters container not found in reply");
230 function view(id
, feed_id
, skip_history
) {
233 debug("loading article: " + id
+ "/" + feed_id
);
235 active_real_feed_id
= feed_id
;
237 var cached_article
= cache_find(id
);
239 debug("cache check result: " + (cached_article
!= false));
243 //setActiveFeedId(feed_id);
245 var query
= "backend.php?op=view&id=" + param_escape(id
) +
246 "&feed=" + param_escape(feed_id
);
248 var date
= new Date();
250 if (!xmlhttp_ready(xmlhttp
) && last_article_view
< date
.getTime() / 1000 - 15) {
251 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
254 debug("trying alternative reset method for Safari");
255 xmlhttp
= Ajax
.getTransport();
259 if (xmlhttp_ready(xmlhttp
)) {
263 cleanSelected("headlinesList");
265 var crow
= document
.getElementById("RROW-" + active_post_id
);
267 var article_is_unread
= crow
.className
.match("Unread");
268 debug("article is unread: " + article_is_unread
);
270 crow
.className
= crow
.className
.replace("Unread", "");
272 var upd_img_pic
= document
.getElementById("FUPDPIC-" + active_post_id
);
275 upd_img_pic
.src
= "images/blank_icon.gif";
278 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
279 markHeadline(active_post_id
);
281 var neighbor_ids
= getRelativePostIds(active_post_id
);
283 /* only request uncached articles */
285 var cids_to_request
= Array();
287 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
288 if (!cache_check(neighbor_ids
[i
])) {
289 cids_to_request
.push(neighbor_ids
[i
]);
293 debug("additional ids: " + cids_to_request
.toString());
295 /* additional info for piggyback counters */
297 if (tagsAreDisplayed()) {
298 query
= query
+ "&omode=lt";
300 query
= query
+ "&omode=flc";
303 var date
= new Date();
304 var timestamp
= Math
.round(date
.getTime() / 1000);
305 query
= query
+ "&ts=" + timestamp
;
307 query
= query
+ "&cids=" + cids_to_request
.toString();
309 if (!cached_article
) {
311 notify_progress("Loading, please wait...");
315 xmlhttp
.open("GET", query
, true);
316 xmlhttp
.onreadystatechange
=article_callback
;
318 } else if (cached_article
&& article_is_unread
) {
320 query
= query
+ "&mode=prefetch";
324 xmlhttp
.open("GET", query
, true);
325 xmlhttp
.onreadystatechange
=article_callback
;
328 render_article(cached_article
);
330 } else if (cached_article
) {
332 query
= query
+ "&mode=prefetch_old";
336 xmlhttp
.open("GET", query
, true);
337 xmlhttp
.onreadystatechange
=article_callback
;
340 render_article(cached_article
);
347 debug("xmlhttp busy (@view)");
352 exception_error("view", e
);
357 return toggleMark(id
);
361 return togglePub(id
);
364 function tMark_afh_off(effect
) {
366 var elem
= effect
.effects
[0].element
;
368 debug("tMark_afh_off : " + elem
.id
);
371 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
372 elem
.alt
= __("Star article");
377 exception_error("tMark_afh_off", e
);
381 function tPub_afh_off(effect
) {
383 var elem
= effect
.effects
[0].element
;
385 debug("tPub_afh_off : " + elem
.id
);
388 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
389 elem
.alt
= __("Publish article");
394 exception_error("tPub_afh_off", e
);
398 function toggleMark(id
, client_only
, no_effects
) {
402 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
404 query
= query
+ "&afid=" + getActiveFeedId();
406 if (tagsAreDisplayed()) {
407 query
= query
+ "&omode=tl";
409 query
= query
+ "&omode=flc";
412 var mark_img
= document
.getElementById("FMPIC-" + id
);
413 var vfeedu
= document
.getElementById("FEEDU--1");
414 var crow
= document
.getElementById("RROW-" + id
);
416 if (mark_img
.src
.match("mark_unset")) {
417 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
418 mark_img
.alt
= __("Unstar article");
419 query
= query
+ "&mark=1";
421 /* if (vfeedu && crow.className.match("Unread")) {
422 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
426 //mark_img.src = "images/mark_unset.png";
427 mark_img
.alt
= __("Please wait...");
428 query
= query
+ "&mark=0";
430 /* if (vfeedu && crow.className.match("Unread")) {
431 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
434 if (document
.getElementById("headlinesList") && !no_effects
) {
435 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
437 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
438 mark_img
.alt
= __("Star article");
442 /* var vfeedctr = document.getElementById("FEEDCTR--1");
443 var vfeedr = document.getElementById("FEEDR--1");
445 if (vfeedu && vfeedctr) {
446 if ((+vfeedu.innerHTML) > 0) {
447 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
448 vfeedr.className = vfeedr.className + "Unread";
449 vfeedctr.className = "odd";
452 vfeedctr.className = "invisible";
453 vfeedr.className = vfeedr.className.replace("Unread", "");
457 debug("toggle starred for aid " + id);
459 //new Ajax.Request(query); */
464 new Ajax
.Request(query
, {
465 onComplete: function(transport
) {
466 all_counters_callback2(transport
);
472 exception_error("toggleMark", e
);
476 function togglePub(id
, client_only
, no_effects
) {
480 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
482 query
= query
+ "&afid=" + getActiveFeedId();
484 if (tagsAreDisplayed()) {
485 query
= query
+ "&omode=tl";
487 query
= query
+ "&omode=flc";
490 var mark_img
= document
.getElementById("FPPIC-" + id
);
491 var vfeedu
= document
.getElementById("FEEDU--2");
492 var crow
= document
.getElementById("RROW-" + id
);
494 if (mark_img
.src
.match("pub_unset")) {
495 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
496 mark_img
.alt
= __("Unpublish article");
497 query
= query
+ "&pub=1";
499 /* if (vfeedu && crow.className.match("Unread")) {
500 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
504 //mark_img.src = "images/pub_unset.png";
505 mark_img
.alt
= __("Please wait...");
506 query
= query
+ "&pub=0";
508 /* if (vfeedu && crow.className.match("Unread")) {
509 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
512 if (document
.getElementById("headlinesList") && !no_effects
) {
513 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
515 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
516 mark_img
.alt
= __("Publish article");
520 /* var vfeedctr = document.getElementById("FEEDCTR--2");
521 var vfeedr = document.getElementById("FEEDR--2");
523 if (vfeedu && vfeedctr) {
524 if ((+vfeedu.innerHTML) > 0) {
525 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
526 vfeedr.className = vfeedr.className + "Unread";
527 vfeedctr.className = "odd";
530 vfeedctr.className = "invisible";
531 vfeedr.className = vfeedr.className.replace("Unread", "");
535 debug("toggle published for aid " + id);
537 new Ajax.Request(query); */
540 new Ajax
.Request(query
, {
541 onComplete: function(transport
) {
542 all_counters_callback2(transport
);
548 exception_error("togglePub", e
);
552 function correctHeadlinesOffset(id
) {
556 var hlist
= document
.getElementById("headlinesList");
557 var container
= document
.getElementById("headlinesInnerContainer");
558 var row
= document
.getElementById("RROW-" + id
);
560 var viewport
= container
.offsetHeight
;
562 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
563 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
565 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
566 debug("Vport: " + viewport
);
568 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
569 container
.scrollTop
= row
.offsetTop
;
570 } else if (rel_offset_bottom
> viewport
) {
572 /* doesn't properly work with Opera in some cases because
573 Opera fucks up element scrolling */
575 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
579 exception_error("correctHeadlinesOffset", e
);
584 function moveToPost(mode
) {
586 // check for combined mode
587 if (!document
.getElementById("headlinesList"))
590 var rows
= getVisibleHeadlineIds();
595 if (!document
.getElementById('RROW-' + active_post_id
)) {
596 active_post_id
= false;
599 if (active_post_id
== false) {
600 next_id
= getFirstVisibleHeadlineId();
601 prev_id
= getLastVisibleHeadlineId();
603 for (var i
= 0; i
< rows
.length
; i
++) {
604 if (rows
[i
] == active_post_id
) {
611 if (mode
== "next") {
613 correctHeadlinesOffset(next_id
);
614 view(next_id
, getActiveFeedId());
618 if (mode
== "prev") {
620 correctHeadlinesOffset(prev_id
);
621 view(prev_id
, getActiveFeedId());
626 function toggleUnread(id
, cmode
) {
629 var row
= document
.getElementById("RROW-" + id
);
631 var nc
= row
.className
;
632 nc
= nc
.replace("Unread", "");
633 nc
= nc
.replace("Selected", "");
635 if (row
.className
.match("Unread")) {
638 row
.className
= nc
+ "Unread";
641 if (!cmode
) cmode
= 2;
643 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
644 param_escape(id
) + "&cmode=" + param_escape(cmode
);
646 // notify_progress("Loading, please wait...");
648 new Ajax
.Request(query
, {
649 onComplete: function(transport
) {
650 all_counters_callback2(transport
);
657 exception_error("toggleUnread", e
);
661 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
663 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
671 rows
= cdmGetSelectedArticles();
673 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
676 if (rows
.length
== 0 && !no_error
) {
677 alert(__("No articles are selected."));
681 for (i
= 0; i
< rows
.length
; i
++) {
682 var row
= document
.getElementById("RROW-" + rows
[i
]);
684 var nc
= row
.className
;
685 nc
= nc
.replace("Unread", "");
686 nc
= nc
.replace("Selected", "");
688 if (set_state
== undefined) {
689 if (row
.className
.match("Unread")) {
690 row
.className
= nc
+ "Selected";
692 row
.className
= nc
+ "UnreadSelected";
696 if (set_state
== false) {
697 row
.className
= nc
+ "Selected";
700 if (set_state
== true) {
701 row
.className
= nc
+ "UnreadSelected";
706 if (rows
.length
> 0) {
710 if (set_state
== undefined) {
712 } else if (set_state
== true) {
714 } else if (set_state
== false) {
718 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
719 param_escape(rows
.toString()) + "&cmode=" + cmode
;
721 // _catchup_callback_func = callback_func;
723 debug(callback_func
);
725 notify_progress("Loading, please wait...");
727 /* xmlhttp_rpc.open("GET", query, true);
728 xmlhttp_rpc.onreadystatechange=catchup_callback;
729 xmlhttp_rpc.send(null); */
731 new Ajax
.Request(query
, {
732 onComplete: function(transport
) {
733 catchup_callback2(transport
, callback_func
);
739 exception_error("selectionToggleUnread", e
);
743 function selectionToggleMarked(cdm_mode
) {
749 rows
= cdmGetSelectedArticles();
751 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
754 if (rows
.length
== 0) {
755 alert(__("No articles are selected."));
759 for (i
= 0; i
< rows
.length
; i
++) {
760 toggleMark(rows
[i
], true, true);
763 if (rows
.length
> 0) {
765 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
766 param_escape(rows
.toString()) + "&cmode=2";
768 query
= query
+ "&afid=" + getActiveFeedId();
770 /* if (tagsAreDisplayed()) {
771 query = query + "&omode=tl";
773 query = query + "&omode=flc";
776 query
= query
+ "&omode=lc";
778 new Ajax
.Request(query
, {
779 onComplete: function(transport
) {
780 all_counters_callback2(transport
);
786 exception_error("selectionToggleMarked", e
);
790 function selectionTogglePublished(cdm_mode
) {
796 rows
= cdmGetSelectedArticles();
798 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
801 if (rows
.length
== 0) {
802 alert(__("No articles are selected."));
806 for (i
= 0; i
< rows
.length
; i
++) {
807 togglePub(rows
[i
], true, true);
810 if (rows
.length
> 0) {
812 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
813 param_escape(rows
.toString()) + "&cmode=2";
815 query
= query
+ "&afid=" + getActiveFeedId();
817 /* if (tagsAreDisplayed()) {
818 query = query + "&omode=tl";
820 query = query + "&omode=flc";
823 query
= query
+ "&omode=lc";
825 new Ajax
.Request(query
, {
826 onComplete: function(transport
) {
827 all_counters_callback2(transport
);
833 exception_error("selectionToggleMarked", e
);
837 function cdmGetSelectedArticles() {
838 var sel_articles
= new Array();
839 var container
= document
.getElementById("headlinesInnerContainer");
841 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
842 var child
= container
.childNodes
[i
];
844 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
845 var c_id
= child
.id
.replace("RROW-", "");
846 sel_articles
.push(c_id
);
853 function cdmGetVisibleArticles() {
854 var sel_articles
= new Array();
855 var container
= document
.getElementById("headlinesInnerContainer");
857 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
858 var child
= container
.childNodes
[i
];
860 if (child
.id
.match("RROW-")) {
861 var c_id
= child
.id
.replace("RROW-", "");
862 sel_articles
.push(c_id
);
869 function cdmGetUnreadArticles() {
870 var sel_articles
= new Array();
871 var container
= document
.getElementById("headlinesInnerContainer");
873 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
874 var child
= container
.childNodes
[i
];
876 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
877 var c_id
= child
.id
.replace("RROW-", "");
878 sel_articles
.push(c_id
);
886 // mode = all,none,unread
887 function cdmSelectArticles(mode
) {
888 var container
= document
.getElementById("headlinesInnerContainer");
890 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
891 var child
= container
.childNodes
[i
];
893 if (child
.id
.match("RROW-")) {
894 var aid
= child
.id
.replace("RROW-", "");
896 var cb
= document
.getElementById("RCHK-" + aid
);
899 if (!child
.className
.match("Selected")) {
900 child
.className
= child
.className
+ "Selected";
903 } else if (mode
== "unread") {
904 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
905 child
.className
= child
.className
+ "Selected";
909 child
.className
= child
.className
.replace("Selected", "");
916 function catchupPage() {
918 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
920 var str
= __("Mark all visible articles in %s as read?");
922 str
= str
.replace("%s", fn
);
924 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
928 if (document
.getElementById("headlinesList")) {
929 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
930 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
931 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
933 cdmSelectArticles('all');
934 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
935 cdmSelectArticles('none');
939 function catchupSelection() {
945 if (document
.getElementById("headlinesList")) {
946 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
948 rows
= cdmGetSelectedArticles();
951 if (rows
.length
== 0) {
952 alert(__("No articles are selected."));
957 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
959 var str
= __("Mark all selected articles in %s as read?");
961 str
= str
.replace("%s", fn
);
963 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
967 if (document
.getElementById("headlinesList")) {
968 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
969 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
971 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
972 // cdmSelectArticles('none');
976 exception_error("catchupSelection", e
);
981 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
983 if (!xmlhttp_ready(xmlhttp_rpc
)) {
987 var title
= prompt(__("Please enter label title:"), "");
991 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
992 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
993 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
994 "&title=" + param_escape(title
);
996 debug("LFS: " + query
);
998 xmlhttp_rpc
.open("GET", query
, true);
999 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
1000 xmlhttp_rpc
.send(null);
1005 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1006 _tag_active_post_id
= id
;
1007 _tag_active_feed_id
= feed_id
;
1008 _tag_active_cdm
= cdm_enabled
;
1010 cache_invalidate(id
);
1013 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1015 displayDlg('editArticleTags', id
);
1019 function tag_saved_callback() {
1020 if (xmlhttp_rpc
.readyState
== 4) {
1022 debug("in tag_saved_callback");
1027 if (tagsAreDisplayed()) {
1028 _reload_feedlist_after_view
= true;
1031 if (!_tag_active_cdm
) {
1032 if (active_post_id
== _tag_active_post_id
) {
1033 debug("reloading current article");
1034 view(_tag_active_post_id
, _tag_active_feed_id
);
1037 debug("reloading current feed");
1042 exception_error("catchup_callback", e
);
1047 function editTagsSave() {
1049 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1050 printLockingError();
1053 notify_progress("Saving article tags...");
1055 var form
= document
.forms
["tag_edit_form"];
1057 var query
= Form
.serialize("tag_edit_form");
1059 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1063 xmlhttp_rpc
.open("GET", query
, true);
1064 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1065 xmlhttp_rpc
.send(null);
1069 function editTagsInsert() {
1072 var form
= document
.forms
["tag_edit_form"];
1074 var found_tags
= form
.found_tags
;
1075 var tags_str
= form
.tags_str
;
1077 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1079 if (tags_str
.value
.length
> 0 &&
1080 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1082 tags_str
.value
= tags_str
.value
+ ", ";
1085 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1087 found_tags
.selectedIndex
= 0;
1090 exception_error(e
, "editTagsInsert");
1094 function cdmWatchdog() {
1098 var ctr
= document
.getElementById("headlinesInnerContainer");
1102 var ids
= new Array();
1104 var e
= ctr
.firstChild
;
1107 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1108 e
.id
.match("RROW-")) {
1110 // article fits in viewport OR article is longer than viewport and
1111 // its bottom is visible
1113 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1114 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1116 // debug(e.id + " is visible " + e.offsetTop + "." +
1117 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1118 // (ctr.scrollTop + ctr.offsetHeight));
1120 ids
.push(e
.id
.replace("RROW-", ""));
1122 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1123 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1124 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1126 ids
.push(e
.id
.replace("RROW-", ""));
1130 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1132 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1133 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1135 ids.push(e.id.replace("RROW-", ""));
1144 debug("cdmWatchdog, ids= " + ids
.toString());
1146 if (ids
.length
> 0) {
1148 for (var i
= 0; i
< ids
.length
; i
++) {
1149 var e
= document
.getElementById("RROW-" + ids
[i
]);
1151 e
.className
= e
.className
.replace("Unread", "");
1155 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1156 param_escape(ids
.toString()) + "&cmode=0";
1158 new Ajax
.Request(query
, {
1159 onComplete: function(transport
) {
1160 all_counters_callback2(transport
);
1165 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1168 exception_error(e
, "cdmWatchdog");
1174 function cache_inject(id
, article
) {
1175 if (!cache_check(id
)) {
1176 debug("cache_article: miss: " + id
);
1178 var cache_obj
= new Array();
1180 cache_obj
["id"] = id
;
1181 cache_obj
["data"] = article
;
1183 article_cache
.push(cache_obj
);
1186 debug("cache_article: hit: " + id
);
1190 function cache_find(id
) {
1191 for (var i
= 0; i
< article_cache
.length
; i
++) {
1192 if (article_cache
[i
]["id"] == id
) {
1193 return article_cache
[i
]["data"];
1199 function cache_check(id
) {
1200 for (var i
= 0; i
< article_cache
.length
; i
++) {
1201 if (article_cache
[i
]["id"] == id
) {
1208 function cache_expire() {
1209 while (article_cache
.length
> 20) {
1210 article_cache
.shift();
1214 function cache_invalidate(id
) {
1219 while (i
< article_cache
.length
) {
1220 if (article_cache
[i
]["id"] == id
) {
1221 debug("cache_invalidate: removed id " + id
);
1222 article_cache
.splice(i
, 1);
1227 debug("cache_invalidate: id not found: " + id
);
1230 exception_error("cache_invalidate", e
);
1234 function getActiveArticleId() {
1235 return active_post_id
;
1238 function cdmMouseIn(elem
) {
1240 if (elem
.id
&& elem
.id
.match("RROW-")) {
1241 var id
= elem
.id
.replace("RROW-", "");
1242 active_post_id
= id
;
1245 exception_error("cdmMouseIn", e
);
1250 function cdmMouseOut(elem
) {
1251 active_post_id
= false;
1254 function headlines_scroll_handler() {
1257 var e
= document
.getElementById("headlinesInnerContainer");
1259 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1260 if (!_infscroll_disable
) {
1261 debug("more cowbell!");
1267 exception_error("headlines_scroll_handler", e
);
1271 function catchupRelativeToArticle(below
) {
1275 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1276 printLockingError();
1279 if (!getActiveArticleId()) {
1280 alert(__("No article is selected."));
1286 if (document
.getElementById("headlinesList")) {
1287 visible_ids
= getVisibleHeadlineIds();
1289 visible_ids
= cdmGetVisibleArticles();
1292 var ids_to_mark
= new Array();
1295 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1296 if (visible_ids
[i
] != getActiveArticleId()) {
1297 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1299 if (e
&& e
.className
.match("Unread")) {
1300 ids_to_mark
.push(visible_ids
[i
]);
1307 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1308 if (visible_ids
[i
] != getActiveArticleId()) {
1309 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1311 if (e
&& e
.className
.match("Unread")) {
1312 ids_to_mark
.push(visible_ids
[i
]);
1320 if (ids_to_mark
.length
== 0) {
1321 alert(__("No articles found to mark"));
1323 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1327 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1328 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1329 e
.className
= e
.className
.replace("Unread", "");
1332 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1333 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1335 xmlhttp_rpc
.open("GET", query
, true);
1336 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1337 xmlhttp_rpc
.send(null);
1343 exception_error("catchupRelativeToArticle", e
);