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
, is_cat
, feed_cur_page
) {
51 debug("headlines_callback2 [page=" + feed_cur_page
+ "]");
53 var feeds
= document
.getElementById("feedList").getElementsByTagName("LI");
55 for (var i
= 0; i
< feeds
.length
; i
++) {
56 if (feeds
[i
].id
&& feeds
[i
].id
.match("FEEDR-")) {
57 feeds
[i
].className
= feeds
[i
].className
.replace("Selected", "");
61 setActiveFeedId(active_feed_id
);
63 if (is_cat
!= undefined) {
64 active_feed_is_cat
= is_cat
;
68 var feedr
= document
.getElementById("FEEDR-" + active_feed_id
);
69 if (feedr
&& !feedr
.className
.match("Selected")) {
70 feedr
.className
= feedr
.className
+ "Selected";
74 var f
= document
.getElementById("headlines-frame");
76 if (feed_cur_page
== 0) {
77 debug("resetting headlines scrollTop");
82 if (transport
.responseXML
) {
83 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
84 var headlines_count_obj
= transport
.responseXML
.getElementsByTagName("headlines-count")[0];
86 var headlines_count
= headlines_count_obj
.getAttribute("value");
88 if (headlines_count
== 0) _infscroll_disable
= 1;
90 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
91 var articles
= transport
.responseXML
.getElementsByTagName("article");
92 var runtime_info
= transport
.responseXML
.getElementsByTagName("runtime-info");
94 if (feed_cur_page
== 0) {
96 f
.innerHTML
= headlines
.firstChild
.nodeValue
;
98 debug("headlines_callback: returned no data");
99 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
104 if (headlines_count
> 0) {
105 debug("adding some more headlines...");
107 var c
= document
.getElementById("headlinesList");
110 c
= document
.getElementById("headlinesInnerContainer");
113 var ids
= getSelectedArticleIds2();
115 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
117 debug("restore selected ids: " + ids
);
119 for (var i
= 0; i
< ids
.length
; i
++) {
120 markHeadline(ids
[i
]);
124 debug("no new headlines received");
127 debug("headlines_callback: returned no data");
128 notify_error("Error while trying to load more headlines");
134 for (var i
= 0; i
< articles
.length
; i
++) {
135 var a_id
= articles
[i
].getAttribute("id");
136 debug("found id: " + a_id
);
137 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
140 debug("no cached articles received");
144 debug("parsing piggybacked counters: " + counters
);
145 parse_counters(counters
, false);
147 debug("counters container not found in reply");
151 debug("parsing runtime info: " + runtime_info
[0]);
152 parse_runtime_info(runtime_info
[0]);
154 debug("counters container not found in reply");
158 debug("headlines_callback: returned no XML object");
159 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
162 if (typeof correctPNG
!= 'undefined') {
166 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
168 if (!document
.getElementById("headlinesList") &&
169 getInitParam("cdm_auto_catchup") == 1) {
170 debug("starting CDM watchdog");
171 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
172 _cdm_wd_vishist
= new Array();
174 debug("not in CDM mode or watchdog disabled");
177 if (_tag_cdm_scroll
) {
179 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
180 _tag_cdm_scroll
= false;
181 debug("resetting headlinesInner scrollTop");
186 _feed_cur_page
= feed_cur_page
;
187 _infscroll_request_sent
= 0;
191 exception_error("headlines_callback2", e
);
195 function render_article(article
) {
197 var f
= document
.getElementById("content-frame");
202 f
.innerHTML
= article
;
205 exception_error("render_article", e
);
209 function showArticleInHeadlines(id
) {
213 cleanSelected("headlinesList");
215 var crow
= document
.getElementById("RROW-" + id
);
216 var article_is_unread
= crow
.className
.match("Unread");
218 crow
.className
= crow
.className
.replace("Unread", "");
220 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
223 upd_img_pic
.src
= "images/blank_icon.gif";
226 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
230 exception_error("showArticleInHeadlines", e
);
234 function article_callback2(transport
, id
, feed_id
) {
236 debug("article_callback2 " + id
);
238 if (transport
.responseXML
) {
240 active_real_feed_id
= feed_id
;
243 showArticleInHeadlines(id
);
245 var reply
= transport
.responseXML
.firstChild
.firstChild
;
247 var articles
= transport
.responseXML
.getElementsByTagName("article");
249 for (var i
= 0; i
< articles
.length
; i
++) {
250 var a_id
= articles
[i
].getAttribute("id");
252 debug("found id: " + a_id
);
254 if (a_id
== active_post_id
) {
255 debug("active article, rendering...");
256 render_article(articles
[i
].firstChild
.nodeValue
);
259 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
263 debug("article_callback: returned no XML object");
264 var f
= document
.getElementById("content-frame");
265 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
268 var date
= new Date();
269 last_article_view
= date
.getTime() / 1000;
271 if (typeof correctPNG
!= 'undefined') {
275 if (_reload_feedlist_after_view
) {
276 setTimeout('updateFeedList(false, false)', 50);
277 _reload_feedlist_after_view
= false;
279 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
282 debug("parsing piggybacked counters: " + counters
);
283 parse_counters(counters
, false);
285 debug("counters container not found in reply");
291 exception_error("article_callback2", e
);
295 function view(id
, feed_id
, skip_history
) {
298 debug("loading article: " + id
+ "/" + feed_id
);
300 var cached_article
= cache_find(id
);
302 debug("cache check result: " + (cached_article
!= false));
306 //setActiveFeedId(feed_id);
308 var query
= "backend.php?op=view&id=" + param_escape(id
) +
309 "&feed=" + param_escape(feed_id
);
311 var date
= new Date();
313 var neighbor_ids
= getRelativePostIds(active_post_id
);
315 /* only request uncached articles */
317 var cids_to_request
= Array();
319 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
320 if (!cache_check(neighbor_ids
[i
])) {
321 cids_to_request
.push(neighbor_ids
[i
]);
325 debug("additional ids: " + cids_to_request
.toString());
327 /* additional info for piggyback counters */
329 if (tagsAreDisplayed()) {
330 query
= query
+ "&omode=lt";
332 query
= query
+ "&omode=flc";
335 var date
= new Date();
336 var timestamp
= Math
.round(date
.getTime() / 1000);
337 query
= query
+ "&ts=" + timestamp
;
339 query
= query
+ "&cids=" + cids_to_request
.toString();
341 var crow
= document
.getElementById("RROW-" + id
);
342 var article_is_unread
= crow
.className
.match("Unread");
344 showArticleInHeadlines(id
);
346 if (!cached_article
) {
348 notify_progress("Loading, please wait...");
350 } else if (cached_article
&& article_is_unread
) {
352 query
= query
+ "&mode=prefetch";
354 render_article(cached_article
);
356 } else if (cached_article
) {
358 query
= query
+ "&mode=prefetch_old";
359 render_article(cached_article
);
364 new Ajax
.Request(query
, {
365 onComplete: function(transport
) {
366 article_callback2(transport
, id
, feed_id
);
370 exception_error("view", e
);
375 return toggleMark(id
);
379 return togglePub(id
);
382 function tMark_afh_off(effect
) {
384 var elem
= effect
.effects
[0].element
;
386 debug("tMark_afh_off : " + elem
.id
);
389 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
390 elem
.alt
= __("Star article");
395 exception_error("tMark_afh_off", e
);
399 function tPub_afh_off(effect
) {
401 var elem
= effect
.effects
[0].element
;
403 debug("tPub_afh_off : " + elem
.id
);
406 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
407 elem
.alt
= __("Publish article");
412 exception_error("tPub_afh_off", e
);
416 function toggleMark(id
, client_only
, no_effects
) {
420 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
422 query
= query
+ "&afid=" + getActiveFeedId();
424 if (tagsAreDisplayed()) {
425 query
= query
+ "&omode=tl";
427 query
= query
+ "&omode=flc";
430 var mark_img
= document
.getElementById("FMPIC-" + id
);
431 var vfeedu
= document
.getElementById("FEEDU--1");
432 var crow
= document
.getElementById("RROW-" + id
);
434 if (mark_img
.src
.match("mark_unset")) {
435 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
436 mark_img
.alt
= __("Unstar article");
437 query
= query
+ "&mark=1";
439 /* if (vfeedu && crow.className.match("Unread")) {
440 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
444 //mark_img.src = "images/mark_unset.png";
445 mark_img
.alt
= __("Please wait...");
446 query
= query
+ "&mark=0";
448 /* if (vfeedu && crow.className.match("Unread")) {
449 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
452 if (document
.getElementById("headlinesList") && !no_effects
) {
453 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
455 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
456 mark_img
.alt
= __("Star article");
460 /* var vfeedctr = document.getElementById("FEEDCTR--1");
461 var vfeedr = document.getElementById("FEEDR--1");
463 if (vfeedu && vfeedctr) {
464 if ((+vfeedu.innerHTML) > 0) {
465 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
466 vfeedr.className = vfeedr.className + "Unread";
467 vfeedctr.className = "odd";
470 vfeedctr.className = "invisible";
471 vfeedr.className = vfeedr.className.replace("Unread", "");
475 debug("toggle starred for aid " + id);
477 //new Ajax.Request(query); */
482 new Ajax
.Request(query
, {
483 onComplete: function(transport
) {
484 all_counters_callback2(transport
);
490 exception_error("toggleMark", e
);
494 function togglePub(id
, client_only
, no_effects
) {
498 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
500 query
= query
+ "&afid=" + getActiveFeedId();
502 if (tagsAreDisplayed()) {
503 query
= query
+ "&omode=tl";
505 query
= query
+ "&omode=flc";
508 var mark_img
= document
.getElementById("FPPIC-" + id
);
509 var vfeedu
= document
.getElementById("FEEDU--2");
510 var crow
= document
.getElementById("RROW-" + id
);
512 if (mark_img
.src
.match("pub_unset")) {
513 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
514 mark_img
.alt
= __("Unpublish article");
515 query
= query
+ "&pub=1";
517 /* if (vfeedu && crow.className.match("Unread")) {
518 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
522 //mark_img.src = "images/pub_unset.png";
523 mark_img
.alt
= __("Please wait...");
524 query
= query
+ "&pub=0";
526 /* if (vfeedu && crow.className.match("Unread")) {
527 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
530 if (document
.getElementById("headlinesList") && !no_effects
) {
531 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
533 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
534 mark_img
.alt
= __("Publish article");
538 /* var vfeedctr = document.getElementById("FEEDCTR--2");
539 var vfeedr = document.getElementById("FEEDR--2");
541 if (vfeedu && vfeedctr) {
542 if ((+vfeedu.innerHTML) > 0) {
543 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
544 vfeedr.className = vfeedr.className + "Unread";
545 vfeedctr.className = "odd";
548 vfeedctr.className = "invisible";
549 vfeedr.className = vfeedr.className.replace("Unread", "");
553 debug("toggle published for aid " + id);
555 new Ajax.Request(query); */
558 new Ajax
.Request(query
, {
559 onComplete: function(transport
) {
560 all_counters_callback2(transport
);
566 exception_error("togglePub", e
);
570 function correctHeadlinesOffset(id
) {
574 var hlist
= document
.getElementById("headlinesList");
575 var container
= document
.getElementById("headlinesInnerContainer");
576 var row
= document
.getElementById("RROW-" + id
);
578 var viewport
= container
.offsetHeight
;
580 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
581 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
583 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
584 debug("Vport: " + viewport
);
586 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
587 container
.scrollTop
= row
.offsetTop
;
588 } else if (rel_offset_bottom
> viewport
) {
590 /* doesn't properly work with Opera in some cases because
591 Opera fucks up element scrolling */
593 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
597 exception_error("correctHeadlinesOffset", e
);
602 function moveToPost(mode
) {
604 // check for combined mode
605 if (!document
.getElementById("headlinesList"))
608 var rows
= getVisibleHeadlineIds();
613 if (!document
.getElementById('RROW-' + active_post_id
)) {
614 active_post_id
= false;
617 if (active_post_id
== false) {
618 next_id
= getFirstVisibleHeadlineId();
619 prev_id
= getLastVisibleHeadlineId();
621 for (var i
= 0; i
< rows
.length
; i
++) {
622 if (rows
[i
] == active_post_id
) {
629 if (mode
== "next") {
631 correctHeadlinesOffset(next_id
);
632 view(next_id
, getActiveFeedId());
636 if (mode
== "prev") {
638 correctHeadlinesOffset(prev_id
);
639 view(prev_id
, getActiveFeedId());
644 function toggleUnread(id
, cmode
) {
647 var row
= document
.getElementById("RROW-" + id
);
649 var nc
= row
.className
;
650 nc
= nc
.replace("Unread", "");
651 nc
= nc
.replace("Selected", "");
653 if (row
.className
.match("Unread")) {
656 row
.className
= nc
+ "Unread";
659 if (!cmode
) cmode
= 2;
661 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
662 param_escape(id
) + "&cmode=" + param_escape(cmode
);
664 // notify_progress("Loading, please wait...");
666 new Ajax
.Request(query
, {
667 onComplete: function(transport
) {
668 all_counters_callback2(transport
);
675 exception_error("toggleUnread", e
);
679 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
684 rows
= cdmGetSelectedArticles();
686 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
689 if (rows
.length
== 0 && !no_error
) {
690 alert(__("No articles are selected."));
694 for (i
= 0; i
< rows
.length
; i
++) {
695 var row
= document
.getElementById("RROW-" + rows
[i
]);
697 var nc
= row
.className
;
698 nc
= nc
.replace("Unread", "");
699 nc
= nc
.replace("Selected", "");
701 if (set_state
== undefined) {
702 if (row
.className
.match("Unread")) {
703 row
.className
= nc
+ "Selected";
705 row
.className
= nc
+ "UnreadSelected";
709 if (set_state
== false) {
710 row
.className
= nc
+ "Selected";
713 if (set_state
== true) {
714 row
.className
= nc
+ "UnreadSelected";
719 if (rows
.length
> 0) {
723 if (set_state
== undefined) {
725 } else if (set_state
== true) {
727 } else if (set_state
== false) {
731 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
732 param_escape(rows
.toString()) + "&cmode=" + cmode
;
734 notify_progress("Loading, please wait...");
736 new Ajax
.Request(query
, {
737 onComplete: function(transport
) {
738 catchup_callback2(transport
, callback_func
);
744 exception_error("selectionToggleUnread", e
);
748 function selectionToggleMarked(cdm_mode
) {
754 rows
= cdmGetSelectedArticles();
756 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
759 if (rows
.length
== 0) {
760 alert(__("No articles are selected."));
764 for (i
= 0; i
< rows
.length
; i
++) {
765 toggleMark(rows
[i
], true, true);
768 if (rows
.length
> 0) {
770 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
771 param_escape(rows
.toString()) + "&cmode=2";
773 query
= query
+ "&afid=" + getActiveFeedId();
775 /* if (tagsAreDisplayed()) {
776 query = query + "&omode=tl";
778 query = query + "&omode=flc";
781 query
= query
+ "&omode=lc";
783 new Ajax
.Request(query
, {
784 onComplete: function(transport
) {
785 all_counters_callback2(transport
);
791 exception_error("selectionToggleMarked", e
);
795 function selectionTogglePublished(cdm_mode
) {
801 rows
= cdmGetSelectedArticles();
803 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
806 if (rows
.length
== 0) {
807 alert(__("No articles are selected."));
811 for (i
= 0; i
< rows
.length
; i
++) {
812 togglePub(rows
[i
], true, true);
815 if (rows
.length
> 0) {
817 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
818 param_escape(rows
.toString()) + "&cmode=2";
820 query
= query
+ "&afid=" + getActiveFeedId();
822 /* if (tagsAreDisplayed()) {
823 query = query + "&omode=tl";
825 query = query + "&omode=flc";
828 query
= query
+ "&omode=lc";
830 new Ajax
.Request(query
, {
831 onComplete: function(transport
) {
832 all_counters_callback2(transport
);
838 exception_error("selectionToggleMarked", e
);
842 function cdmGetSelectedArticles() {
843 var sel_articles
= new Array();
844 var container
= document
.getElementById("headlinesInnerContainer");
846 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
847 var child
= container
.childNodes
[i
];
849 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
850 var c_id
= child
.id
.replace("RROW-", "");
851 sel_articles
.push(c_id
);
858 function cdmGetVisibleArticles() {
859 var sel_articles
= new Array();
860 var container
= document
.getElementById("headlinesInnerContainer");
862 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
863 var child
= container
.childNodes
[i
];
865 if (child
.id
.match("RROW-")) {
866 var c_id
= child
.id
.replace("RROW-", "");
867 sel_articles
.push(c_id
);
874 function cdmGetUnreadArticles() {
875 var sel_articles
= new Array();
876 var container
= document
.getElementById("headlinesInnerContainer");
878 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
879 var child
= container
.childNodes
[i
];
881 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
882 var c_id
= child
.id
.replace("RROW-", "");
883 sel_articles
.push(c_id
);
891 // mode = all,none,unread
892 function cdmSelectArticles(mode
) {
893 var container
= document
.getElementById("headlinesInnerContainer");
895 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
896 var child
= container
.childNodes
[i
];
898 if (child
.id
.match("RROW-")) {
899 var aid
= child
.id
.replace("RROW-", "");
901 var cb
= document
.getElementById("RCHK-" + aid
);
904 if (!child
.className
.match("Selected")) {
905 child
.className
= child
.className
+ "Selected";
908 } else if (mode
== "unread") {
909 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
910 child
.className
= child
.className
+ "Selected";
914 child
.className
= child
.className
.replace("Selected", "");
921 function catchupPage() {
923 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
925 var str
= __("Mark all visible articles in %s as read?");
927 str
= str
.replace("%s", fn
);
929 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
933 if (document
.getElementById("headlinesList")) {
934 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
935 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
936 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
938 cdmSelectArticles('all');
939 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
940 cdmSelectArticles('none');
944 function catchupSelection() {
950 if (document
.getElementById("headlinesList")) {
951 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
953 rows
= cdmGetSelectedArticles();
956 if (rows
.length
== 0) {
957 alert(__("No articles are selected."));
962 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
964 var str
= __("Mark %d selected articles in %s as read?");
966 str
= str
.replace("%d", rows
.length
);
967 str
= str
.replace("%s", fn
);
969 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
973 if (document
.getElementById("headlinesList")) {
974 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
975 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
977 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
978 // cdmSelectArticles('none');
982 exception_error("catchupSelection", e
);
987 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
989 if (!xmlhttp_ready(xmlhttp_rpc
)) {
993 var title
= prompt(__("Please enter label title:"), "");
997 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
998 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
999 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1000 "&title=" + param_escape(title
);
1002 debug("LFS: " + query
);
1004 new Ajax
.Request(query
, {
1005 onComplete: function(transport
) {
1006 dlg_frefresh_callback(transport
);
1011 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1012 _tag_active_post_id
= id
;
1013 _tag_active_feed_id
= feed_id
;
1014 _tag_active_cdm
= cdm_enabled
;
1016 cache_invalidate(id
);
1019 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1021 displayDlg('editArticleTags', id
);
1025 function tag_saved_callback(transport
) {
1027 debug("in tag_saved_callback");
1032 if (tagsAreDisplayed()) {
1033 _reload_feedlist_after_view
= true;
1036 if (!_tag_active_cdm
) {
1037 if (active_post_id
== _tag_active_post_id
) {
1038 debug("reloading current article");
1039 view(_tag_active_post_id
, _tag_active_feed_id
);
1042 debug("reloading current feed");
1047 exception_error("catchup_callback", e
);
1051 function editTagsSave() {
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 new Ajax
.Request(query
, {
1064 onComplete: function(transport
) {
1065 tag_saved_callback(transport
);
1070 function editTagsInsert() {
1073 var form
= document
.forms
["tag_edit_form"];
1075 var found_tags
= form
.found_tags
;
1076 var tags_str
= form
.tags_str
;
1078 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1080 if (tags_str
.value
.length
> 0 &&
1081 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1083 tags_str
.value
= tags_str
.value
+ ", ";
1086 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1088 found_tags
.selectedIndex
= 0;
1091 exception_error(e
, "editTagsInsert");
1095 function cdmWatchdog() {
1099 var ctr
= document
.getElementById("headlinesInnerContainer");
1103 var ids
= new Array();
1105 var e
= ctr
.firstChild
;
1108 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1109 e
.id
.match("RROW-")) {
1111 // article fits in viewport OR article is longer than viewport and
1112 // its bottom is visible
1114 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1115 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1117 // debug(e.id + " is visible " + e.offsetTop + "." +
1118 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1119 // (ctr.scrollTop + ctr.offsetHeight));
1121 ids
.push(e
.id
.replace("RROW-", ""));
1123 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1124 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1125 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1127 ids
.push(e
.id
.replace("RROW-", ""));
1131 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1133 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1134 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1136 ids.push(e.id.replace("RROW-", ""));
1145 debug("cdmWatchdog, ids= " + ids
.toString());
1147 if (ids
.length
> 0) {
1149 for (var i
= 0; i
< ids
.length
; i
++) {
1150 var e
= document
.getElementById("RROW-" + ids
[i
]);
1152 e
.className
= e
.className
.replace("Unread", "");
1156 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1157 param_escape(ids
.toString()) + "&cmode=0";
1159 new Ajax
.Request(query
, {
1160 onComplete: function(transport
) {
1161 all_counters_callback2(transport
);
1166 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1169 exception_error(e
, "cdmWatchdog");
1175 function cache_inject(id
, article
) {
1176 if (!cache_check(id
)) {
1177 debug("cache_article: miss: " + id
);
1179 var cache_obj
= new Array();
1181 cache_obj
["id"] = id
;
1182 cache_obj
["data"] = article
;
1184 article_cache
.push(cache_obj
);
1187 debug("cache_article: hit: " + id
);
1191 function cache_find(id
) {
1192 for (var i
= 0; i
< article_cache
.length
; i
++) {
1193 if (article_cache
[i
]["id"] == id
) {
1194 return article_cache
[i
]["data"];
1200 function cache_check(id
) {
1201 for (var i
= 0; i
< article_cache
.length
; i
++) {
1202 if (article_cache
[i
]["id"] == id
) {
1209 function cache_expire() {
1210 while (article_cache
.length
> 20) {
1211 article_cache
.shift();
1215 function cache_invalidate(id
) {
1220 while (i
< article_cache
.length
) {
1221 if (article_cache
[i
]["id"] == id
) {
1222 debug("cache_invalidate: removed id " + id
);
1223 article_cache
.splice(i
, 1);
1228 debug("cache_invalidate: id not found: " + id
);
1231 exception_error("cache_invalidate", e
);
1235 function getActiveArticleId() {
1236 return active_post_id
;
1239 function cdmMouseIn(elem
) {
1241 if (elem
.id
&& elem
.id
.match("RROW-")) {
1242 var id
= elem
.id
.replace("RROW-", "");
1243 active_post_id
= id
;
1246 exception_error("cdmMouseIn", e
);
1251 function cdmMouseOut(elem
) {
1252 active_post_id
= false;
1255 function headlines_scroll_handler() {
1258 var e
= document
.getElementById("headlinesInnerContainer");
1260 // don't do infinite scrolling when Limit == All
1262 var toolbar_form
= document
.forms
["main_toolbar_form"];
1264 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1265 if (limit
.value
!= 0) {
1266 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1267 if (!_infscroll_disable
) {
1268 debug("more cowbell!");
1275 exception_error("headlines_scroll_handler", e
);
1279 function catchupRelativeToArticle(below
) {
1283 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1284 printLockingError();
1287 if (!getActiveArticleId()) {
1288 alert(__("No article is selected."));
1294 if (document
.getElementById("headlinesList")) {
1295 visible_ids
= getVisibleHeadlineIds();
1297 visible_ids
= cdmGetVisibleArticles();
1300 var ids_to_mark
= new Array();
1303 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1304 if (visible_ids
[i
] != getActiveArticleId()) {
1305 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1307 if (e
&& e
.className
.match("Unread")) {
1308 ids_to_mark
.push(visible_ids
[i
]);
1315 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1316 if (visible_ids
[i
] != getActiveArticleId()) {
1317 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1319 if (e
&& e
.className
.match("Unread")) {
1320 ids_to_mark
.push(visible_ids
[i
]);
1328 if (ids_to_mark
.length
== 0) {
1329 alert(__("No articles found to mark"));
1331 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1335 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1336 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1337 e
.className
= e
.className
.replace("Unread", "");
1340 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1341 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1343 new Ajax
.Request(query
, {
1344 onComplete: function(transport
) {
1345 catchup_callback2(transport
);
1352 exception_error("catchupRelativeToArticle", e
);