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
);
219 var article_is_unread
= crow
.className
.match("Unread");
221 crow
.className
= crow
.className
.replace("Unread", "");
223 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
226 upd_img_pic
.src
= "images/blank_icon.gif";
229 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
233 exception_error("showArticleInHeadlines", e
);
237 function article_callback2(transport
, id
, feed_id
) {
239 debug("article_callback2 " + id
);
241 if (transport
.responseXML
) {
243 active_real_feed_id
= feed_id
;
246 showArticleInHeadlines(id
);
248 var reply
= transport
.responseXML
.firstChild
.firstChild
;
250 var articles
= transport
.responseXML
.getElementsByTagName("article");
252 for (var i
= 0; i
< articles
.length
; i
++) {
253 var a_id
= articles
[i
].getAttribute("id");
255 debug("found id: " + a_id
);
257 if (a_id
== active_post_id
) {
258 debug("active article, rendering...");
259 render_article(articles
[i
].firstChild
.nodeValue
);
262 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
266 debug("article_callback: returned no XML object");
267 var f
= document
.getElementById("content-frame");
268 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
271 var date
= new Date();
272 last_article_view
= date
.getTime() / 1000;
274 if (typeof correctPNG
!= 'undefined') {
278 if (_reload_feedlist_after_view
) {
279 setTimeout('updateFeedList(false, false)', 50);
280 _reload_feedlist_after_view
= false;
282 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
285 debug("parsing piggybacked counters: " + counters
);
286 parse_counters(counters
, false);
288 debug("counters container not found in reply");
294 exception_error("article_callback2", e
);
298 function view(id
, feed_id
, skip_history
) {
301 debug("loading article: " + id
+ "/" + feed_id
);
303 var cached_article
= cache_find(id
);
305 debug("cache check result: " + (cached_article
!= false));
309 //setActiveFeedId(feed_id);
311 var query
= "backend.php?op=view&id=" + param_escape(id
) +
312 "&feed=" + param_escape(feed_id
);
314 var date
= new Date();
316 var neighbor_ids
= getRelativePostIds(active_post_id
);
318 /* only request uncached articles */
320 var cids_to_request
= Array();
322 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
323 if (!cache_check(neighbor_ids
[i
])) {
324 cids_to_request
.push(neighbor_ids
[i
]);
328 debug("additional ids: " + cids_to_request
.toString());
330 /* additional info for piggyback counters */
332 if (tagsAreDisplayed()) {
333 query
= query
+ "&omode=lt";
335 query
= query
+ "&omode=flc";
338 var date
= new Date();
339 var timestamp
= Math
.round(date
.getTime() / 1000);
340 query
= query
+ "&ts=" + timestamp
;
342 query
= query
+ "&cids=" + cids_to_request
.toString();
344 var crow
= document
.getElementById("RROW-" + id
);
345 var article_is_unread
= crow
.className
.match("Unread");
347 showArticleInHeadlines(id
);
349 if (!cached_article
) {
351 notify_progress("Loading, please wait...");
353 } else if (cached_article
&& article_is_unread
) {
355 query
= query
+ "&mode=prefetch";
357 render_article(cached_article
);
359 } else if (cached_article
) {
361 query
= query
+ "&mode=prefetch_old";
362 render_article(cached_article
);
367 new Ajax
.Request(query
, {
368 onComplete: function(transport
) {
369 article_callback2(transport
, id
, feed_id
);
373 exception_error("view", e
);
378 return toggleMark(id
);
382 return togglePub(id
);
385 function tMark_afh_off(effect
) {
387 var elem
= effect
.effects
[0].element
;
389 debug("tMark_afh_off : " + elem
.id
);
392 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
393 elem
.alt
= __("Star article");
398 exception_error("tMark_afh_off", e
);
402 function tPub_afh_off(effect
) {
404 var elem
= effect
.effects
[0].element
;
406 debug("tPub_afh_off : " + elem
.id
);
409 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
410 elem
.alt
= __("Publish article");
415 exception_error("tPub_afh_off", e
);
419 function toggleMark(id
, client_only
, no_effects
) {
423 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
425 query
= query
+ "&afid=" + getActiveFeedId();
427 if (tagsAreDisplayed()) {
428 query
= query
+ "&omode=tl";
430 query
= query
+ "&omode=flc";
433 var mark_img
= document
.getElementById("FMPIC-" + id
);
434 var vfeedu
= document
.getElementById("FEEDU--1");
435 var crow
= document
.getElementById("RROW-" + id
);
437 if (mark_img
.src
.match("mark_unset")) {
438 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
439 mark_img
.alt
= __("Unstar article");
440 query
= query
+ "&mark=1";
442 /* if (vfeedu && crow.className.match("Unread")) {
443 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
447 //mark_img.src = "images/mark_unset.png";
448 mark_img
.alt
= __("Please wait...");
449 query
= query
+ "&mark=0";
451 /* if (vfeedu && crow.className.match("Unread")) {
452 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
455 if (document
.getElementById("headlinesList") && !no_effects
) {
456 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
458 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
459 mark_img
.alt
= __("Star article");
463 /* var vfeedctr = document.getElementById("FEEDCTR--1");
464 var vfeedr = document.getElementById("FEEDR--1");
466 if (vfeedu && vfeedctr) {
467 if ((+vfeedu.innerHTML) > 0) {
468 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
469 vfeedr.className = vfeedr.className + "Unread";
470 vfeedctr.className = "odd";
473 vfeedctr.className = "invisible";
474 vfeedr.className = vfeedr.className.replace("Unread", "");
478 debug("toggle starred for aid " + id);
480 //new Ajax.Request(query); */
485 new Ajax
.Request(query
, {
486 onComplete: function(transport
) {
487 all_counters_callback2(transport
);
493 exception_error("toggleMark", e
);
497 function togglePub(id
, client_only
, no_effects
) {
501 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
503 query
= query
+ "&afid=" + getActiveFeedId();
505 if (tagsAreDisplayed()) {
506 query
= query
+ "&omode=tl";
508 query
= query
+ "&omode=flc";
511 var mark_img
= document
.getElementById("FPPIC-" + id
);
512 var vfeedu
= document
.getElementById("FEEDU--2");
513 var crow
= document
.getElementById("RROW-" + id
);
515 if (mark_img
.src
.match("pub_unset")) {
516 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
517 mark_img
.alt
= __("Unpublish article");
518 query
= query
+ "&pub=1";
520 /* if (vfeedu && crow.className.match("Unread")) {
521 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
525 //mark_img.src = "images/pub_unset.png";
526 mark_img
.alt
= __("Please wait...");
527 query
= query
+ "&pub=0";
529 /* if (vfeedu && crow.className.match("Unread")) {
530 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
533 if (document
.getElementById("headlinesList") && !no_effects
) {
534 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
536 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
537 mark_img
.alt
= __("Publish article");
541 /* var vfeedctr = document.getElementById("FEEDCTR--2");
542 var vfeedr = document.getElementById("FEEDR--2");
544 if (vfeedu && vfeedctr) {
545 if ((+vfeedu.innerHTML) > 0) {
546 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
547 vfeedr.className = vfeedr.className + "Unread";
548 vfeedctr.className = "odd";
551 vfeedctr.className = "invisible";
552 vfeedr.className = vfeedr.className.replace("Unread", "");
556 debug("toggle published for aid " + id);
558 new Ajax.Request(query); */
561 new Ajax
.Request(query
, {
562 onComplete: function(transport
) {
563 all_counters_callback2(transport
);
569 exception_error("togglePub", e
);
573 function correctHeadlinesOffset(id
) {
577 var hlist
= document
.getElementById("headlinesList");
578 var container
= document
.getElementById("headlinesInnerContainer");
579 var row
= document
.getElementById("RROW-" + id
);
581 var viewport
= container
.offsetHeight
;
583 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
584 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
586 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
587 debug("Vport: " + viewport
);
589 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
590 container
.scrollTop
= row
.offsetTop
;
591 } else if (rel_offset_bottom
> viewport
) {
593 /* doesn't properly work with Opera in some cases because
594 Opera fucks up element scrolling */
596 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
600 exception_error("correctHeadlinesOffset", e
);
605 function moveToPost(mode
) {
607 // check for combined mode
608 if (!document
.getElementById("headlinesList"))
611 var rows
= getVisibleHeadlineIds();
616 if (!document
.getElementById('RROW-' + active_post_id
)) {
617 active_post_id
= false;
620 if (active_post_id
== false) {
621 next_id
= getFirstVisibleHeadlineId();
622 prev_id
= getLastVisibleHeadlineId();
624 for (var i
= 0; i
< rows
.length
; i
++) {
625 if (rows
[i
] == active_post_id
) {
632 if (mode
== "next") {
634 correctHeadlinesOffset(next_id
);
635 view(next_id
, getActiveFeedId());
639 if (mode
== "prev") {
641 correctHeadlinesOffset(prev_id
);
642 view(prev_id
, getActiveFeedId());
647 function toggleUnread(id
, cmode
) {
650 var row
= document
.getElementById("RROW-" + id
);
652 var nc
= row
.className
;
653 nc
= nc
.replace("Unread", "");
654 nc
= nc
.replace("Selected", "");
656 if (cmode
== undefined || cmode
== 2) {
657 if (row
.className
.match("Unread")) {
660 row
.className
= nc
+ "Unread";
662 } else if (cmode
== 0) {
664 } else if (cmode
== 1) {
665 row
.className
= nc
+ "Unread";
668 if (cmode
== undefined) cmode
= 2;
670 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
671 param_escape(id
) + "&cmode=" + param_escape(cmode
);
673 // notify_progress("Loading, please wait...");
675 new Ajax
.Request(query
, {
676 onComplete: function(transport
) {
677 all_counters_callback2(transport
);
684 exception_error("toggleUnread", e
);
688 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
693 rows
= cdmGetSelectedArticles();
695 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
698 if (rows
.length
== 0 && !no_error
) {
699 alert(__("No articles are selected."));
703 for (i
= 0; i
< rows
.length
; i
++) {
704 var row
= document
.getElementById("RROW-" + rows
[i
]);
706 var nc
= row
.className
;
707 nc
= nc
.replace("Unread", "");
708 nc
= nc
.replace("Selected", "");
710 if (set_state
== undefined) {
711 if (row
.className
.match("Unread")) {
712 row
.className
= nc
+ "Selected";
714 row
.className
= nc
+ "UnreadSelected";
718 if (set_state
== false) {
719 row
.className
= nc
+ "Selected";
722 if (set_state
== true) {
723 row
.className
= nc
+ "UnreadSelected";
728 if (rows
.length
> 0) {
732 if (set_state
== undefined) {
734 } else if (set_state
== true) {
736 } else if (set_state
== false) {
740 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
741 param_escape(rows
.toString()) + "&cmode=" + cmode
;
743 notify_progress("Loading, please wait...");
745 new Ajax
.Request(query
, {
746 onComplete: function(transport
) {
747 catchup_callback2(transport
, callback_func
);
753 exception_error("selectionToggleUnread", e
);
757 function selectionToggleMarked(cdm_mode
) {
763 rows
= cdmGetSelectedArticles();
765 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
768 if (rows
.length
== 0) {
769 alert(__("No articles are selected."));
773 for (i
= 0; i
< rows
.length
; i
++) {
774 toggleMark(rows
[i
], true, true);
777 if (rows
.length
> 0) {
779 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
780 param_escape(rows
.toString()) + "&cmode=2";
782 query
= query
+ "&afid=" + getActiveFeedId();
784 /* if (tagsAreDisplayed()) {
785 query = query + "&omode=tl";
787 query = query + "&omode=flc";
790 query
= query
+ "&omode=lc";
792 new Ajax
.Request(query
, {
793 onComplete: function(transport
) {
794 all_counters_callback2(transport
);
800 exception_error("selectionToggleMarked", e
);
804 function selectionTogglePublished(cdm_mode
) {
810 rows
= cdmGetSelectedArticles();
812 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
815 if (rows
.length
== 0) {
816 alert(__("No articles are selected."));
820 for (i
= 0; i
< rows
.length
; i
++) {
821 togglePub(rows
[i
], true, true);
824 if (rows
.length
> 0) {
826 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
827 param_escape(rows
.toString()) + "&cmode=2";
829 query
= query
+ "&afid=" + getActiveFeedId();
831 /* if (tagsAreDisplayed()) {
832 query = query + "&omode=tl";
834 query = query + "&omode=flc";
837 query
= query
+ "&omode=lc";
839 new Ajax
.Request(query
, {
840 onComplete: function(transport
) {
841 all_counters_callback2(transport
);
847 exception_error("selectionToggleMarked", e
);
851 function cdmGetSelectedArticles() {
852 var sel_articles
= new Array();
853 var container
= document
.getElementById("headlinesInnerContainer");
855 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
856 var child
= container
.childNodes
[i
];
858 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
859 var c_id
= child
.id
.replace("RROW-", "");
860 sel_articles
.push(c_id
);
867 function cdmGetVisibleArticles() {
868 var sel_articles
= new Array();
869 var container
= document
.getElementById("headlinesInnerContainer");
871 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
872 var child
= container
.childNodes
[i
];
874 if (child
.id
.match("RROW-")) {
875 var c_id
= child
.id
.replace("RROW-", "");
876 sel_articles
.push(c_id
);
883 function cdmGetUnreadArticles() {
884 var sel_articles
= new Array();
885 var container
= document
.getElementById("headlinesInnerContainer");
887 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
888 var child
= container
.childNodes
[i
];
890 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
891 var c_id
= child
.id
.replace("RROW-", "");
892 sel_articles
.push(c_id
);
900 // mode = all,none,unread
901 function cdmSelectArticles(mode
) {
902 var container
= document
.getElementById("headlinesInnerContainer");
904 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
905 var child
= container
.childNodes
[i
];
907 if (child
.id
.match("RROW-")) {
908 var aid
= child
.id
.replace("RROW-", "");
910 var cb
= document
.getElementById("RCHK-" + aid
);
913 if (!child
.className
.match("Selected")) {
914 child
.className
= child
.className
+ "Selected";
917 } else if (mode
== "unread") {
918 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
919 child
.className
= child
.className
+ "Selected";
923 child
.className
= child
.className
.replace("Selected", "");
930 function catchupPage() {
932 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
934 var str
= __("Mark all visible articles in %s as read?");
936 str
= str
.replace("%s", fn
);
938 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
942 if (document
.getElementById("headlinesList")) {
943 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
944 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
945 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
947 cdmSelectArticles('all');
948 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
949 cdmSelectArticles('none');
953 function catchupSelection() {
959 if (document
.getElementById("headlinesList")) {
960 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
962 rows
= cdmGetSelectedArticles();
965 if (rows
.length
== 0) {
966 alert(__("No articles are selected."));
971 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
973 var str
= __("Mark %d selected articles in %s as read?");
975 str
= str
.replace("%d", rows
.length
);
976 str
= str
.replace("%s", fn
);
978 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
982 if (document
.getElementById("headlinesList")) {
983 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
984 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
986 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
987 // cdmSelectArticles('none');
991 exception_error("catchupSelection", e
);
996 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
998 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1002 var title
= prompt(__("Please enter label title:"), "");
1006 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1007 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1008 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1009 "&title=" + param_escape(title
);
1011 debug("LFS: " + query
);
1013 new Ajax
.Request(query
, {
1014 onComplete: function(transport
) {
1015 dlg_frefresh_callback(transport
);
1020 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1021 _tag_active_post_id
= id
;
1022 _tag_active_feed_id
= feed_id
;
1023 _tag_active_cdm
= cdm_enabled
;
1025 cache_invalidate(id
);
1028 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1030 displayDlg('editArticleTags', id
);
1034 function tag_saved_callback(transport
) {
1036 debug("in tag_saved_callback");
1041 if (tagsAreDisplayed()) {
1042 _reload_feedlist_after_view
= true;
1045 if (!_tag_active_cdm
) {
1046 if (active_post_id
== _tag_active_post_id
) {
1047 debug("reloading current article");
1048 view(_tag_active_post_id
, _tag_active_feed_id
);
1051 debug("reloading current feed");
1056 exception_error("catchup_callback", e
);
1060 function editTagsSave() {
1062 notify_progress("Saving article tags...");
1064 var form
= document
.forms
["tag_edit_form"];
1066 var query
= Form
.serialize("tag_edit_form");
1068 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1072 new Ajax
.Request(query
, {
1073 onComplete: function(transport
) {
1074 tag_saved_callback(transport
);
1079 function editTagsInsert() {
1082 var form
= document
.forms
["tag_edit_form"];
1084 var found_tags
= form
.found_tags
;
1085 var tags_str
= form
.tags_str
;
1087 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1089 if (tags_str
.value
.length
> 0 &&
1090 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1092 tags_str
.value
= tags_str
.value
+ ", ";
1095 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1097 found_tags
.selectedIndex
= 0;
1100 exception_error(e
, "editTagsInsert");
1104 function cdmWatchdog() {
1108 var ctr
= document
.getElementById("headlinesInnerContainer");
1112 var ids
= new Array();
1114 var e
= ctr
.firstChild
;
1117 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1118 e
.id
.match("RROW-")) {
1120 // article fits in viewport OR article is longer than viewport and
1121 // its bottom is visible
1123 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1124 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1126 // debug(e.id + " is visible " + e.offsetTop + "." +
1127 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1128 // (ctr.scrollTop + ctr.offsetHeight));
1130 ids
.push(e
.id
.replace("RROW-", ""));
1132 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1133 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1134 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1136 ids
.push(e
.id
.replace("RROW-", ""));
1140 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1142 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1143 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1145 ids.push(e.id.replace("RROW-", ""));
1154 debug("cdmWatchdog, ids= " + ids
.toString());
1156 if (ids
.length
> 0) {
1158 for (var i
= 0; i
< ids
.length
; i
++) {
1159 var e
= document
.getElementById("RROW-" + ids
[i
]);
1161 e
.className
= e
.className
.replace("Unread", "");
1165 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1166 param_escape(ids
.toString()) + "&cmode=0";
1168 new Ajax
.Request(query
, {
1169 onComplete: function(transport
) {
1170 all_counters_callback2(transport
);
1175 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1178 exception_error(e
, "cdmWatchdog");
1184 function cache_inject(id
, article
) {
1185 if (!cache_check(id
)) {
1186 debug("cache_article: miss: " + id
);
1188 var cache_obj
= new Array();
1190 cache_obj
["id"] = id
;
1191 cache_obj
["data"] = article
;
1193 article_cache
.push(cache_obj
);
1196 debug("cache_article: hit: " + id
);
1200 function cache_find(id
) {
1201 for (var i
= 0; i
< article_cache
.length
; i
++) {
1202 if (article_cache
[i
]["id"] == id
) {
1203 return article_cache
[i
]["data"];
1209 function cache_check(id
) {
1210 for (var i
= 0; i
< article_cache
.length
; i
++) {
1211 if (article_cache
[i
]["id"] == id
) {
1218 function cache_expire() {
1219 while (article_cache
.length
> 20) {
1220 article_cache
.shift();
1224 function cache_invalidate(id
) {
1229 while (i
< article_cache
.length
) {
1230 if (article_cache
[i
]["id"] == id
) {
1231 debug("cache_invalidate: removed id " + id
);
1232 article_cache
.splice(i
, 1);
1237 debug("cache_invalidate: id not found: " + id
);
1240 exception_error("cache_invalidate", e
);
1244 function getActiveArticleId() {
1245 return active_post_id
;
1248 function cdmMouseIn(elem
) {
1250 if (elem
.id
&& elem
.id
.match("RROW-")) {
1251 var id
= elem
.id
.replace("RROW-", "");
1252 active_post_id
= id
;
1255 exception_error("cdmMouseIn", e
);
1260 function cdmMouseOut(elem
) {
1261 active_post_id
= false;
1264 function headlines_scroll_handler() {
1267 var e
= document
.getElementById("headlinesInnerContainer");
1269 // don't do infinite scrolling when Limit == All
1271 var toolbar_form
= document
.forms
["main_toolbar_form"];
1273 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1274 if (limit
.value
!= 0) {
1275 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1276 if (!_infscroll_disable
) {
1277 debug("more cowbell!");
1284 exception_error("headlines_scroll_handler", e
);
1288 function catchupRelativeToArticle(below
) {
1292 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1293 printLockingError();
1296 if (!getActiveArticleId()) {
1297 alert(__("No article is selected."));
1303 if (document
.getElementById("headlinesList")) {
1304 visible_ids
= getVisibleHeadlineIds();
1306 visible_ids
= cdmGetVisibleArticles();
1309 var ids_to_mark
= new Array();
1312 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1313 if (visible_ids
[i
] != getActiveArticleId()) {
1314 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1316 if (e
&& e
.className
.match("Unread")) {
1317 ids_to_mark
.push(visible_ids
[i
]);
1324 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1325 if (visible_ids
[i
] != getActiveArticleId()) {
1326 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1328 if (e
&& e
.className
.match("Unread")) {
1329 ids_to_mark
.push(visible_ids
[i
]);
1337 if (ids_to_mark
.length
== 0) {
1338 alert(__("No articles found to mark"));
1340 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1344 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1345 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1346 e
.className
= e
.className
.replace("Unread", "");
1349 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1350 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1352 new Ajax
.Request(query
, {
1353 onComplete: function(transport
) {
1354 catchup_callback2(transport
);
1361 exception_error("catchupRelativeToArticle", e
);
1365 function cdmExpandArticle(a_id
) {
1367 var id
= 'CICD-' + a_id
;
1369 Effect
.Appear(id
, {duration
: 0.5,
1370 beforeStart: function(effect
) {
1371 var h_id
= 'CICH-' + a_id
;
1372 var h_elem
= document
.getElementById(h_id
);
1373 if (h_elem
) { h_elem
.style
.display
= "none"; }
1375 toggleUnread(a_id
, 0);
1380 exception_error("appearBlockElementF", e
);