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
;
178 _infscroll_request_sent
= 0;
182 exception_error("headlines_callback2", e
);
186 function render_article(article
) {
188 var f
= document
.getElementById("content-frame");
193 f
.innerHTML
= article
;
196 exception_error("render_article", e
);
200 function showArticleInHeadlines(id
) {
204 cleanSelected("headlinesList");
206 var crow
= document
.getElementById("RROW-" + id
);
207 var article_is_unread
= crow
.className
.match("Unread");
209 crow
.className
= crow
.className
.replace("Unread", "");
211 var upd_img_pic
= document
.getElementById("FUPDPIC-" + id
);
214 upd_img_pic
.src
= "images/blank_icon.gif";
217 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
221 exception_error("showArticleInHeadlines", e
);
225 function article_callback2(transport
, id
, feed_id
) {
227 debug("article_callback2 " + id
);
229 if (transport
.responseXML
) {
231 active_real_feed_id
= feed_id
;
234 showArticleInHeadlines(id
);
236 var reply
= transport
.responseXML
.firstChild
.firstChild
;
238 var articles
= transport
.responseXML
.getElementsByTagName("article");
240 for (var i
= 0; i
< articles
.length
; i
++) {
241 var a_id
= articles
[i
].getAttribute("id");
243 debug("found id: " + a_id
);
245 if (a_id
== active_post_id
) {
246 debug("active article, rendering...");
247 render_article(articles
[i
].firstChild
.nodeValue
);
250 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
254 debug("article_callback: returned no XML object");
255 var f
= document
.getElementById("content-frame");
256 f
.innerHTML
= "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
259 var date
= new Date();
260 last_article_view
= date
.getTime() / 1000;
262 if (typeof correctPNG
!= 'undefined') {
266 if (_reload_feedlist_after_view
) {
267 setTimeout('updateFeedList(false, false)', 50);
268 _reload_feedlist_after_view
= false;
270 var counters
= transport
.responseXML
.getElementsByTagName("counters")[0];
273 debug("parsing piggybacked counters: " + counters
);
274 parse_counters(counters
, false);
276 debug("counters container not found in reply");
282 exception_error("article_callback2", e
);
286 function view(id
, feed_id
, skip_history
) {
289 debug("loading article: " + id
+ "/" + feed_id
);
291 var cached_article
= cache_find(id
);
293 debug("cache check result: " + (cached_article
!= false));
297 //setActiveFeedId(feed_id);
299 var query
= "backend.php?op=view&id=" + param_escape(id
) +
300 "&feed=" + param_escape(feed_id
);
302 var date
= new Date();
304 var neighbor_ids
= getRelativePostIds(active_post_id
);
306 /* only request uncached articles */
308 var cids_to_request
= Array();
310 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
311 if (!cache_check(neighbor_ids
[i
])) {
312 cids_to_request
.push(neighbor_ids
[i
]);
316 debug("additional ids: " + cids_to_request
.toString());
318 /* additional info for piggyback counters */
320 if (tagsAreDisplayed()) {
321 query
= query
+ "&omode=lt";
323 query
= query
+ "&omode=flc";
326 var date
= new Date();
327 var timestamp
= Math
.round(date
.getTime() / 1000);
328 query
= query
+ "&ts=" + timestamp
;
330 query
= query
+ "&cids=" + cids_to_request
.toString();
332 var crow
= document
.getElementById("RROW-" + id
);
333 var article_is_unread
= crow
.className
.match("Unread");
335 showArticleInHeadlines(id
);
337 if (!cached_article
) {
339 notify_progress("Loading, please wait...");
341 } else if (cached_article
&& article_is_unread
) {
343 query
= query
+ "&mode=prefetch";
345 render_article(cached_article
);
347 } else if (cached_article
) {
349 query
= query
+ "&mode=prefetch_old";
350 render_article(cached_article
);
355 new Ajax
.Request(query
, {
356 onComplete: function(transport
) {
357 article_callback2(transport
, id
, feed_id
);
361 exception_error("view", e
);
366 return toggleMark(id
);
370 return togglePub(id
);
373 function tMark_afh_off(effect
) {
375 var elem
= effect
.effects
[0].element
;
377 debug("tMark_afh_off : " + elem
.id
);
380 elem
.src
= elem
.src
.replace("mark_set", "mark_unset");
381 elem
.alt
= __("Star article");
386 exception_error("tMark_afh_off", e
);
390 function tPub_afh_off(effect
) {
392 var elem
= effect
.effects
[0].element
;
394 debug("tPub_afh_off : " + elem
.id
);
397 elem
.src
= elem
.src
.replace("pub_set", "pub_unset");
398 elem
.alt
= __("Publish article");
403 exception_error("tPub_afh_off", e
);
407 function toggleMark(id
, client_only
, no_effects
) {
411 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=mark";
413 query
= query
+ "&afid=" + getActiveFeedId();
415 if (tagsAreDisplayed()) {
416 query
= query
+ "&omode=tl";
418 query
= query
+ "&omode=flc";
421 var mark_img
= document
.getElementById("FMPIC-" + id
);
422 var vfeedu
= document
.getElementById("FEEDU--1");
423 var crow
= document
.getElementById("RROW-" + id
);
425 if (mark_img
.src
.match("mark_unset")) {
426 mark_img
.src
= mark_img
.src
.replace("mark_unset", "mark_set");
427 mark_img
.alt
= __("Unstar article");
428 query
= query
+ "&mark=1";
430 /* if (vfeedu && crow.className.match("Unread")) {
431 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
435 //mark_img.src = "images/mark_unset.png";
436 mark_img
.alt
= __("Please wait...");
437 query
= query
+ "&mark=0";
439 /* if (vfeedu && crow.className.match("Unread")) {
440 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
443 if (document
.getElementById("headlinesList") && !no_effects
) {
444 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tMark_afh_off
});
446 mark_img
.src
= mark_img
.src
.replace("mark_set", "mark_unset");
447 mark_img
.alt
= __("Star article");
451 /* var vfeedctr = document.getElementById("FEEDCTR--1");
452 var vfeedr = document.getElementById("FEEDR--1");
454 if (vfeedu && vfeedctr) {
455 if ((+vfeedu.innerHTML) > 0) {
456 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
457 vfeedr.className = vfeedr.className + "Unread";
458 vfeedctr.className = "odd";
461 vfeedctr.className = "invisible";
462 vfeedr.className = vfeedr.className.replace("Unread", "");
466 debug("toggle starred for aid " + id);
468 //new Ajax.Request(query); */
473 new Ajax
.Request(query
, {
474 onComplete: function(transport
) {
475 all_counters_callback2(transport
);
481 exception_error("toggleMark", e
);
485 function togglePub(id
, client_only
, no_effects
) {
489 var query
= "backend.php?op=rpc&id=" + id
+ "&subop=publ";
491 query
= query
+ "&afid=" + getActiveFeedId();
493 if (tagsAreDisplayed()) {
494 query
= query
+ "&omode=tl";
496 query
= query
+ "&omode=flc";
499 var mark_img
= document
.getElementById("FPPIC-" + id
);
500 var vfeedu
= document
.getElementById("FEEDU--2");
501 var crow
= document
.getElementById("RROW-" + id
);
503 if (mark_img
.src
.match("pub_unset")) {
504 mark_img
.src
= mark_img
.src
.replace("pub_unset", "pub_set");
505 mark_img
.alt
= __("Unpublish article");
506 query
= query
+ "&pub=1";
508 /* if (vfeedu && crow.className.match("Unread")) {
509 vfeedu.innerHTML = (+vfeedu.innerHTML) + 1;
513 //mark_img.src = "images/pub_unset.png";
514 mark_img
.alt
= __("Please wait...");
515 query
= query
+ "&pub=0";
517 /* if (vfeedu && crow.className.match("Unread")) {
518 vfeedu.innerHTML = (+vfeedu.innerHTML) - 1;
521 if (document
.getElementById("headlinesList") && !no_effects
) {
522 Effect
.Puff(mark_img
, {duration
: 0.25, afterFinish
: tPub_afh_off
});
524 mark_img
.src
= mark_img
.src
.replace("pub_set", "pub_unset");
525 mark_img
.alt
= __("Publish article");
529 /* var vfeedctr = document.getElementById("FEEDCTR--2");
530 var vfeedr = document.getElementById("FEEDR--2");
532 if (vfeedu && vfeedctr) {
533 if ((+vfeedu.innerHTML) > 0) {
534 if (crow.className.match("Unread") && !vfeedr.className.match("Unread")) {
535 vfeedr.className = vfeedr.className + "Unread";
536 vfeedctr.className = "odd";
539 vfeedctr.className = "invisible";
540 vfeedr.className = vfeedr.className.replace("Unread", "");
544 debug("toggle published for aid " + id);
546 new Ajax.Request(query); */
549 new Ajax
.Request(query
, {
550 onComplete: function(transport
) {
551 all_counters_callback2(transport
);
557 exception_error("togglePub", e
);
561 function correctHeadlinesOffset(id
) {
565 var hlist
= document
.getElementById("headlinesList");
566 var container
= document
.getElementById("headlinesInnerContainer");
567 var row
= document
.getElementById("RROW-" + id
);
569 var viewport
= container
.offsetHeight
;
571 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
572 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
574 debug("Rtop: " + rel_offset_top
+ " Rbtm: " + rel_offset_bottom
);
575 debug("Vport: " + viewport
);
577 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
578 container
.scrollTop
= row
.offsetTop
;
579 } else if (rel_offset_bottom
> viewport
) {
581 /* doesn't properly work with Opera in some cases because
582 Opera fucks up element scrolling */
584 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
588 exception_error("correctHeadlinesOffset", e
);
593 function moveToPost(mode
) {
595 // check for combined mode
596 if (!document
.getElementById("headlinesList"))
599 var rows
= getVisibleHeadlineIds();
604 if (!document
.getElementById('RROW-' + active_post_id
)) {
605 active_post_id
= false;
608 if (active_post_id
== false) {
609 next_id
= getFirstVisibleHeadlineId();
610 prev_id
= getLastVisibleHeadlineId();
612 for (var i
= 0; i
< rows
.length
; i
++) {
613 if (rows
[i
] == active_post_id
) {
620 if (mode
== "next") {
622 correctHeadlinesOffset(next_id
);
623 view(next_id
, getActiveFeedId());
627 if (mode
== "prev") {
629 correctHeadlinesOffset(prev_id
);
630 view(prev_id
, getActiveFeedId());
635 function toggleUnread(id
, cmode
) {
638 var row
= document
.getElementById("RROW-" + id
);
640 var nc
= row
.className
;
641 nc
= nc
.replace("Unread", "");
642 nc
= nc
.replace("Selected", "");
644 if (row
.className
.match("Unread")) {
647 row
.className
= nc
+ "Unread";
650 if (!cmode
) cmode
= 2;
652 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
653 param_escape(id
) + "&cmode=" + param_escape(cmode
);
655 // notify_progress("Loading, please wait...");
657 new Ajax
.Request(query
, {
658 onComplete: function(transport
) {
659 all_counters_callback2(transport
);
666 exception_error("toggleUnread", e
);
670 function selectionToggleUnread(cdm_mode
, set_state
, callback_func
, no_error
) {
675 rows
= cdmGetSelectedArticles();
677 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
680 if (rows
.length
== 0 && !no_error
) {
681 alert(__("No articles are selected."));
685 for (i
= 0; i
< rows
.length
; i
++) {
686 var row
= document
.getElementById("RROW-" + rows
[i
]);
688 var nc
= row
.className
;
689 nc
= nc
.replace("Unread", "");
690 nc
= nc
.replace("Selected", "");
692 if (set_state
== undefined) {
693 if (row
.className
.match("Unread")) {
694 row
.className
= nc
+ "Selected";
696 row
.className
= nc
+ "UnreadSelected";
700 if (set_state
== false) {
701 row
.className
= nc
+ "Selected";
704 if (set_state
== true) {
705 row
.className
= nc
+ "UnreadSelected";
710 if (rows
.length
> 0) {
714 if (set_state
== undefined) {
716 } else if (set_state
== true) {
718 } else if (set_state
== false) {
722 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
723 param_escape(rows
.toString()) + "&cmode=" + cmode
;
725 notify_progress("Loading, please wait...");
727 new Ajax
.Request(query
, {
728 onComplete: function(transport
) {
729 catchup_callback2(transport
, callback_func
);
735 exception_error("selectionToggleUnread", e
);
739 function selectionToggleMarked(cdm_mode
) {
745 rows
= cdmGetSelectedArticles();
747 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
750 if (rows
.length
== 0) {
751 alert(__("No articles are selected."));
755 for (i
= 0; i
< rows
.length
; i
++) {
756 toggleMark(rows
[i
], true, true);
759 if (rows
.length
> 0) {
761 var query
= "backend.php?op=rpc&subop=markSelected&ids=" +
762 param_escape(rows
.toString()) + "&cmode=2";
764 query
= query
+ "&afid=" + getActiveFeedId();
766 /* if (tagsAreDisplayed()) {
767 query = query + "&omode=tl";
769 query = query + "&omode=flc";
772 query
= query
+ "&omode=lc";
774 new Ajax
.Request(query
, {
775 onComplete: function(transport
) {
776 all_counters_callback2(transport
);
782 exception_error("selectionToggleMarked", e
);
786 function selectionTogglePublished(cdm_mode
) {
792 rows
= cdmGetSelectedArticles();
794 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
797 if (rows
.length
== 0) {
798 alert(__("No articles are selected."));
802 for (i
= 0; i
< rows
.length
; i
++) {
803 togglePub(rows
[i
], true, true);
806 if (rows
.length
> 0) {
808 var query
= "backend.php?op=rpc&subop=publishSelected&ids=" +
809 param_escape(rows
.toString()) + "&cmode=2";
811 query
= query
+ "&afid=" + getActiveFeedId();
813 /* if (tagsAreDisplayed()) {
814 query = query + "&omode=tl";
816 query = query + "&omode=flc";
819 query
= query
+ "&omode=lc";
821 new Ajax
.Request(query
, {
822 onComplete: function(transport
) {
823 all_counters_callback2(transport
);
829 exception_error("selectionToggleMarked", e
);
833 function cdmGetSelectedArticles() {
834 var sel_articles
= new Array();
835 var container
= document
.getElementById("headlinesInnerContainer");
837 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
838 var child
= container
.childNodes
[i
];
840 if (child
.id
.match("RROW-") && child
.className
.match("Selected")) {
841 var c_id
= child
.id
.replace("RROW-", "");
842 sel_articles
.push(c_id
);
849 function cdmGetVisibleArticles() {
850 var sel_articles
= new Array();
851 var container
= document
.getElementById("headlinesInnerContainer");
853 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
854 var child
= container
.childNodes
[i
];
856 if (child
.id
.match("RROW-")) {
857 var c_id
= child
.id
.replace("RROW-", "");
858 sel_articles
.push(c_id
);
865 function cdmGetUnreadArticles() {
866 var sel_articles
= new Array();
867 var container
= document
.getElementById("headlinesInnerContainer");
869 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
870 var child
= container
.childNodes
[i
];
872 if (child
.id
.match("RROW-") && child
.className
.match("Unread")) {
873 var c_id
= child
.id
.replace("RROW-", "");
874 sel_articles
.push(c_id
);
882 // mode = all,none,unread
883 function cdmSelectArticles(mode
) {
884 var container
= document
.getElementById("headlinesInnerContainer");
886 for (i
= 0; i
< container
.childNodes
.length
; i
++) {
887 var child
= container
.childNodes
[i
];
889 if (child
.id
.match("RROW-")) {
890 var aid
= child
.id
.replace("RROW-", "");
892 var cb
= document
.getElementById("RCHK-" + aid
);
895 if (!child
.className
.match("Selected")) {
896 child
.className
= child
.className
+ "Selected";
899 } else if (mode
== "unread") {
900 if (child
.className
.match("Unread") && !child
.className
.match("Selected")) {
901 child
.className
= child
.className
+ "Selected";
905 child
.className
= child
.className
.replace("Selected", "");
912 function catchupPage() {
914 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
916 var str
= __("Mark all visible articles in %s as read?");
918 str
= str
.replace("%s", fn
);
920 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
924 if (document
.getElementById("headlinesList")) {
925 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
926 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
927 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
929 cdmSelectArticles('all');
930 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
931 cdmSelectArticles('none');
935 function catchupSelection() {
941 if (document
.getElementById("headlinesList")) {
942 rows
= getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
944 rows
= cdmGetSelectedArticles();
947 if (rows
.length
== 0) {
948 alert(__("No articles are selected."));
953 var fn
= getFeedName(getActiveFeedId(), active_feed_is_cat
);
955 var str
= __("Mark %d selected articles in %s as read?");
957 str
= str
.replace("%d", rows
.length
);
958 str
= str
.replace("%s", fn
);
960 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
964 if (document
.getElementById("headlinesList")) {
965 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
966 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
968 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
969 // cdmSelectArticles('none');
973 exception_error("catchupSelection", e
);
978 function labelFromSearch(search
, search_mode
, match_on
, feed_id
, is_cat
) {
980 if (!xmlhttp_ready(xmlhttp_rpc
)) {
984 var title
= prompt(__("Please enter label title:"), "");
988 var query
= "backend.php?op=labelFromSearch&search=" + param_escape(search
) +
989 "&smode=" + param_escape(search_mode
) + "&match=" + param_escape(match_on
) +
990 "&feed=" + param_escape(feed_id
) + "&is_cat=" + param_escape(is_cat
) +
991 "&title=" + param_escape(title
);
993 debug("LFS: " + query
);
995 new Ajax
.Request(query
, {
996 onComplete: function(transport
) {
997 dlg_frefresh_callback(transport
);
1002 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1003 _tag_active_post_id
= id
;
1004 _tag_active_feed_id
= feed_id
;
1005 _tag_active_cdm
= cdm_enabled
;
1007 cache_invalidate(id
);
1010 _tag_cdm_scroll
= document
.getElementById("headlinesInnerContainer").scrollTop
;
1012 displayDlg('editArticleTags', id
);
1016 function tag_saved_callback(transport
) {
1018 debug("in tag_saved_callback");
1023 if (tagsAreDisplayed()) {
1024 _reload_feedlist_after_view
= true;
1027 if (!_tag_active_cdm
) {
1028 if (active_post_id
== _tag_active_post_id
) {
1029 debug("reloading current article");
1030 view(_tag_active_post_id
, _tag_active_feed_id
);
1033 debug("reloading current feed");
1038 exception_error("catchup_callback", e
);
1042 function editTagsSave() {
1044 notify_progress("Saving article tags...");
1046 var form
= document
.forms
["tag_edit_form"];
1048 var query
= Form
.serialize("tag_edit_form");
1050 query
= "backend.php?op=rpc&subop=setArticleTags&" + query
;
1054 new Ajax
.Request(query
, {
1055 onComplete: function(transport
) {
1056 tag_saved_callback(transport
);
1061 function editTagsInsert() {
1064 var form
= document
.forms
["tag_edit_form"];
1066 var found_tags
= form
.found_tags
;
1067 var tags_str
= form
.tags_str
;
1069 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1071 if (tags_str
.value
.length
> 0 &&
1072 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1074 tags_str
.value
= tags_str
.value
+ ", ";
1077 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1079 found_tags
.selectedIndex
= 0;
1082 exception_error(e
, "editTagsInsert");
1086 function cdmWatchdog() {
1090 var ctr
= document
.getElementById("headlinesInnerContainer");
1094 var ids
= new Array();
1096 var e
= ctr
.firstChild
;
1099 if (e
.className
&& e
.className
== "cdmArticleUnread" && e
.id
&&
1100 e
.id
.match("RROW-")) {
1102 // article fits in viewport OR article is longer than viewport and
1103 // its bottom is visible
1105 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1106 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1108 // debug(e.id + " is visible " + e.offsetTop + "." +
1109 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1110 // (ctr.scrollTop + ctr.offsetHeight));
1112 ids
.push(e
.id
.replace("RROW-", ""));
1114 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1115 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1116 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1118 ids
.push(e
.id
.replace("RROW-", ""));
1122 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1124 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1125 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1127 ids.push(e.id.replace("RROW-", ""));
1136 debug("cdmWatchdog, ids= " + ids
.toString());
1138 if (ids
.length
> 0) {
1140 for (var i
= 0; i
< ids
.length
; i
++) {
1141 var e
= document
.getElementById("RROW-" + ids
[i
]);
1143 e
.className
= e
.className
.replace("Unread", "");
1147 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1148 param_escape(ids
.toString()) + "&cmode=0";
1150 new Ajax
.Request(query
, {
1151 onComplete: function(transport
) {
1152 all_counters_callback2(transport
);
1157 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1160 exception_error(e
, "cdmWatchdog");
1166 function cache_inject(id
, article
) {
1167 if (!cache_check(id
)) {
1168 debug("cache_article: miss: " + id
);
1170 var cache_obj
= new Array();
1172 cache_obj
["id"] = id
;
1173 cache_obj
["data"] = article
;
1175 article_cache
.push(cache_obj
);
1178 debug("cache_article: hit: " + id
);
1182 function cache_find(id
) {
1183 for (var i
= 0; i
< article_cache
.length
; i
++) {
1184 if (article_cache
[i
]["id"] == id
) {
1185 return article_cache
[i
]["data"];
1191 function cache_check(id
) {
1192 for (var i
= 0; i
< article_cache
.length
; i
++) {
1193 if (article_cache
[i
]["id"] == id
) {
1200 function cache_expire() {
1201 while (article_cache
.length
> 20) {
1202 article_cache
.shift();
1206 function cache_invalidate(id
) {
1211 while (i
< article_cache
.length
) {
1212 if (article_cache
[i
]["id"] == id
) {
1213 debug("cache_invalidate: removed id " + id
);
1214 article_cache
.splice(i
, 1);
1219 debug("cache_invalidate: id not found: " + id
);
1222 exception_error("cache_invalidate", e
);
1226 function getActiveArticleId() {
1227 return active_post_id
;
1230 function cdmMouseIn(elem
) {
1232 if (elem
.id
&& elem
.id
.match("RROW-")) {
1233 var id
= elem
.id
.replace("RROW-", "");
1234 active_post_id
= id
;
1237 exception_error("cdmMouseIn", e
);
1242 function cdmMouseOut(elem
) {
1243 active_post_id
= false;
1246 function headlines_scroll_handler() {
1249 var e
= document
.getElementById("headlinesInnerContainer");
1251 // don't do infinite scrolling when Limit == All
1253 var toolbar_form
= document
.forms
["main_toolbar_form"];
1255 var limit
= toolbar_form
.limit
[toolbar_form
.limit
.selectedIndex
];
1256 if (limit
.value
!= 0) {
1257 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 50) {
1258 if (!_infscroll_disable
) {
1259 debug("more cowbell!");
1266 exception_error("headlines_scroll_handler", e
);
1270 function catchupRelativeToArticle(below
) {
1274 if (!xmlhttp_ready(xmlhttp_rpc
)) {
1275 printLockingError();
1278 if (!getActiveArticleId()) {
1279 alert(__("No article is selected."));
1285 if (document
.getElementById("headlinesList")) {
1286 visible_ids
= getVisibleHeadlineIds();
1288 visible_ids
= cdmGetVisibleArticles();
1291 var ids_to_mark
= new Array();
1294 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1295 if (visible_ids
[i
] != getActiveArticleId()) {
1296 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1298 if (e
&& e
.className
.match("Unread")) {
1299 ids_to_mark
.push(visible_ids
[i
]);
1306 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1307 if (visible_ids
[i
] != getActiveArticleId()) {
1308 var e
= document
.getElementById("RROW-" + visible_ids
[i
]);
1310 if (e
&& e
.className
.match("Unread")) {
1311 ids_to_mark
.push(visible_ids
[i
]);
1319 if (ids_to_mark
.length
== 0) {
1320 alert(__("No articles found to mark"));
1322 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1326 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1327 var e
= document
.getElementById("RROW-" + ids_to_mark
[i
]);
1328 e
.className
= e
.className
.replace("Unread", "");
1331 var query
= "backend.php?op=rpc&subop=catchupSelected&ids=" +
1332 param_escape(ids_to_mark
.toString()) + "&cmode=0";
1334 new Ajax
.Request(query
, {
1335 onComplete: function(transport
) {
1336 catchup_callback2(transport
);
1343 exception_error("catchupRelativeToArticle", e
);