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 c
.innerHTML
= c
.innerHTML
+ headlines
.firstChild
.nodeValue
;
115 debug("no new headlines received");
118 debug("headlines_callback: returned no data");
119 notify_error("Error while trying to load more headlines");
125 for (var i
= 0; i
< articles
.length
; i
++) {
126 var a_id
= articles
[i
].getAttribute("id");
127 debug("found id: " + a_id
);
128 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
131 debug("no cached articles received");
135 debug("parsing piggybacked counters: " + counters
);
136 parse_counters(counters
, false);
138 debug("counters container not found in reply");
142 debug("parsing runtime info: " + runtime_info
[0]);
143 parse_runtime_info(runtime_info
[0]);
145 debug("counters container not found in reply");
149 debug("headlines_callback: returned no XML object");
150 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
153 if (typeof correctPNG
!= 'undefined') {
157 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
159 if (!document
.getElementById("headlinesList") &&
160 getInitParam("cdm_auto_catchup") == 1) {
161 debug("starting CDM watchdog");
162 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
163 _cdm_wd_vishist
= new Array();
165 debug("not in CDM mode or watchdog disabled");
168 if (_tag_cdm_scroll
) {
170 document
.getElementById("headlinesInnerContainer").scrollTop
= _tag_cdm_scroll
;
171 _tag_cdm_scroll
= false;
172 debug("resetting headlinesInner scrollTop");
177 _feed_cur_page
= feed_cur_page
;
181 exception_error("headlines_callback2", e
);
185 function render_article(article
) {
187 var f
= document
.getElementById("content-frame");
192 f
.innerHTML
= article
;
195 exception_error("render_article", e
);
199 function showArticleInHeadlines(id
) {
203 cleanSelected("headlinesList");
205 var crow
= document
.getElementById("RROW-" + id
);
206 var article_is_unread
= crow
.className
.match("Unread");
208 crow
.className
= crow
.className
.replace("Unread", "");
210 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
213 upd_img_pic
.src
= "images/blank_icon.gif";
216 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
220 exception_error("showArticleInHeadlines", e
);
224 function article_callback2(transport
, id
, feed_id
) {
226 debug("article_callback2 " + id
);
228 if (transport
.responseXML
) {
230 active_real_feed_id
= feed_id
;
233 showArticleInHeadlines(id
);
235 var reply
= transport
.responseXML
.firstChild
.firstChild
;
237 var articles
= transport
.responseXML
.getElementsByTagName("article");
239 for (var i
= 0; i
< articles
.length
; i
++) {
240 var a_id
= articles
[i
].getAttribute("id");
242 debug("found id: " + a_id
);
244 if (a_id
== active_post_id
) {
245 debug("active article, rendering...");
246 render_article(articles
[i
].firstChild
.nodeValue
);
249 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
253 debug("article_callback: returned no XML object");
254 var f
= document
.getElementById("content-frame");
255 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
258 var date
= new Date();
259 last_article_view
= date
.getTime() / 1000;
261 if (typeof correctPNG
!= 'undefined') {
265 if (_reload_feedlist_after_view
) {
266 setTimeout('updateFeedList(false, false)', 50);
267 _reload_feedlist_after_view
= false;
269 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
272 debug("parsing piggybacked counters: " + counters
);
273 parse_counters(counters
, false);
275 debug("counters container not found in reply");
281 exception_error("article_callback2", e
);
285 function view(id
, feed_id
, skip_history
) {
288 debug("loading article: " + id
+ "/" + feed_id
);
290 var cached_article
= cache_find(id
);
292 debug("cache check result: " + (cached_article
!= false));
296 //setActiveFeedId(feed_id);
298 var query
= "backend.php?op=view&id=" + param_escape(id
) +
299 "&feed=" + param_escape(feed_id
);
301 var date
= new Date();
303 var neighbor_ids
= getRelativePostIds(active_post_id
);
305 /* only request uncached articles */
307 var cids_to_request
= Array();
309 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
310 if (!cache_check(neighbor_ids
[i
])) {
311 cids_to_request
.push(neighbor_ids
[i
]);
315 debug("additional ids: " + cids_to_request
.toString());
317 /* additional info for piggyback counters */
319 if (tagsAreDisplayed()) {
320 query
= query
+ "&omode=lt";
322 query
= query
+ "&omode=flc";
325 var date
= new Date();
326 var timestamp
= Math
.round(date
.getTime() / 1000);
327 query
= query
+ "&ts=" + timestamp
;
329 query
= query
+ "&cids=" + cids_to_request
.toString();
331 var crow
= document
.getElementById("RROW-" + id
);
332 var article_is_unread
= crow
.className
.match("Unread");
334 showArticleInHeadlines(id
);
336 if (!cached_article
) {
338 notify_progress("Loading, please wait...");
340 } else if (cached_article
&& article_is_unread
) {
342 query
= query
+ "&mode=prefetch";
344 render_article(cached_article
);
346 } else if (cached_article
) {
348 query
= query
+ "&mode=prefetch_old";
349 render_article(cached_article
);
354 new Ajax
.Request(query
, {
355 onComplete: function(transport
) {
356 article_callback2(transport
, id
, feed_id
);
360 exception_error("view", e
);
365 return toggleMark(id
);
369 return togglePub(id
);
372 function tMark_afh_off(effect
) {
374 var elem
= effect
.effects
[0].element
;
376 debug("tMark_afh_off : " + elem
.id
);
379 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
380 elem
.alt
= __("Star article");
385 exception_error("tMark_afh_off", e
);
389 function tPub_afh_off(effect
) {
391 var elem
= effect
.effects
[0].element
;
393 debug("tPub_afh_off : " + elem
.id
);
396 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
397 elem
.alt
= __("Publish article");
402 exception_error("tPub_afh_off", e
);
406 function toggleMark(id
, client_only
, no_effects
) {
410 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
412 query
= query
+ "&afid=" + getActiveFeedId();
414 if (tagsAreDisplayed()) {
415 query
= query
+ "&omode=tl";
417 query
= query
+ "&omode=flc";
420 var mark_img
= document
.getElementById("FMPIC-" + id
);
421 var vfeedu
= document
.getElementById("FEEDU--1");
422 var crow
= document
.getElementById("RROW-" + id
);
424 if (mark_img
.src
.match("mark_unset")) {
425 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
426 mark_img
.alt
= __("Unstar article");
427 query
= query
+ "&mark=1";
429 /* if (vfeedu && crow.className.match("Unread")) {
430 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
434 //mark_img.src = "images/mark_unset.png";
435 mark_img
.alt
= __("Please wait...");
436 query
= query
+ "&mark=0";
438 /* if (vfeedu && crow.className.match("Unread")) {
439 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
442 if (document
.getElementById("headlinesList") && !no_effects
) {
443 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
445 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
446 mark_img
.alt
= __("Star article");
450 /* var vfeedctr = document.getElementById("FEEDCTR--1");
451 var vfeedr = document.getElementById("FEEDR--1");
453 if (vfeedu && vfeedctr) {
454 if ((+vfeedu.innerHTML) > 0) {
455 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
456 vfeedr.className = vfeedr.className + "Unread";
457 vfeedctr.className = "odd";
460 vfeedctr.className = "invisible";
461 vfeedr.className = vfeedr.className.replace("Unread", "");
465 debug("toggle starred for aid " + id);
467 //new Ajax.Request(query); */
472 new Ajax
.Request(query
, {
473 onComplete: function(transport
) {
474 all_counters_callback2(transport
);
480 exception_error("toggleMark", e
);
484 function togglePub(id
, client_only
, no_effects
) {
488 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
490 query
= query
+ "&afid=" + getActiveFeedId();
492 if (tagsAreDisplayed()) {
493 query
= query
+ "&omode=tl";
495 query
= query
+ "&omode=flc";
498 var mark_img
= document
.getElementById("FPPIC-" + id
);
499 var vfeedu
= document
.getElementById("FEEDU--2");
500 var crow
= document
.getElementById("RROW-" + id
);
502 if (mark_img
.src
.match("pub_unset")) {
503 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
504 mark_img
.alt
= __("Unpublish article");
505 query
= query
+ "&pub=1";
507 /* if (vfeedu && crow.className.match("Unread")) {
508 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
512 //mark_img.src = "images/pub_unset.png";
513 mark_img
.alt
= __("Please wait...");
514 query
= query
+ "&pub=0";
516 /* if (vfeedu && crow.className.match("Unread")) {
517 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
520 if (document
.getElementById("headlinesList") && !no_effects
) {
521 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
523 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
524 mark_img
.alt
= __("Publish article");
528 /* var vfeedctr = document.getElementById("FEEDCTR--2");
529 var vfeedr = document.getElementById("FEEDR--2");
531 if (vfeedu && vfeedctr) {
532 if ((+vfeedu.innerHTML) > 0) {
533 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
534 vfeedr.className = vfeedr.className + "Unread";
535 vfeedctr.className = "odd";
538 vfeedctr.className = "invisible";
539 vfeedr.className = vfeedr.className.replace("Unread", "");
543 debug("toggle published for aid " + id);
545 new Ajax.Request(query); */
548 new Ajax
.Request(query
, {
549 onComplete: function(transport
) {
550 all_counters_callback2(transport
);
556 exception_error("togglePub", e
);
560 function correctHeadlinesOffset(id
) {
564 var hlist
= document
.getElementById("headlinesList");
565 var container
= document
.getElementById("headlinesInnerContainer");
566 var row
= document
.getElementById("RROW-" + id
);
568 var viewport
= container
.offsetHeight
;
570 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
571 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
573 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
574 debug("Vport: " + viewport
);
576 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
577 container
.scrollTop
= row
.offsetTop
;
578 } else if (rel_offset_bottom
> viewport
) {
580 /* doesn't properly work with Opera in some cases because
581 Opera fucks up element scrolling */
583 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
587 exception_error("correctHeadlinesOffset", e
);
592 function moveToPost(mode
) {
594 // check for combined mode
595 if (!document
.getElementById("headlinesList"))
598 var rows
= getVisibleHeadlineIds();
603 if (!document
.getElementById('RROW-' + active_post_id
)) {
604 active_post_id
= false;
607 if (active_post_id
== false) {
608 next_id
= getFirstVisibleHeadlineId();
609 prev_id
= getLastVisibleHeadlineId();
611 for (var i
= 0; i
< rows
.length
; i
++) {
612 if (rows
[i
] == active_post_id
) {
619 if (mode
== "next") {
621 correctHeadlinesOffset(next_id
);
622 view(next_id
, getActiveFeedId());
626 if (mode
== "prev") {
628 correctHeadlinesOffset(prev_id
);
629 view(prev_id
, getActiveFeedId());
634 function toggleUnread(id
, cmode
) {
637 var row
= document
.getElementById("RROW-" + id
);
639 var nc
= row
.className
;
640 nc
= nc
.replace("Unread", "");
641 nc
= nc
.replace("Selected", "");
643 if (row
.className
.match("Unread")) {
646 row
.className
= nc
+ "Unread";
649 if (!cmode
) cmode
= 2;
651 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
652 param_escape(id
) + "&cmode=" + param_escape(cmode
);
654 // notify_progress("Loading, please wait...");
656 new Ajax
.Request(query
, {
657 onComplete: function(transport
) {
658 all_counters_callback2(transport
);
665 exception_error("toggleUnread", e
);
669 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
674 rows
= cdmGetSelectedArticles();
676 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
679 if (rows
.length
== 0 && !no_error
) {
680 alert(__("No articles are selected."));
684 for (i
= 0; i
< rows
.length
; i
++) {
685 var row
= document
.getElementById("RROW-" + rows
[i
]);
687 var nc
= row
.className
;
688 nc
= nc
.replace("Unread", "");
689 nc
= nc
.replace("Selected", "");
691 if (set_state
== undefined) {
692 if (row
.className
.match("Unread")) {
693 row
.className
= nc
+ "Selected";
695 row
.className
= nc
+ "UnreadSelected";
699 if (set_state
== false) {
700 row
.className
= nc
+ "Selected";
703 if (set_state
== true) {
704 row
.className
= nc
+ "UnreadSelected";
709 if (rows
.length
> 0) {
713 if (set_state
== undefined) {
715 } else if (set_state
== true) {
717 } else if (set_state
== false) {
721 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
722 param_escape(rows
.toString()) + "&cmode=" + cmode
;
724 notify_progress("Loading, please wait...");
726 new Ajax
.Request(query
, {
727 onComplete: function(transport
) {
728 catchup_callback2(transport
, callback_func
);
734 exception_error("selectionToggleUnread", e
);
738 function selectionToggleMarked(cdm_mode
) {
744 rows
= cdmGetSelectedArticles();
746 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
749 if (rows
.length
== 0) {
750 alert(__("No articles are selected."));
754 for (i
= 0; i
< rows
.length
; i
++) {
755 toggleMark(rows
[i
], true, true);
758 if (rows
.length
> 0) {
760 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
761 param_escape(rows
.toString()) + "&cmode=2";
763 query
= query
+ "&afid=" + getActiveFeedId();
765 /* if (tagsAreDisplayed()) {
766 query = query + "&omode=tl";
768 query = query + "&omode=flc";
771 query
= query
+ "&omode=lc";
773 new Ajax
.Request(query
, {
774 onComplete: function(transport
) {
775 all_counters_callback2(transport
);
781 exception_error("selectionToggleMarked", e
);
785 function selectionTogglePublished(cdm_mode
) {
791 rows
= cdmGetSelectedArticles();
793 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
796 if (rows
.length
== 0) {
797 alert(__("No articles are selected."));
801 for (i
= 0; i
< rows
.length
; i
++) {
802 togglePub(rows
[i
], true, true);
805 if (rows
.length
> 0) {
807 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
808 param_escape(rows
.toString()) + "&cmode=2";
810 query
= query
+ "&afid=" + getActiveFeedId();
812 /* if (tagsAreDisplayed()) {
813 query = query + "&omode=tl";
815 query = query + "&omode=flc";
818 query
= query
+ "&omode=lc";
820 new Ajax
.Request(query
, {
821 onComplete: function(transport
) {
822 all_counters_callback2(transport
);
828 exception_error("selectionToggleMarked", e
);
832 function cdmGetSelectedArticles() {
833 var sel_articles
= new Array();
834 var container
= document
.getElementById("headlinesInnerContainer");
836 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
837 var child
= container
.childNodes
[i
];
839 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
840 var c_id
= child
.id
.replace("RROW-", "");
841 sel_articles
.push(c_id
);
848 function cdmGetVisibleArticles() {
849 var sel_articles
= new Array();
850 var container
= document
.getElementById("headlinesInnerContainer");
852 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
853 var child
= container
.childNodes
[i
];
855 if (child
.id
.match("RROW-")) {
856 var c_id
= child
.id
.replace("RROW-", "");
857 sel_articles
.push(c_id
);
864 function cdmGetUnreadArticles() {
865 var sel_articles
= new Array();
866 var container
= document
.getElementById("headlinesInnerContainer");
868 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
869 var child
= container
.childNodes
[i
];
871 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
872 var c_id
= child
.id
.replace("RROW-", "");
873 sel_articles
.push(c_id
);
881 // mode = all,none,unread
882 function cdmSelectArticles(mode
) {
883 var container
= document
.getElementById("headlinesInnerContainer");
885 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
886 var child
= container
.childNodes
[i
];
888 if (child
.id
.match("RROW-")) {
889 var aid
= child
.id
.replace("RROW-", "");
891 var cb
= document
.getElementById("RCHK-" + aid
);
894 if (!child
.className
.match("Selected")) {
895 child
.className
= child
.className
+ "Selected";
898 } else if (mode
== "unread") {
899 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
900 child
.className
= child
.className
+ "Selected";
904 child
.className
= child
.className
.replace("Selected", "");
911 function catchupPage() {
913 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
915 var str
= __("Mark all visible articles in %s as read?");
917 str
= str
.replace("%s", fn
);
919 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
923 if (document
.getElementById("headlinesList")) {
924 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
925 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
926 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
928 cdmSelectArticles('all');
929 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
930 cdmSelectArticles('none');
934 function catchupSelection() {
940 if (document
.getElementById("headlinesList")) {
941 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
943 rows
= cdmGetSelectedArticles();
946 if (rows
.length
== 0) {
947 alert(__("No articles are selected."));
952 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
954 var str
= __("Mark %d selected articles in %s as read?");
956 str
= str
.replace("%d", rows
.length
);
957 str
= str
.replace("%s", fn
);
959 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
963 if (document
.getElementById("headlinesList")) {
964 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
965 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
967 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
968 // cdmSelectArticles('none');
972 exception_error("catchupSelection", e
);
977 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
979 if (!xmlhttp_ready(xmlhttp_rpc
)) {
983 var title
= prompt(__("Please enter label title:"), "");
987 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
988 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
989 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
990 "&title=" + param_escape(title
);
992 debug("LFS: " + query
);
994 new Ajax
.Request(query
, {
995 onComplete: function(transport
) {
996 dlg_frefresh_callback(transport
);
1001 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1002 _tag_active_post_id
= id
;
1003 _tag_active_feed_id
= feed_id
;
1004 _tag_active_cdm
= cdm_enabled
;
1006 cache_invalidate(id
);
1009 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1011 displayDlg('editArticleTags', id
);
1015 function tag_saved_callback(transport
) {
1017 debug("in tag_saved_callback");
1022 if (tagsAreDisplayed()) {
1023 _reload_feedlist_after_view
= true;
1026 if (!_tag_active_cdm
) {
1027 if (active_post_id
== _tag_active_post_id
) {
1028 debug("reloading current article");
1029 view(_tag_active_post_id
, _tag_active_feed_id
);
1032 debug("reloading current feed");
1037 exception_error("catchup_callback", e
);
1041 function editTagsSave() {
1043 notify_progress("Saving article tags...");
1045 var form
= document
.forms
["tag_edit_form"];
1047 var query
= Form
.serialize("tag_edit_form");
1049 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1053 new Ajax
.Request(query
, {
1054 onComplete: function(transport
) {
1055 tag_saved_callback(transport
);
1060 function editTagsInsert() {
1063 var form
= document
.forms
["tag_edit_form"];
1065 var found_tags
= form
.found_tags
;
1066 var tags_str
= form
.tags_str
;
1068 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1070 if (tags_str
.value
.length
> 0 &&
1071 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1073 tags_str
.value
= tags_str
.value
+ ", ";
1076 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1078 found_tags
.selectedIndex
= 0;
1081 exception_error(e
, "editTagsInsert");
1085 function cdmWatchdog() {
1089 var ctr
= document
.getElementById("headlinesInnerContainer");
1093 var ids
= new Array();
1095 var e
= ctr
.firstChild
;
1098 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1099 e
.id
.match("RROW-")) {
1101 // article fits in viewport OR article is longer than viewport and
1102 // its bottom is visible
1104 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1105 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1107 // debug(e.id + " is visible " + e.offsetTop + "." +
1108 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1109 // (ctr.scrollTop + ctr.offsetHeight));
1111 ids
.push(e
.id
.replace("RROW-", ""));
1113 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1114 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1115 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1117 ids
.push(e
.id
.replace("RROW-", ""));
1121 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1123 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1124 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1126 ids.push(e.id.replace("RROW-", ""));
1135 debug("cdmWatchdog, ids= " + ids
.toString());
1137 if (ids
.length
> 0) {
1139 for (var i
= 0; i
< ids
.length
; i
++) {
1140 var e
= document
.getElementById("RROW-" + ids
[i
]);
1142 e
.className
= e
.className
.replace("Unread", "");
1146 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1147 param_escape(ids
.toString()) + "&cmode=0";
1149 new Ajax
.Request(query
, {
1150 onComplete: function(transport
) {
1151 all_counters_callback2(transport
);
1156 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1159 exception_error(e
, "cdmWatchdog");
1165 function cache_inject(id
, article
) {
1166 if (!cache_check(id
)) {
1167 debug("cache_article: miss: " + id
);
1169 var cache_obj
= new Array();
1171 cache_obj
["id"] = id
;
1172 cache_obj
["data"] = article
;
1174 article_cache
.push(cache_obj
);
1177 debug("cache_article: hit: " + id
);
1181 function cache_find(id
) {
1182 for (var i
= 0; i
< article_cache
.length
; i
++) {
1183 if (article_cache
[i
]["id"] == id
) {
1184 return article_cache
[i
]["data"];
1190 function cache_check(id
) {
1191 for (var i
= 0; i
< article_cache
.length
; i
++) {
1192 if (article_cache
[i
]["id"] == id
) {
1199 function cache_expire() {
1200 while (article_cache
.length
> 20) {
1201 article_cache
.shift();
1205 function cache_invalidate(id
) {
1210 while (i
< article_cache
.length
) {
1211 if (article_cache
[i
]["id"] == id
) {
1212 debug("cache_invalidate: removed id " + id
);
1213 article_cache
.splice(i
, 1);
1218 debug("cache_invalidate: id not found: " + id
);
1221 exception_error("cache_invalidate", e
);
1225 function getActiveArticleId() {
1226 return active_post_id
;
1229 function cdmMouseIn(elem
) {
1231 if (elem
.id
&& elem
.id
.match("RROW-")) {
1232 var id
= elem
.id
.replace("RROW-", "");
1233 active_post_id
= id
;
1236 exception_error("cdmMouseIn", e
);
1241 function cdmMouseOut(elem
) {
1242 active_post_id
= false;
1245 function headlines_scroll_handler() {
1248 var e
= document
.getElementById("headlinesInnerContainer");
1250 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1251 if (!_infscroll_disable
) {
1252 debug("more cowbell!");
1258 exception_error("headlines_scroll_handler", e
);
1262 function catchupRelativeToArticle(below
) {
1266 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1267 printLockingError();
1270 if (!getActiveArticleId()) {
1271 alert(__("No article is selected."));
1277 if (document
.getElementById("headlinesList")) {
1278 visible_ids
= getVisibleHeadlineIds();
1280 visible_ids
= cdmGetVisibleArticles();
1283 var ids_to_mark
= new Array();
1286 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1287 if (visible_ids
[i
] != getActiveArticleId()) {
1288 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1290 if (e
&& e
.className
.match("Unread")) {
1291 ids_to_mark
.push(visible_ids
[i
]);
1298 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1299 if (visible_ids
[i
] != getActiveArticleId()) {
1300 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1302 if (e
&& e
.className
.match("Unread")) {
1303 ids_to_mark
.push(visible_ids
[i
]);
1311 if (ids_to_mark
.length
== 0) {
1312 alert(__("No articles found to mark"));
1314 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1318 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1319 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1320 e
.className
= e
.className
.replace("Unread", "");
1323 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1324 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1326 xmlhttp_rpc
.open("GET", query
, true);
1327 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1328 xmlhttp_rpc
.send(null);
1334 exception_error("catchupRelativeToArticle", e
);