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
) {
201 cleanSelected("headlinesList");
203 var crow
= document
.getElementById("RROW-" + id
);
204 var article_is_unread
= crow
.className
.match("Unread");
206 crow
.className
= crow
.className
.replace("Unread", "");
208 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
211 upd_img_pic
.src
= "images/blank_icon.gif";
214 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
219 function article_callback2(transport
, id
, feed_id
) {
221 debug("article_callback2 " + id
);
223 if (transport
.responseXML
) {
225 active_real_feed_id
= feed_id
;
228 showArticleInHeadlines(id
);
230 var reply
= transport
.responseXML
.firstChild
.firstChild
;
232 var articles
= transport
.responseXML
.getElementsByTagName("article");
234 for (var i
= 0; i
< articles
.length
; i
++) {
235 var a_id
= articles
[i
].getAttribute("id");
237 debug("found id: " + a_id
);
239 if (a_id
== active_post_id
) {
240 debug("active article, rendering...");
241 render_article(articles
[i
].firstChild
.nodeValue
);
244 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
248 debug("article_callback: returned no XML object");
249 var f
= document
.getElementById("content-frame");
250 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
253 var date
= new Date();
254 last_article_view
= date
.getTime() / 1000;
256 if (typeof correctPNG
!= 'undefined') {
260 if (_reload_feedlist_after_view
) {
261 setTimeout('updateFeedList(false, false)', 50);
262 _reload_feedlist_after_view
= false;
264 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
267 debug("parsing piggybacked counters: " + counters
);
268 parse_counters(counters
, false);
270 debug("counters container not found in reply");
276 exception_error("article_callback2", e
);
280 function view(id
, feed_id
, skip_history
) {
283 debug("loading article: " + id
+ "/" + feed_id
);
285 var cached_article
= cache_find(id
);
287 debug("cache check result: " + (cached_article
!= false));
291 //setActiveFeedId(feed_id);
293 var query
= "backend.php?op=view&id=" + param_escape(id
) +
294 "&feed=" + param_escape(feed_id
);
296 var date
= new Date();
298 /* if (!xmlhttp_ready(xmlhttp) && last_article_view < date.getTime() / 1000 - 15) {
299 debug("<b>xmlhttp seems to be stuck at view, aborting</b>");
302 debug("trying alternative reset method for Safari");
303 xmlhttp = Ajax.getTransport();
307 if (xmlhttp_ready(xmlhttp)) { */
309 var neighbor_ids
= getRelativePostIds(active_post_id
);
311 /* only request uncached articles */
313 var cids_to_request
= Array();
315 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
316 if (!cache_check(neighbor_ids
[i
])) {
317 cids_to_request
.push(neighbor_ids
[i
]);
321 debug("additional ids: " + cids_to_request
.toString());
323 /* additional info for piggyback counters */
325 if (tagsAreDisplayed()) {
326 query
= query
+ "&omode=lt";
328 query
= query
+ "&omode=flc";
331 var date
= new Date();
332 var timestamp
= Math
.round(date
.getTime() / 1000);
333 query
= query
+ "&ts=" + timestamp
;
335 query
= query
+ "&cids=" + cids_to_request
.toString();
337 var crow
= document
.getElementById("RROW-" + id
);
338 var article_is_unread
= crow
.className
.match("Unread");
340 showArticleInHeadlines(id
);
342 if (!cached_article
) {
344 notify_progress("Loading, please wait...");
346 } else if (cached_article
&& article_is_unread
) {
348 query
= query
+ "&mode=prefetch";
350 render_article(cached_article
);
352 } else if (cached_article
) {
354 query
= query
+ "&mode=prefetch_old";
355 render_article(cached_article
);
360 new Ajax
.Request(query
, {
361 onComplete: function(transport
) {
362 article_callback2(transport
, id
, feed_id
);
366 exception_error("view", e
);
371 return toggleMark(id
);
375 return togglePub(id
);
378 function tMark_afh_off(effect
) {
380 var elem
= effect
.effects
[0].element
;
382 debug("tMark_afh_off : " + elem
.id
);
385 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
386 elem
.alt
= __("Star article");
391 exception_error("tMark_afh_off", e
);
395 function tPub_afh_off(effect
) {
397 var elem
= effect
.effects
[0].element
;
399 debug("tPub_afh_off : " + elem
.id
);
402 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
403 elem
.alt
= __("Publish article");
408 exception_error("tPub_afh_off", e
);
412 function toggleMark(id
, client_only
, no_effects
) {
416 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
418 query
= query
+ "&afid=" + getActiveFeedId();
420 if (tagsAreDisplayed()) {
421 query
= query
+ "&omode=tl";
423 query
= query
+ "&omode=flc";
426 var mark_img
= document
.getElementById("FMPIC-" + id
);
427 var vfeedu
= document
.getElementById("FEEDU--1");
428 var crow
= document
.getElementById("RROW-" + id
);
430 if (mark_img
.src
.match("mark_unset")) {
431 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
432 mark_img
.alt
= __("Unstar article");
433 query
= query
+ "&mark=1";
435 /* if (vfeedu && crow.className.match("Unread")) {
436 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
440 //mark_img.src = "images/mark_unset.png";
441 mark_img
.alt
= __("Please wait...");
442 query
= query
+ "&mark=0";
444 /* if (vfeedu && crow.className.match("Unread")) {
445 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
448 if (document
.getElementById("headlinesList") && !no_effects
) {
449 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
451 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
452 mark_img
.alt
= __("Star article");
456 /* var vfeedctr = document.getElementById("FEEDCTR--1");
457 var vfeedr = document.getElementById("FEEDR--1");
459 if (vfeedu && vfeedctr) {
460 if ((+vfeedu.innerHTML) > 0) {
461 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
462 vfeedr.className = vfeedr.className + "Unread";
463 vfeedctr.className = "odd";
466 vfeedctr.className = "invisible";
467 vfeedr.className = vfeedr.className.replace("Unread", "");
471 debug("toggle starred for aid " + id);
473 //new Ajax.Request(query); */
478 new Ajax
.Request(query
, {
479 onComplete: function(transport
) {
480 all_counters_callback2(transport
);
486 exception_error("toggleMark", e
);
490 function togglePub(id
, client_only
, no_effects
) {
494 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
496 query
= query
+ "&afid=" + getActiveFeedId();
498 if (tagsAreDisplayed()) {
499 query
= query
+ "&omode=tl";
501 query
= query
+ "&omode=flc";
504 var mark_img
= document
.getElementById("FPPIC-" + id
);
505 var vfeedu
= document
.getElementById("FEEDU--2");
506 var crow
= document
.getElementById("RROW-" + id
);
508 if (mark_img
.src
.match("pub_unset")) {
509 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
510 mark_img
.alt
= __("Unpublish article");
511 query
= query
+ "&pub=1";
513 /* if (vfeedu && crow.className.match("Unread")) {
514 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
518 //mark_img.src = "images/pub_unset.png";
519 mark_img
.alt
= __("Please wait...");
520 query
= query
+ "&pub=0";
522 /* if (vfeedu && crow.className.match("Unread")) {
523 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
526 if (document
.getElementById("headlinesList") && !no_effects
) {
527 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
529 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
530 mark_img
.alt
= __("Publish article");
534 /* var vfeedctr = document.getElementById("FEEDCTR--2");
535 var vfeedr = document.getElementById("FEEDR--2");
537 if (vfeedu && vfeedctr) {
538 if ((+vfeedu.innerHTML) > 0) {
539 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
540 vfeedr.className = vfeedr.className + "Unread";
541 vfeedctr.className = "odd";
544 vfeedctr.className = "invisible";
545 vfeedr.className = vfeedr.className.replace("Unread", "");
549 debug("toggle published for aid " + id);
551 new Ajax.Request(query); */
554 new Ajax
.Request(query
, {
555 onComplete: function(transport
) {
556 all_counters_callback2(transport
);
562 exception_error("togglePub", e
);
566 function correctHeadlinesOffset(id
) {
570 var hlist
= document
.getElementById("headlinesList");
571 var container
= document
.getElementById("headlinesInnerContainer");
572 var row
= document
.getElementById("RROW-" + id
);
574 var viewport
= container
.offsetHeight
;
576 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
577 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
579 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
580 debug("Vport: " + viewport
);
582 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
583 container
.scrollTop
= row
.offsetTop
;
584 } else if (rel_offset_bottom
> viewport
) {
586 /* doesn't properly work with Opera in some cases because
587 Opera fucks up element scrolling */
589 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
593 exception_error("correctHeadlinesOffset", e
);
598 function moveToPost(mode
) {
600 // check for combined mode
601 if (!document
.getElementById("headlinesList"))
604 var rows
= getVisibleHeadlineIds();
609 if (!document
.getElementById('RROW-' + active_post_id
)) {
610 active_post_id
= false;
613 if (active_post_id
== false) {
614 next_id
= getFirstVisibleHeadlineId();
615 prev_id
= getLastVisibleHeadlineId();
617 for (var i
= 0; i
< rows
.length
; i
++) {
618 if (rows
[i
] == active_post_id
) {
625 if (mode
== "next") {
627 correctHeadlinesOffset(next_id
);
628 view(next_id
, getActiveFeedId());
632 if (mode
== "prev") {
634 correctHeadlinesOffset(prev_id
);
635 view(prev_id
, getActiveFeedId());
640 function toggleUnread(id
, cmode
) {
643 var row
= document
.getElementById("RROW-" + id
);
645 var nc
= row
.className
;
646 nc
= nc
.replace("Unread", "");
647 nc
= nc
.replace("Selected", "");
649 if (row
.className
.match("Unread")) {
652 row
.className
= nc
+ "Unread";
655 if (!cmode
) cmode
= 2;
657 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
658 param_escape(id
) + "&cmode=" + param_escape(cmode
);
660 // notify_progress("Loading, please wait...");
662 new Ajax
.Request(query
, {
663 onComplete: function(transport
) {
664 all_counters_callback2(transport
);
671 exception_error("toggleUnread", e
);
675 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
677 /* if (!xmlhttp_ready(xmlhttp_rpc)) {
685 rows
= cdmGetSelectedArticles();
687 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
690 if (rows
.length
== 0 && !no_error
) {
691 alert(__("No articles are selected."));
695 for (i
= 0; i
< rows
.length
; i
++) {
696 var row
= document
.getElementById("RROW-" + rows
[i
]);
698 var nc
= row
.className
;
699 nc
= nc
.replace("Unread", "");
700 nc
= nc
.replace("Selected", "");
702 if (set_state
== undefined) {
703 if (row
.className
.match("Unread")) {
704 row
.className
= nc
+ "Selected";
706 row
.className
= nc
+ "UnreadSelected";
710 if (set_state
== false) {
711 row
.className
= nc
+ "Selected";
714 if (set_state
== true) {
715 row
.className
= nc
+ "UnreadSelected";
720 if (rows
.length
> 0) {
724 if (set_state
== undefined) {
726 } else if (set_state
== true) {
728 } else if (set_state
== false) {
732 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
733 param_escape(rows
.toString()) + "&cmode=" + cmode
;
735 // _catchup_callback_func = callback_func;
737 debug(callback_func
);
739 notify_progress("Loading, please wait...");
741 /* xmlhttp_rpc.open("GET", query, true);
742 xmlhttp_rpc.onreadystatechange=catchup_callback;
743 xmlhttp_rpc.send(null); */
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 all selected articles in %s as read?");
975 str
= str
.replace("%s", fn
);
977 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
981 if (document
.getElementById("headlinesList")) {
982 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
983 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
985 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
986 // cdmSelectArticles('none');
990 exception_error("catchupSelection", e
);
995 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
997 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1001 var title
= prompt(__("Please enter label title:"), "");
1005 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
1006 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
1007 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
1008 "&title=" + param_escape(title
);
1010 debug("LFS: " + query
);
1012 xmlhttp_rpc
.open("GET", query
, true);
1013 xmlhttp_rpc
.onreadystatechange
=dlg_frefresh_callback
;
1014 xmlhttp_rpc
.send(null);
1019 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1020 _tag_active_post_id
= id
;
1021 _tag_active_feed_id
= feed_id
;
1022 _tag_active_cdm
= cdm_enabled
;
1024 cache_invalidate(id
);
1027 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1029 displayDlg('editArticleTags', id
);
1033 function tag_saved_callback() {
1034 if (xmlhttp_rpc
.readyState
== 4) {
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
);
1061 function editTagsSave() {
1063 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1064 printLockingError();
1067 notify_progress("Saving article tags...");
1069 var form
= document
.forms
["tag_edit_form"];
1071 var query
= Form
.serialize("tag_edit_form");
1073 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1077 xmlhttp_rpc
.open("GET", query
, true);
1078 xmlhttp_rpc
.onreadystatechange
=tag_saved_callback
;
1079 xmlhttp_rpc
.send(null);
1083 function editTagsInsert() {
1086 var form
= document
.forms
["tag_edit_form"];
1088 var found_tags
= form
.found_tags
;
1089 var tags_str
= form
.tags_str
;
1091 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1093 if (tags_str
.value
.length
> 0 &&
1094 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1096 tags_str
.value
= tags_str
.value
+ ", ";
1099 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1101 found_tags
.selectedIndex
= 0;
1104 exception_error(e
, "editTagsInsert");
1108 function cdmWatchdog() {
1112 var ctr
= document
.getElementById("headlinesInnerContainer");
1116 var ids
= new Array();
1118 var e
= ctr
.firstChild
;
1121 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1122 e
.id
.match("RROW-")) {
1124 // article fits in viewport OR article is longer than viewport and
1125 // its bottom is visible
1127 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1128 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1130 // debug(e.id + " is visible " + e.offsetTop + "." +
1131 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1132 // (ctr.scrollTop + ctr.offsetHeight));
1134 ids
.push(e
.id
.replace("RROW-", ""));
1136 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1137 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1138 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1140 ids
.push(e
.id
.replace("RROW-", ""));
1144 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1146 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1147 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1149 ids.push(e.id.replace("RROW-", ""));
1158 debug("cdmWatchdog, ids= " + ids
.toString());
1160 if (ids
.length
> 0) {
1162 for (var i
= 0; i
< ids
.length
; i
++) {
1163 var e
= document
.getElementById("RROW-" + ids
[i
]);
1165 e
.className
= e
.className
.replace("Unread", "");
1169 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1170 param_escape(ids
.toString()) + "&cmode=0";
1172 new Ajax
.Request(query
, {
1173 onComplete: function(transport
) {
1174 all_counters_callback2(transport
);
1179 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1182 exception_error(e
, "cdmWatchdog");
1188 function cache_inject(id
, article
) {
1189 if (!cache_check(id
)) {
1190 debug("cache_article: miss: " + id
);
1192 var cache_obj
= new Array();
1194 cache_obj
["id"] = id
;
1195 cache_obj
["data"] = article
;
1197 article_cache
.push(cache_obj
);
1200 debug("cache_article: hit: " + id
);
1204 function cache_find(id
) {
1205 for (var i
= 0; i
< article_cache
.length
; i
++) {
1206 if (article_cache
[i
]["id"] == id
) {
1207 return article_cache
[i
]["data"];
1213 function cache_check(id
) {
1214 for (var i
= 0; i
< article_cache
.length
; i
++) {
1215 if (article_cache
[i
]["id"] == id
) {
1222 function cache_expire() {
1223 while (article_cache
.length
> 20) {
1224 article_cache
.shift();
1228 function cache_invalidate(id
) {
1233 while (i
< article_cache
.length
) {
1234 if (article_cache
[i
]["id"] == id
) {
1235 debug("cache_invalidate: removed id " + id
);
1236 article_cache
.splice(i
, 1);
1241 debug("cache_invalidate: id not found: " + id
);
1244 exception_error("cache_invalidate", e
);
1248 function getActiveArticleId() {
1249 return active_post_id
;
1252 function cdmMouseIn(elem
) {
1254 if (elem
.id
&& elem
.id
.match("RROW-")) {
1255 var id
= elem
.id
.replace("RROW-", "");
1256 active_post_id
= id
;
1259 exception_error("cdmMouseIn", e
);
1264 function cdmMouseOut(elem
) {
1265 active_post_id
= false;
1268 function headlines_scroll_handler() {
1271 var e
= document
.getElementById("headlinesInnerContainer");
1273 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 300) {
1274 if (!_infscroll_disable
) {
1275 debug("more cowbell!");
1281 exception_error("headlines_scroll_handler", e
);
1285 function catchupRelativeToArticle(below
) {
1289 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1290 printLockingError();
1293 if (!getActiveArticleId()) {
1294 alert(__("No article is selected."));
1300 if (document
.getElementById("headlinesList")) {
1301 visible_ids
= getVisibleHeadlineIds();
1303 visible_ids
= cdmGetVisibleArticles();
1306 var ids_to_mark
= new Array();
1309 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1310 if (visible_ids
[i
] != getActiveArticleId()) {
1311 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1313 if (e
&& e
.className
.match("Unread")) {
1314 ids_to_mark
.push(visible_ids
[i
]);
1321 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1322 if (visible_ids
[i
] != getActiveArticleId()) {
1323 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1325 if (e
&& e
.className
.match("Unread")) {
1326 ids_to_mark
.push(visible_ids
[i
]);
1334 if (ids_to_mark
.length
== 0) {
1335 alert(__("No articles found to mark"));
1337 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1341 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1342 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1343 e
.className
= e
.className
.replace("Unread", "");
1346 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1347 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1349 xmlhttp_rpc
.open("GET", query
, true);
1350 xmlhttp_rpc
.onreadystatechange
=catchup_callback
;
1351 xmlhttp_rpc
.send(null);
1357 exception_error("catchupRelativeToArticle", e
);