]>
git.wh0rd.org - tt-rss.git/blob - js/viewfeed.js
1 var active_post_id
= false;
3 var article_cache
= new Array();
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
12 var feed_precache_timeout_id
= false;
13 var precache_idle_timeout_id
= false;
15 var cids_requested
= [];
17 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
19 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
21 handle_rpc_json(transport
);
23 loading_set_progress(25);
25 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
33 reply
= JSON
.parse(transport
.responseText
);
40 is_cat
= reply
['headlines']['is_cat'];
41 feed_id
= reply
['headlines']['id'];
44 var content
= reply
['headlines']['content'];
46 if (getInitParam("cdm_auto_catchup") == 1) {
47 content
= content
+ "<div id='headlines-spacer'></div>";
50 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], content
);
54 setActiveFeedId(feed_id
, is_cat
);
56 dijit
.getEnclosingWidget(
57 document
.forms
["main_toolbar_form"].update
).attr('disabled',
58 is_cat
|| feed_id
<= 0);
61 if (offset
== 0 && infscroll_req
== false) {
62 $("headlines-frame").scrollTop
= 0;
66 var headlines_count
= reply
['headlines-info']['count'];
68 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
70 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
71 _infscroll_disable
= 1;
73 _infscroll_disable
= 0;
76 var counters
= reply
['counters'];
77 var articles
= reply
['articles'];
78 //var runtime_info = reply['runtime-info'];
80 if (offset
== 0 && infscroll_req
== false) {
81 dijit
.byId("headlines-frame").attr('content',
82 reply
['headlines']['content']);
84 dijit
.byId("headlines-toolbar").attr('content',
85 reply
['headlines']['toolbar']);
87 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
88 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
> 1) {
89 row
.parentNode
.removeChild(row
);
93 if (getInitParam("cdm_auto_catchup") == 1) {
94 var hsp
= $("headlines-spacer");
95 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
96 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
103 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
104 console
.log("adding some more headlines: " + headlines_count
);
106 var c
= dijit
.byId("headlines-frame");
107 var ids
= getSelectedArticleIds2();
110 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
112 var hsp
= $("headlines-spacer");
115 c
.domNode
.removeChild(hsp
);
117 $$("#headlines-tmp > div").each(function(row
) {
118 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
119 row
.style
.display
= 'none';
120 c
.domNode
.appendChild(row
);
123 row
.parentNode
.removeChild(row
);
127 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
129 fixHeadlinesOrder(getLoadedArticleIds());
131 if (getInitParam("cdm_auto_catchup") == 1) {
132 c
.domNode
.appendChild(hsp
);
135 console
.log("added " + num_added
+ " headlines");
138 _infscroll_disable
= true;
140 console
.log("restore selected ids: " + ids
);
142 for (var i
= 0; i
< ids
.length
; i
++) {
143 markHeadline(ids
[i
]);
148 $$("#headlines-frame > div[id*=RROW]").each(
150 if (!Element
.visible(child
))
151 new Effect
.Appear(child
, { duration
: 0.5 });
155 console
.log("no new headlines received");
157 var hsp
= $("headlines-spacer");
159 if (hsp
) hsp
.innerHTML
= "";
163 if (headlines_count
> 0)
164 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
167 for (var i
= 0; i
< articles
.length
; i
++) {
168 var a_id
= articles
[i
]['id'];
169 cache_set("article:" + a_id
, articles
[i
]['content']);
172 console
.log("no cached articles received");
175 // do not precache stuff after fresh feed
177 precache_headlines();
180 parse_counters(counters
);
185 console
.error("Invalid object received: " + transport
.responseText
);
186 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
187 __('Could not update headlines (invalid object received - see error console for details)') +
191 _infscroll_request_sent
= 0;
196 exception_error("headlines_callback2", e
, transport
);
200 function render_article(article
) {
202 dijit
.byId("headlines-wrap-inner").addChild(
203 dijit
.byId("content-insert"));
205 var c
= dijit
.byId("content-insert");
208 c
.domNode
.scrollTop
= 0;
211 c
.attr('content', article
);
213 correctHeadlinesOffset(getActiveArticleId());
220 exception_error("render_article", e
);
224 function showArticleInHeadlines(id
) {
228 selectArticles("none");
230 var crow
= $("RROW-" + id
);
234 var article_is_unread
= crow
.hasClassName("Unread");
236 crow
.removeClassName("Unread");
238 selectArticles('none');
240 var upd_img_pic
= $("FUPDPIC-" + id
);
242 var view_mode
= false;
245 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
246 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
251 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
252 upd_img_pic
.src
.match("fresh_sign.png"))) {
254 upd_img_pic
.src
= "images/blank_icon.gif";
256 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
258 } else if (article_is_unread
&& view_mode
== "all_articles") {
259 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
264 if (article_is_unread
)
265 _force_scheduled_update
= true;
268 exception_error("showArticleInHeadlines", e
);
272 function article_callback2(transport
, id
) {
274 console
.log("article_callback2 " + id
);
276 handle_rpc_json(transport
);
281 reply
= JSON
.parse(transport
.responseText
);
288 var upic
= $('FUPDPIC-' + id
);
290 if (upic
) upic
.src
= 'images/blank_icon.gif';
292 reply
.each(function(article
) {
293 if (active_post_id
== article
['id']) {
294 render_article(article
['content']);
296 cids_requested
.remove(article
['id']);
298 cache_set("article:" + article
['id'], article
['content']);
301 // if (id != last_requested_article) {
302 // console.log("requested article id is out of sequence, aborting");
307 console
.error("Invalid object received: " + transport
.responseText
);
309 render_article("<div class='whiteBox'>" +
310 __('Could not display article (invalid object received - see error console for details)') + "</div>");
315 headlines_scroll_handler($("headlines-frame"));
318 if (!_infscroll_disable &&
319 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
329 exception_error("article_callback2", e
, transport
);
335 console
.log("loading article: " + id
);
337 var cached_article
= cache_get("article:" + id
);
339 console
.log("cache check result: " + (cached_article
!= false));
343 var query
= "?op=article&method=view&id=" + param_escape(id
);
345 var neighbor_ids
= getRelativePostIds(id
);
347 /* only request uncached articles */
349 var cids_to_request
= [];
351 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
352 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
353 if (!cache_get("article:" + neighbor_ids
[i
])) {
354 cids_to_request
.push(neighbor_ids
[i
]);
355 cids_requested
.push(neighbor_ids
[i
]);
359 console
.log("additional ids: " + cids_to_request
.toString());
361 query
= query
+ "&cids=" + cids_to_request
.toString();
363 var crow
= $("RROW-" + id
);
364 var article_is_unread
= crow
.hasClassName("Unread");
367 showArticleInHeadlines(id
);
369 precache_headlines();
371 if (!cached_article
) {
373 var upic
= $('FUPDPIC-' + id
);
376 upic
.src
= getInitParam("sign_progress");
379 } else if (cached_article
&& article_is_unread
) {
381 query
= query
+ "&mode=prefetch";
383 render_article(cached_article
);
385 } else if (cached_article
) {
387 query
= query
+ "&mode=prefetch_old";
388 render_article(cached_article
);
390 // if we don't need to request any relative ids, we might as well skip
391 // the server roundtrip altogether
392 if (cids_to_request
.length
== 0) {
395 if (!_infscroll_disable &&
396 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
404 headlines_scroll_handler($("headlines-frame"));
410 last_requested_article
= id
;
414 if (article_is_unread
) {
415 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
418 new Ajax
.Request("backend.php", {
420 onComplete: function(transport
) {
421 article_callback2(transport
, id
);
427 exception_error("view", e
);
431 function toggleMark(id
, client_only
) {
433 var query
= "?op=rpc&id=" + id
+ "&method=mark";
435 var img
= $("FMPIC-" + id
);
439 if (img
.src
.match("mark_unset")) {
440 img
.src
= img
.src
.replace("mark_unset", "mark_set");
441 img
.alt
= __("Unstar article");
442 query
= query
+ "&mark=1";
445 img
.src
= img
.src
.replace("mark_set", "mark_unset");
446 img
.alt
= __("Star article");
447 query
= query
+ "&mark=0";
450 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
453 new Ajax
.Request("backend.php", {
455 onComplete: function(transport
) {
456 handle_rpc_json(transport
);
461 exception_error("toggleMark", e
);
465 function togglePub(id
, client_only
, no_effects
, note
) {
467 var query
= "?op=rpc&id=" + id
+ "&method=publ";
469 if (note
!= undefined) {
470 query
= query
+ "¬e=" + param_escape(note
);
472 query
= query
+ "¬e=undefined";
475 var img
= $("FPPIC-" + id
);
479 if (img
.src
.match("pub_unset") || note
!= undefined) {
480 img
.src
= img
.src
.replace("pub_unset", "pub_set");
481 img
.alt
= __("Unpublish article");
482 query
= query
+ "&pub=1";
485 img
.src
= img
.src
.replace("pub_set", "pub_unset");
486 img
.alt
= __("Publish article");
488 query
= query
+ "&pub=0";
491 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
494 new Ajax
.Request("backend.php", {
496 onComplete: function(transport
) {
497 handle_rpc_json(transport
);
502 exception_error("togglePub", e
);
506 function moveToPost(mode
) {
510 var rows
= getVisibleArticleIds();
515 if (!$('RROW-' + active_post_id
)) {
516 active_post_id
= false;
519 if (active_post_id
== false) {
521 prev_id
= rows
[rows
.length
-1]
523 for (var i
= 0; i
< rows
.length
; i
++) {
524 if (rows
[i
] == active_post_id
) {
526 // Account for adjacent identical article ids.
527 if (i
> 0) prev_id
= rows
[i
-1];
529 for (var j
= i
+1; j
< rows
.length
; j
++) {
530 if (rows
[j
] != active_post_id
) {
540 if (mode
== "next") {
544 cdmExpandArticle(next_id
);
545 cdmScrollToArticleId(next_id
);
548 correctHeadlinesOffset(next_id
);
549 view(next_id
, getActiveFeedId());
554 if (mode
== "prev") {
557 cdmExpandArticle(prev_id
);
558 cdmScrollToArticleId(prev_id
);
560 correctHeadlinesOffset(prev_id
);
561 view(prev_id
, getActiveFeedId());
567 exception_error("moveToPost", e
);
571 function toggleSelected(id
, force_on
) {
574 var cb
= $("RCHK-" + id
);
575 var row
= $("RROW-" + id
);
578 if (row
.hasClassName('Selected') && !force_on
) {
579 row
.removeClassName('Selected');
580 if (cb
) cb
.checked
= false;
582 row
.addClassName('Selected');
583 if (cb
) cb
.checked
= true;
587 exception_error("toggleSelected", e
);
591 function toggleUnread_afh(effect
) {
594 var elem
= effect
.element
;
595 elem
.style
.backgroundColor
= "";
598 exception_error("toggleUnread_afh", e
);
602 function toggleUnread(id
, cmode
, effect
) {
605 var row
= $("RROW-" + id
);
607 if (cmode
== undefined || cmode
== 2) {
608 if (row
.hasClassName("Unread")) {
609 row
.removeClassName("Unread");
612 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
613 afterFinish
: toggleUnread_afh
,
614 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
618 row
.addClassName("Unread");
621 } else if (cmode
== 0) {
623 row
.removeClassName("Unread");
626 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
627 afterFinish
: toggleUnread_afh
,
628 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
631 } else if (cmode
== 1) {
632 row
.addClassName("Unread");
635 if (cmode
== undefined) cmode
= 2;
637 var query
= "?op=rpc&method=catchupSelected" +
638 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
640 // notify_progress("Loading, please wait...");
642 new Ajax
.Request("backend.php", {
644 onComplete: function(transport
) {
645 handle_rpc_json(transport
);
651 exception_error("toggleUnread", e
);
655 function selectionRemoveLabel(id
, ids
) {
658 if (!ids
) ids
= getSelectedArticleIds2();
660 if (ids
.length
== 0) {
661 alert(__("No articles are selected."));
665 var query
= "?op=rpc&method=removeFromLabel&ids=" +
666 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
670 new Ajax
.Request("backend.php", {
672 onComplete: function(transport
) {
673 handle_rpc_json(transport
);
674 show_labels_in_headlines(transport
);
678 exception_error("selectionAssignLabel", e
);
683 function selectionAssignLabel(id
, ids
) {
686 if (!ids
) ids
= getSelectedArticleIds2();
688 if (ids
.length
== 0) {
689 alert(__("No articles are selected."));
693 var query
= "?op=rpc&method=assignToLabel&ids=" +
694 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
698 new Ajax
.Request("backend.php", {
700 onComplete: function(transport
) {
701 handle_rpc_json(transport
);
702 show_labels_in_headlines(transport
);
706 exception_error("selectionAssignLabel", e
);
711 function selectionToggleUnread(set_state
, callback
, no_error
) {
713 var rows
= getSelectedArticleIds2();
715 if (rows
.length
== 0 && !no_error
) {
716 alert(__("No articles are selected."));
720 for (var i
= 0; i
< rows
.length
; i
++) {
721 var row
= $("RROW-" + rows
[i
]);
723 if (set_state
== undefined) {
724 if (row
.hasClassName("Unread")) {
725 row
.removeClassName("Unread");
727 row
.addClassName("Unread");
731 if (set_state
== false) {
732 row
.removeClassName("Unread");
735 if (set_state
== true) {
736 row
.addClassName("Unread");
741 if (rows
.length
> 0) {
745 if (set_state
== undefined) {
747 } else if (set_state
== true) {
749 } else if (set_state
== false) {
753 var query
= "?op=rpc&method=catchupSelected" +
754 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
756 notify_progress("Loading, please wait...");
758 new Ajax
.Request("backend.php", {
760 onComplete: function(transport
) {
761 handle_rpc_json(transport
);
762 if (callback
) callback(transport
);
768 exception_error("selectionToggleUnread", e
);
772 function selectionToggleMarked() {
775 var rows
= getSelectedArticleIds2();
777 if (rows
.length
== 0) {
778 alert(__("No articles are selected."));
782 for (var i
= 0; i
< rows
.length
; i
++) {
783 toggleMark(rows
[i
], true, true);
786 if (rows
.length
> 0) {
788 var query
= "?op=rpc&method=markSelected&ids=" +
789 param_escape(rows
.toString()) + "&cmode=2";
791 new Ajax
.Request("backend.php", {
793 onComplete: function(transport
) {
794 handle_rpc_json(transport
);
800 exception_error("selectionToggleMarked", e
);
804 function selectionTogglePublished() {
807 var rows
= getSelectedArticleIds2();
809 if (rows
.length
== 0) {
810 alert(__("No articles are selected."));
814 for (var i
= 0; i
< rows
.length
; i
++) {
815 togglePub(rows
[i
], true, true);
818 if (rows
.length
> 0) {
820 var query
= "?op=rpc&method=publishSelected&ids=" +
821 param_escape(rows
.toString()) + "&cmode=2";
823 new Ajax
.Request("backend.php", {
825 onComplete: function(transport
) {
826 handle_rpc_json(transport
);
832 exception_error("selectionToggleMarked", e
);
836 function getSelectedArticleIds2() {
840 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
842 rv
.push(child
.id
.replace("RROW-", ""));
848 function getLoadedArticleIds() {
851 var children
= $$("#headlines-frame > div[id*=RROW-]");
853 children
.each(function(child
) {
854 rv
.push(child
.id
.replace("RROW-", ""));
861 // mode = all,none,unread,invert,marked,published
862 function selectArticles(mode
) {
865 var children
= $$("#headlines-frame > div[id*=RROW]");
867 children
.each(function(child
) {
868 var id
= child
.id
.replace("RROW-", "");
869 var cb
= $("RCHK-" + id
);
872 child
.addClassName("Selected");
874 } else if (mode
== "unread") {
875 if (child
.hasClassName("Unread")) {
876 child
.addClassName("Selected");
879 child
.removeClassName("Selected");
882 } else if (mode
== "marked") {
883 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
885 if (img
&& img
.src
.match("mark_set")) {
886 child
.addClassName("Selected");
889 child
.removeClassName("Selected");
892 } else if (mode
== "published") {
893 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
895 if (img
&& img
.src
.match("pub_set")) {
896 child
.addClassName("Selected");
899 child
.removeClassName("Selected");
903 } else if (mode
== "invert") {
904 if (child
.hasClassName("Selected")) {
905 child
.removeClassName("Selected");
908 child
.addClassName("Selected");
913 child
.removeClassName("Selected");
919 exception_error("selectArticles", e
);
923 function catchupPage() {
925 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
927 var str
= __("Mark all visible articles in %s as read?");
929 str
= str
.replace("%s", fn
);
931 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
935 selectArticles('all');
936 selectionToggleUnread(false, 'viewCurrentFeed()', true);
937 selectArticles('none');
940 function deleteSelection() {
944 var rows
= getSelectedArticleIds2();
946 if (rows
.length
== 0) {
947 alert(__("No articles are selected."));
951 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
954 if (getActiveFeedId() != 0) {
955 str
= __("Delete %d selected articles in %s?");
957 str
= __("Delete %d selected articles?");
960 str
= str
.replace("%d", rows
.length
);
961 str
= str
.replace("%s", fn
);
963 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
967 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
971 new Ajax
.Request("backend.php", {
973 onComplete: function(transport
) {
974 handle_rpc_json(transport
);
979 exception_error("deleteSelection", e
);
983 function archiveSelection() {
987 var rows
= getSelectedArticleIds2();
989 if (rows
.length
== 0) {
990 alert(__("No articles are selected."));
994 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
998 if (getActiveFeedId() != 0) {
999 str
= __("Archive %d selected articles in %s?");
1002 str
= __("Move %d archived articles back?");
1006 str
= str
.replace("%d", rows
.length
);
1007 str
= str
.replace("%s", fn
);
1009 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1013 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1017 for (var i
= 0; i
< rows
.length
; i
++) {
1018 cache_delete("article:" + rows
[i
]);
1021 new Ajax
.Request("backend.php", {
1023 onComplete: function(transport
) {
1024 handle_rpc_json(transport
);
1029 exception_error("archiveSelection", e
);
1033 function catchupSelection() {
1037 var rows
= getSelectedArticleIds2();
1039 if (rows
.length
== 0) {
1040 alert(__("No articles are selected."));
1044 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1046 var str
= __("Mark %d selected articles in %s as read?");
1048 str
= str
.replace("%d", rows
.length
);
1049 str
= str
.replace("%s", fn
);
1051 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1055 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1058 exception_error("catchupSelection", e
);
1062 function editArticleTags(id
) {
1063 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1065 if (dijit
.byId("editTagsDlg"))
1066 dijit
.byId("editTagsDlg").destroyRecursive();
1068 dialog
= new dijit
.Dialog({
1070 title
: __("Edit article Tags"),
1071 style
: "width: 600px",
1072 execute: function() {
1073 if (this.validate()) {
1074 var query
= dojo
.objectToQuery(this.attr('value'));
1076 notify_progress("Saving article tags...", true);
1078 new Ajax
.Request("backend.php", {
1080 onComplete: function(transport
) {
1084 var data
= JSON
.parse(transport
.responseText
);
1087 var tags_str
= article
.tags
;
1088 var id
= tags_str
.id
;
1090 var tags
= $("ATSTR-" + id
);
1091 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1093 if (tags
) tags
.innerHTML
= tags_str
.content
;
1094 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1096 cache_delete("article:" + id
);
1105 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1106 dojo
.disconnect(tmph
);
1108 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1109 "backend.php?op=rpc&method=completeTags",
1110 { tokens
: ',', paramName
: "search" });
1117 function cdmScrollToArticleId(id
) {
1119 var ctr
= $("headlines-frame");
1120 var e
= $("RROW-" + id
);
1122 if (!e
|| !ctr
) return;
1124 ctr
.scrollTop
= e
.offsetTop
;
1127 exception_error("cdmScrollToArticleId", e
);
1131 function getActiveArticleId() {
1132 return active_post_id
;
1135 function postMouseIn(id
) {
1136 post_under_pointer
= id
;
1139 function postMouseOut(id
) {
1140 post_under_pointer
= false;
1143 function headlines_scroll_handler(e
) {
1145 var hsp
= $("headlines-spacer");
1147 if (!_infscroll_disable
) {
1148 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1149 (e
.scrollHeight
!= 0 &&
1150 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1153 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1154 __("Loading, please wait...");
1156 loadMoreHeadlines();
1161 if (hsp
) hsp
.innerHTML
= "";
1164 if (getInitParam("cdm_auto_catchup") == 1) {
1166 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1168 if ($("headlines-frame").scrollTop
>
1169 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1171 var id
= child
.id
.replace("RROW-", "");
1173 if (catchup_id_batch
.indexOf(id
) == -1)
1174 catchup_id_batch
.push(id
);
1176 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1180 if (catchup_id_batch
.length
> 0) {
1181 window
.clearTimeout(catchup_timeout_id
);
1183 if (!_infscroll_request_sent
) {
1184 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1191 console
.warn("headlines_scroll_handler: " + e
);
1195 function catchupBatchedArticles() {
1197 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1199 // make a copy of the array
1200 var batch
= catchup_id_batch
.slice();
1201 var query
= "?op=rpc&method=catchupSelected" +
1202 "&cmode=0&ids=" + param_escape(batch
.toString());
1206 new Ajax
.Request("backend.php", {
1208 onComplete: function(transport
) {
1209 handle_rpc_json(transport
);
1211 batch
.each(function(id
) {
1212 var elem
= $("RROW-" + id
);
1213 if (elem
) elem
.removeClassName("Unread");
1214 catchup_id_batch
.remove(id
);
1221 exception_error("catchupBatchedArticles", e
);
1225 function catchupRelativeToArticle(below
, id
) {
1229 if (!id
) id
= getActiveArticleId();
1232 alert(__("No article is selected."));
1236 var visible_ids
= getVisibleArticleIds();
1238 var ids_to_mark
= new Array();
1241 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1242 if (visible_ids
[i
] != id
) {
1243 var e
= $("RROW-" + visible_ids
[i
]);
1245 if (e
&& e
.hasClassName("Unread")) {
1246 ids_to_mark
.push(visible_ids
[i
]);
1253 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1254 if (visible_ids
[i
] != id
) {
1255 var e
= $("RROW-" + visible_ids
[i
]);
1257 if (e
&& e
.hasClassName("Unread")) {
1258 ids_to_mark
.push(visible_ids
[i
]);
1266 if (ids_to_mark
.length
== 0) {
1267 alert(__("No articles found to mark"));
1269 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1271 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1273 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1274 var e
= $("RROW-" + ids_to_mark
[i
]);
1275 e
.removeClassName("Unread");
1278 var query
= "?op=rpc&method=catchupSelected" +
1279 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1281 new Ajax
.Request("backend.php", {
1283 onComplete: function(transport
) {
1284 handle_rpc_json(transport
);
1291 exception_error("catchupRelativeToArticle", e
);
1295 function cdmExpandArticle(id
) {
1300 var elem
= $("CICD-" + active_post_id
);
1302 var upd_img_pic
= $("FUPDPIC-" + id
);
1304 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1305 upd_img_pic
.src
.match("fresh_sign.png"))) {
1307 upd_img_pic
.src
= "images/blank_icon.gif";
1310 if (id
== active_post_id
&& Element
.visible(elem
))
1313 selectArticles("none");
1315 var old_offset
= $("RROW-" + id
).offsetTop
;
1317 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1319 Element
.show("CEXC-" + active_post_id
);
1322 active_post_id
= id
;
1324 elem
= $("CICD-" + id
);
1326 if (!Element
.visible(elem
)) {
1328 Element
.hide("CEXC-" + id
);
1330 if ($("CWRAP-" + id
).innerHTML
== "") {
1332 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1334 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1335 __("Loading, please wait...") + "</div>";
1337 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1339 var neighbor_ids
= getRelativePostIds(id
);
1341 /* only request uncached articles */
1342 var cids_to_request
= [];
1344 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1345 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1346 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1347 cids_to_request
.push(neighbor_ids
[i
]);
1348 cids_requested
.push(neighbor_ids
[i
]);
1352 console
.log("additional ids: " + cids_to_request
.toString());
1354 query
= query
+ "&cids=" + cids_to_request
.toString();
1358 new Ajax
.Request("backend.php", {
1360 onComplete: function(transport
) {
1362 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1364 handle_rpc_json(transport
);
1366 var reply
= JSON
.parse(transport
.responseText
);
1368 reply
.each(function(article
) {
1369 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1370 cids_requested
.remove(article
['id']);
1377 var new_offset
= $("RROW-" + id
).offsetTop
;
1379 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1381 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1382 $("headlines-frame").scrollTop
= new_offset
;
1384 toggleUnread(id
, 0, true);
1388 exception_error("cdmExpandArticle", e
);
1394 function fixHeadlinesOrder(ids
) {
1396 for (var i
= 0; i
< ids
.length
; i
++) {
1397 var e
= $("RROW-" + ids
[i
]);
1401 e
.removeClassName("even");
1402 e
.addClassName("odd");
1404 e
.removeClassName("odd");
1405 e
.addClassName("even");
1410 exception_error("fixHeadlinesOrder", e
);
1414 function getArticleUnderPointer() {
1415 return post_under_pointer
;
1418 function zoomToArticle(event
, id
) {
1420 var cached_article
= cache_get("article: " + id
);
1422 if (dijit
.byId("ATAB-" + id
))
1423 if (!event
|| !event
.shiftKey
)
1424 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1426 if (dijit
.byId("ATSTRTIP-" + id
))
1427 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1429 if (cached_article
) {
1430 //closeArticlePanel();
1432 var article_pane
= new dijit
.layout
.ContentPane({
1433 title
: __("Loading...") , content
: cached_article
,
1434 style
: 'padding : 0px;',
1438 dijit
.byId("content-tabs").addChild(article_pane
);
1440 if (!event
|| !event
.shiftKey
)
1441 dijit
.byId("content-tabs").selectChild(article_pane
);
1443 if ($("PTITLE-" + id
))
1444 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1448 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1450 notify_progress("Loading, please wait...", true);
1452 new Ajax
.Request("backend.php", {
1454 onComplete: function(transport
) {
1457 var reply
= JSON
.parse(transport
.responseText
);
1460 //closeArticlePanel();
1462 var content
= reply
[0]['content'];
1464 var article_pane
= new dijit
.layout
.ContentPane({
1465 title
: "article-" + id
, content
: content
,
1466 style
: 'padding : 0px;',
1470 dijit
.byId("content-tabs").addChild(article_pane
);
1472 if (!event
|| !event
.shiftKey
)
1473 dijit
.byId("content-tabs").selectChild(article_pane
);
1475 if ($("PTITLE-" + id
))
1476 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1483 exception_error("zoomToArticle", e
);
1487 function scrollArticle(offset
) {
1490 var ci
= $("content-insert");
1492 ci
.scrollTop
+= offset
;
1495 var hi
= $("headlines-frame");
1497 hi
.scrollTop
+= offset
;
1502 exception_error("scrollArticle", e
);
1506 function show_labels_in_headlines(transport
) {
1508 var data
= JSON
.parse(transport
.responseText
);
1511 data
['info-for-headlines'].each(function(elem
) {
1512 var ctr
= $("HLLCTR-" + elem
.id
);
1514 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1517 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1521 exception_error("show_labels_in_headlines", e
);
1525 /* function toggleHeadlineActions() {
1527 var e = $("headlineActionsBody");
1528 var p = $("headlineActionsDrop");
1530 if (!Element.visible(e)) {
1537 e.style.left = (p.offsetLeft + 1) + "px";
1538 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1541 exception_error("toggleHeadlineActions", e);
1545 /* function publishWithNote(id, def_note) {
1547 if (!def_note) def_note = '';
1549 var note = prompt(__("Please enter a note for this article:"), def_note);
1551 if (note != undefined) {
1552 togglePub(id, false, false, note);
1556 exception_error("publishWithNote", e);
1560 function dismissArticle(id
) {
1562 var elem
= $("RROW-" + id
);
1564 toggleUnread(id
, 0, true);
1566 new Effect
.Fade(elem
, {duration
: 0.5});
1568 active_post_id
= false;
1571 exception_error("dismissArticle", e
);
1575 function dismissSelectedArticles() {
1578 var ids
= getVisibleArticleIds();
1582 for (var i
= 0; i
< ids
.length
; i
++) {
1583 var elem
= $("RROW-" + ids
[i
]);
1585 if (elem
.className
&& elem
.hasClassName("Selected") &&
1586 ids
[i
] != active_post_id
) {
1587 new Effect
.Fade(elem
, {duration
: 0.5});
1595 selectionToggleUnread(false);
1597 fixHeadlinesOrder(tmp
);
1600 exception_error("dismissSelectedArticles", e
);
1604 function dismissReadArticles() {
1607 var ids
= getVisibleArticleIds();
1610 for (var i
= 0; i
< ids
.length
; i
++) {
1611 var elem
= $("RROW-" + ids
[i
]);
1613 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1614 !elem
.hasClassName("Selected")) {
1616 new Effect
.Fade(elem
, {duration
: 0.5});
1622 fixHeadlinesOrder(tmp
);
1625 exception_error("dismissSelectedArticles", e
);
1629 function getVisibleArticleIds() {
1634 getLoadedArticleIds().each(function(id
) {
1635 var elem
= $("RROW-" + id
);
1636 if (elem
&& Element
.visible(elem
))
1641 exception_error("getVisibleArticleIds", e
);
1647 function cdmClicked(event
, id
) {
1649 //var shift_key = event.shiftKey;
1653 if (!event
.ctrlKey
) {
1655 if (!getInitParam("cdm_expanded")) {
1656 return cdmExpandArticle(id
);
1659 selectArticles("none");
1662 var elem
= $("RROW-" + id
);
1663 var article_is_unread
= elem
.hasClassName("Unread");
1666 elem
.removeClassName("Unread");
1668 var upd_img_pic
= $("FUPDPIC-" + id
);
1670 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1671 upd_img_pic
.src
.match("fresh_sign.png"))) {
1673 upd_img_pic
.src
= "images/blank_icon.gif";
1676 active_post_id
= id
;
1678 if (article_is_unread
) {
1679 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1682 var query
= "?op=rpc&method=catchupSelected" +
1683 "&cmode=0&ids=" + param_escape(id
);
1685 new Ajax
.Request("backend.php", {
1687 onComplete: function(transport
) {
1688 handle_rpc_json(transport
);
1695 toggleSelected(id
, true);
1697 var elem
= $("RROW-" + id
);
1698 var article_is_unread
= elem
.hasClassName("Unread");
1700 if (article_is_unread
) {
1701 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1704 toggleUnread(id
, 0, false);
1705 zoomToArticle(event
, id
);
1709 exception_error("cdmClicked");
1715 function postClicked(event
, id
) {
1718 if (!event
.ctrlKey
) {
1721 postOpenInNewTab(event
, id
);
1726 exception_error("postClicked");
1730 function hlOpenInNewTab(event
, id
) {
1731 toggleUnread(id
, 0, false);
1732 zoomToArticle(event
, id
);
1735 function postOpenInNewTab(event
, id
) {
1736 closeArticlePanel(id
);
1737 zoomToArticle(event
, id
);
1740 function hlClicked(event
, id
) {
1742 if (event
.which
== 2) {
1745 } else if (event
.altKey
) {
1746 openArticleInNewWindow(id
);
1747 } else if (!event
.ctrlKey
) {
1752 toggleUnread(id
, 0, false);
1753 zoomToArticle(event
, id
);
1758 exception_error("hlClicked");
1762 function getFirstVisibleHeadlineId() {
1763 var rows
= getVisibleArticleIds();
1768 function getLastVisibleHeadlineId() {
1769 var rows
= getVisibleArticleIds();
1770 return rows
[rows
.length
-1];
1773 function openArticleInNewWindow(id
) {
1774 toggleUnread(id
, 0, false);
1775 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1778 function isCdmMode() {
1779 return getInitParam("combined_display_mode");
1782 function markHeadline(id
) {
1783 var row
= $("RROW-" + id
);
1785 var check
= $("RCHK-" + id
);
1788 check
.checked
= true;
1791 row
.addClassName("Selected");
1795 function getRelativePostIds(id
, limit
) {
1801 if (!limit
) limit
= 6; //3
1803 var ids
= getVisibleArticleIds();
1805 for (var i
= 0; i
< ids
.length
; i
++) {
1807 for (var k
= 1; k
<= limit
; k
++) {
1808 //if (i > k-1) tmp.push(ids[i-k]);
1809 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1816 exception_error("getRelativePostIds", e
);
1822 function correctHeadlinesOffset(id
) {
1826 var container
= $("headlines-frame");
1827 var row
= $("RROW-" + id
);
1829 if (!container
|| !row
) return;
1831 var viewport
= container
.offsetHeight
;
1833 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1834 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1836 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1837 //console.log("Vport: " + viewport);
1839 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1840 container
.scrollTop
= row
.offsetTop
;
1841 } else if (rel_offset_bottom
> viewport
) {
1843 /* doesn't properly work with Opera in some cases because
1844 Opera fucks up element scrolling */
1846 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1850 exception_error("correctHeadlinesOffset", e
);
1855 function headlineActionsChange(elem
) {
1858 elem
.attr('value', 'false');
1860 exception_error("headlineActionsChange", e
);
1864 function closeArticlePanel() {
1866 var tabs
= dijit
.byId("content-tabs");
1867 var child
= tabs
.selectedChildWidget
;
1869 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1870 tabs
.removeChild(child
);
1873 if (dijit
.byId("content-insert"))
1874 dijit
.byId("headlines-wrap-inner").removeChild(
1875 dijit
.byId("content-insert"));
1879 function initHeadlinesMenu() {
1881 if (dijit
.byId("headlinesMenu"))
1882 dijit
.byId("headlinesMenu").destroyRecursive();
1887 nodes
= $$("#headlines-frame > div[id*=RROW]");
1889 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1892 nodes
.each(function(node
) {
1896 var menu
= new dijit
.Menu({
1897 id
: "headlinesMenu",
1901 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1902 var callerNode
= event
.target
, match
= null, tries
= 0;
1904 while (match
== null && callerNode
&& tries
<= 3) {
1905 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1906 callerNode
= callerNode
.parentNode
;
1910 if (match
) this.callerRowId
= parseInt(match
[1]);
1914 /* if (!isCdmMode())
1915 menu.addChild(new dijit.MenuItem({
1916 label: __("View article"),
1917 onClick: function(event) {
1918 view(this.getParent().callerRowId);
1921 menu
.addChild(new dijit
.MenuItem({
1922 label
: __("Open original article"),
1923 onClick: function(event
) {
1924 openArticleInNewWindow(this.getParent().callerRowId
);
1927 menu
.addChild(new dijit
.MenuItem({
1928 label
: __("View in a tt-rss tab"),
1929 onClick: function(event
) {
1930 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1933 menu
.addChild(new dijit
.MenuSeparator());
1935 menu
.addChild(new dijit
.MenuItem({
1936 label
: __("Mark above as read"),
1937 onClick: function(event
) {
1938 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1941 menu
.addChild(new dijit
.MenuItem({
1942 label
: __("Mark below as read"),
1943 onClick: function(event
) {
1944 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1948 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1952 menu
.addChild(new dijit
.MenuSeparator());
1954 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1955 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1957 labels
.each(function(label
) {
1958 var id
= label
.id
[0];
1959 var bare_id
= id
.substr(id
.indexOf(":")+1);
1960 var name
= label
.name
[0];
1962 bare_id
= -11-bare_id
;
1964 labelAddMenu
.addChild(new dijit
.MenuItem({
1967 onClick: function(event
) {
1968 var ids
= getSelectedArticleIds2();
1970 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1972 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1974 selectionAssignLabel(this.labelId
, ids
);
1977 labelDelMenu
.addChild(new dijit
.MenuItem({
1980 onClick: function(event
) {
1981 var ids
= getSelectedArticleIds2();
1983 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1985 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1987 selectionRemoveLabel(this.labelId
, ids
);
1992 menu
.addChild(new dijit
.PopupMenuItem({
1993 label
: __("Assign label"),
1994 popup
: labelAddMenu
,
1997 menu
.addChild(new dijit
.PopupMenuItem({
1998 label
: __("Remove label"),
1999 popup
: labelDelMenu
,
2007 exception_error("initHeadlinesMenu", e
);
2012 function player(elem
) {
2013 var aid
= elem
.getAttribute("audio-id");
2014 var status
= elem
.getAttribute("status");
2022 elem
.innerHTML
= __("Playing...");
2023 elem
.title
= __("Click to pause");
2024 elem
.addClassName("playing");
2028 elem
.innerHTML
= __("Play");
2029 elem
.title
= __("Click to play");
2030 elem
.removeClassName("playing");
2033 elem
.setAttribute("status", status
);
2035 alert("Your browser doesn't seem to support HTML5 audio.");
2039 function cache_set(id
, obj
) {
2040 //console.log("cache_set: " + id);
2043 sessionStorage
[id
] = obj
;
2045 sessionStorage
.clear();
2049 function cache_get(id
) {
2051 return sessionStorage
[id
];
2054 function cache_clear() {
2056 sessionStorage
.clear();
2059 function cache_delete(id
) {
2061 sessionStorage
.removeItem(id
);
2064 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2065 if (toolbar_obj
&& content_obj
) {
2066 cache_set("feed:" + feed
+ ":" + is_cat
,
2067 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2070 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2073 obj
= JSON
.parse(obj
);
2075 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2076 if (content_obj
) obj
.content
= content_obj
;
2078 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2082 console
.warn("cache_headlines failed: " + e
);
2087 function render_local_headlines(feed
, is_cat
, obj
) {
2090 dijit
.byId("headlines-toolbar").attr('content',
2093 dijit
.byId("headlines-frame").attr('content',
2096 dojo
.parser
.parse('headlines-toolbar');
2098 $("headlines-frame").scrollTop
= 0;
2099 selectArticles('none');
2100 setActiveFeedId(feed
, is_cat
);
2101 initHeadlinesMenu();
2103 precache_headlines();
2106 exception_error("render_local_headlines", e
);
2110 function precache_headlines_idle() {
2112 if (!feed_precache_timeout_id
) {
2113 if (get_timestamp() - _viewfeed_last
> 120) {
2115 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2118 feeds
.each(function(item
) {
2119 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2120 uncached
.push(item
);
2123 if (uncached
.length
> 0) {
2124 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2125 viewfeed(rf
[0], '', rf
[1], 0, true);
2129 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2132 exception_error("precache_headlines_idle", e
);
2136 function precache_headlines() {
2139 if (!feed_precache_timeout_id
) {
2140 feed_precache_timeout_id
= window
.setTimeout(function() {
2141 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2142 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2144 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2145 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2147 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2148 viewfeed(nf
[0], '', nf
[1], 0, true);
2150 window
.setTimeout(function() {
2151 feed_precache_timeout_id
= false;
2157 exception_error("precache_headlines", e
);