]>
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
= [];
16 var loaded_article_ids
= [];
18 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
20 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
22 handle_rpc_json(transport
);
24 loading_set_progress(25);
26 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
34 reply
= JSON
.parse(transport
.responseText
);
41 is_cat
= reply
['headlines']['is_cat'];
42 feed_id
= reply
['headlines']['id'];
45 var content
= reply
['headlines']['content'];
47 if (getInitParam("cdm_auto_catchup") == 1) {
48 content
= content
+ "<div id='headlines-spacer'></div>";
51 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], content
);
55 setActiveFeedId(feed_id
, is_cat
);
57 dijit
.getEnclosingWidget(
58 document
.forms
["main_toolbar_form"].update
).attr('disabled',
59 is_cat
|| feed_id
<= 0);
62 if (offset
== 0 && infscroll_req
== false) {
63 $("headlines-frame").scrollTop
= 0;
67 var headlines_count
= reply
['headlines-info']['count'];
69 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
71 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
72 _infscroll_disable
= 1;
74 _infscroll_disable
= 0;
77 var counters
= reply
['counters'];
78 var articles
= reply
['articles'];
79 //var runtime_info = reply['runtime-info'];
81 if (offset
== 0 && infscroll_req
== false) {
82 loaded_article_ids
= [];
84 dijit
.byId("headlines-frame").attr('content',
85 reply
['headlines']['content']);
87 dijit
.byId("headlines-toolbar").attr('content',
88 reply
['headlines']['toolbar']);
90 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
91 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
92 row
.parentNode
.removeChild(row
);
94 loaded_article_ids
.push(row
.id
);
98 if (getInitParam("cdm_auto_catchup") == 1) {
99 var hsp
= $("headlines-spacer");
100 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
101 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
107 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
108 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
114 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
115 console
.log("adding some more headlines: " + headlines_count
);
117 var c
= dijit
.byId("headlines-frame");
118 var ids
= getSelectedArticleIds2();
121 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
123 var hsp
= $("headlines-spacer");
126 c
.domNode
.removeChild(hsp
);
128 $$("#headlines-tmp > div").each(function(row
) {
129 if (row
.className
== 'cdmFeedTitle') {
130 row
.style
.display
= 'none';
131 c
.domNode
.appendChild(row
);
133 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
134 row
.style
.display
= 'none';
135 c
.domNode
.appendChild(row
);
137 loaded_article_ids
.push(row
.id
);
139 row
.parentNode
.removeChild(row
);
143 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
145 fixHeadlinesOrder(getLoadedArticleIds());
147 if (getInitParam("cdm_auto_catchup") == 1) {
148 c
.domNode
.appendChild(hsp
);
151 console
.log("added " + new_elems
.size() + " headlines");
153 if (new_elems
.size() == 0)
154 _infscroll_disable
= true;
156 console
.log("restore selected ids: " + ids
);
158 for (var i
= 0; i
< ids
.length
; i
++) {
159 markHeadline(ids
[i
]);
164 new_elems
.each(function(child
) {
165 if (dijit
.byId("RCHK-" + child
.id
)) {
166 dijit
.byId("RCHK-" + child
.id
).destroy();
169 dojo
.parser
.parse(child
);
171 if (!Element
.visible(child
))
172 new Effect
.Appear(child
, { duration
: 0.5 });
176 console
.log("no new headlines received");
178 var hsp
= $("headlines-spacer");
180 if (hsp
) hsp
.innerHTML
= "";
184 if (headlines_count
> 0)
185 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
188 for (var i
= 0; i
< articles
.length
; i
++) {
189 var a_id
= articles
[i
]['id'];
190 cache_set("article:" + a_id
, articles
[i
]['content']);
193 console
.log("no cached articles received");
196 // do not precache stuff after fresh feed
198 precache_headlines();
201 parse_counters(counters
);
206 console
.error("Invalid object received: " + transport
.responseText
);
207 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
208 __('Could not update headlines (invalid object received - see error console for details)') +
212 _infscroll_request_sent
= 0;
217 exception_error("headlines_callback2", e
, transport
);
221 function render_article(article
) {
223 dijit
.byId("headlines-wrap-inner").addChild(
224 dijit
.byId("content-insert"));
226 var c
= dijit
.byId("content-insert");
229 c
.domNode
.scrollTop
= 0;
232 c
.attr('content', article
);
234 correctHeadlinesOffset(getActiveArticleId());
241 exception_error("render_article", e
);
245 function showArticleInHeadlines(id
) {
249 selectArticles("none");
251 var crow
= $("RROW-" + id
);
255 var article_is_unread
= crow
.hasClassName("Unread");
257 crow
.removeClassName("Unread");
259 selectArticles('none');
261 var view_mode
= false;
264 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
265 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
270 if (article_is_unread
&& view_mode
== "all_articles") {
271 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
276 if (article_is_unread
)
277 _force_scheduled_update
= true;
280 exception_error("showArticleInHeadlines", e
);
284 function article_callback2(transport
, id
) {
286 console
.log("article_callback2 " + id
);
288 handle_rpc_json(transport
);
293 reply
= JSON
.parse(transport
.responseText
);
300 reply
.each(function(article
) {
301 if (active_post_id
== article
['id']) {
302 render_article(article
['content']);
304 cids_requested
.remove(article
['id']);
306 cache_set("article:" + article
['id'], article
['content']);
309 // if (id != last_requested_article) {
310 // console.log("requested article id is out of sequence, aborting");
315 console
.error("Invalid object received: " + transport
.responseText
);
317 render_article("<div class='whiteBox'>" +
318 __('Could not display article (invalid object received - see error console for details)') + "</div>");
323 headlines_scroll_handler($("headlines-frame"));
326 if (!_infscroll_disable &&
327 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
337 exception_error("article_callback2", e
, transport
);
343 console
.log("loading article: " + id
);
345 var cached_article
= cache_get("article:" + id
);
347 console
.log("cache check result: " + (cached_article
!= false));
351 var query
= "?op=article&method=view&id=" + param_escape(id
);
353 var neighbor_ids
= getRelativePostIds(id
);
355 /* only request uncached articles */
357 var cids_to_request
= [];
359 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
360 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
361 if (!cache_get("article:" + neighbor_ids
[i
])) {
362 cids_to_request
.push(neighbor_ids
[i
]);
363 cids_requested
.push(neighbor_ids
[i
]);
367 console
.log("additional ids: " + cids_to_request
.toString());
369 query
= query
+ "&cids=" + cids_to_request
.toString();
371 var crow
= $("RROW-" + id
);
372 var article_is_unread
= crow
.hasClassName("Unread");
375 showArticleInHeadlines(id
);
377 precache_headlines();
379 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
= dijit
.byId("RCHK-" + id
);
575 var row
= $("RROW-" + id
);
578 if (row
.hasClassName('Selected') && !force_on
) {
579 row
.removeClassName('Selected');
580 if (cb
) cb
.attr("checked", false);
582 row
.addClassName('Selected');
583 if (cb
) cb
.attr("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
= dijit
.byId("RCHK-" + id
);
872 child
.addClassName("Selected");
873 if (cb
) cb
.attr("checked", true);
874 } else if (mode
== "unread") {
875 if (child
.hasClassName("Unread")) {
876 child
.addClassName("Selected");
877 if (cb
) cb
.attr("checked", true);
879 child
.removeClassName("Selected");
880 if (cb
) cb
.attr("checked", false);
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");
887 if (cb
) cb
.attr("checked", true);
889 child
.removeClassName("Selected");
890 if (cb
) cb
.attr("checked", false);
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");
897 if (cb
) cb
.attr("checked", true);
899 child
.removeClassName("Selected");
900 if (cb
) cb
.attr("checked", false);
903 } else if (mode
== "invert") {
904 if (child
.hasClassName("Selected")) {
905 child
.removeClassName("Selected");
906 if (cb
) cb
.attr("checked", false);
908 child
.addClassName("Selected");
909 if (cb
) cb
.attr("checked", true);
913 child
.removeClassName("Selected");
914 if (cb
) cb
.attr("checked", false);
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 if (id
== active_post_id
&& Element
.visible(elem
))
1305 selectArticles("none");
1307 var old_offset
= $("RROW-" + id
).offsetTop
;
1309 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1311 Element
.show("CEXC-" + active_post_id
);
1314 active_post_id
= id
;
1316 elem
= $("CICD-" + id
);
1318 if (!Element
.visible(elem
)) {
1320 Element
.hide("CEXC-" + id
);
1323 var new_offset
= $("RROW-" + id
).offsetTop
;
1325 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1327 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1328 $("headlines-frame").scrollTop
= new_offset
;
1330 toggleUnread(id
, 0, true);
1334 exception_error("cdmExpandArticle", e
);
1340 function fixHeadlinesOrder(ids
) {
1342 for (var i
= 0; i
< ids
.length
; i
++) {
1343 var e
= $("RROW-" + ids
[i
]);
1347 e
.removeClassName("even");
1348 e
.addClassName("odd");
1350 e
.removeClassName("odd");
1351 e
.addClassName("even");
1356 exception_error("fixHeadlinesOrder", e
);
1360 function getArticleUnderPointer() {
1361 return post_under_pointer
;
1364 function zoomToArticle(event
, id
) {
1366 var cached_article
= cache_get("article: " + id
);
1368 if (dijit
.byId("ATAB-" + id
))
1369 if (!event
|| !event
.shiftKey
)
1370 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1372 if (dijit
.byId("ATSTRTIP-" + id
))
1373 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1375 if (cached_article
) {
1376 //closeArticlePanel();
1378 var article_pane
= new dijit
.layout
.ContentPane({
1379 title
: __("Loading...") , content
: cached_article
,
1380 style
: 'padding : 0px;',
1384 dijit
.byId("content-tabs").addChild(article_pane
);
1386 if (!event
|| !event
.shiftKey
)
1387 dijit
.byId("content-tabs").selectChild(article_pane
);
1389 if ($("PTITLE-" + id
))
1390 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1394 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1396 notify_progress("Loading, please wait...", true);
1398 new Ajax
.Request("backend.php", {
1400 onComplete: function(transport
) {
1403 var reply
= JSON
.parse(transport
.responseText
);
1406 //closeArticlePanel();
1408 var content
= reply
[0]['content'];
1410 var article_pane
= new dijit
.layout
.ContentPane({
1411 title
: "article-" + id
, content
: content
,
1412 style
: 'padding : 0px;',
1416 dijit
.byId("content-tabs").addChild(article_pane
);
1418 if (!event
|| !event
.shiftKey
)
1419 dijit
.byId("content-tabs").selectChild(article_pane
);
1421 if ($("PTITLE-" + id
))
1422 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1429 exception_error("zoomToArticle", e
);
1433 function scrollArticle(offset
) {
1436 var ci
= $("content-insert");
1438 ci
.scrollTop
+= offset
;
1441 var hi
= $("headlines-frame");
1443 hi
.scrollTop
+= offset
;
1448 exception_error("scrollArticle", e
);
1452 function show_labels_in_headlines(transport
) {
1454 var data
= JSON
.parse(transport
.responseText
);
1457 data
['info-for-headlines'].each(function(elem
) {
1458 var ctr
= $("HLLCTR-" + elem
.id
);
1460 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1463 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1467 exception_error("show_labels_in_headlines", e
);
1471 /* function toggleHeadlineActions() {
1473 var e = $("headlineActionsBody");
1474 var p = $("headlineActionsDrop");
1476 if (!Element.visible(e)) {
1483 e.style.left = (p.offsetLeft + 1) + "px";
1484 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1487 exception_error("toggleHeadlineActions", e);
1491 /* function publishWithNote(id, def_note) {
1493 if (!def_note) def_note = '';
1495 var note = prompt(__("Please enter a note for this article:"), def_note);
1497 if (note != undefined) {
1498 togglePub(id, false, false, note);
1502 exception_error("publishWithNote", e);
1506 function dismissArticle(id
) {
1508 var elem
= $("RROW-" + id
);
1510 toggleUnread(id
, 0, true);
1512 new Effect
.Fade(elem
, {duration
: 0.5});
1514 active_post_id
= false;
1517 exception_error("dismissArticle", e
);
1521 function dismissSelectedArticles() {
1524 var ids
= getVisibleArticleIds();
1528 for (var i
= 0; i
< ids
.length
; i
++) {
1529 var elem
= $("RROW-" + ids
[i
]);
1531 if (elem
.className
&& elem
.hasClassName("Selected") &&
1532 ids
[i
] != active_post_id
) {
1533 new Effect
.Fade(elem
, {duration
: 0.5});
1541 selectionToggleUnread(false);
1543 fixHeadlinesOrder(tmp
);
1546 exception_error("dismissSelectedArticles", e
);
1550 function dismissReadArticles() {
1553 var ids
= getVisibleArticleIds();
1556 for (var i
= 0; i
< ids
.length
; i
++) {
1557 var elem
= $("RROW-" + ids
[i
]);
1559 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1560 !elem
.hasClassName("Selected")) {
1562 new Effect
.Fade(elem
, {duration
: 0.5});
1568 fixHeadlinesOrder(tmp
);
1571 exception_error("dismissSelectedArticles", e
);
1575 function getVisibleArticleIds() {
1580 getLoadedArticleIds().each(function(id
) {
1581 var elem
= $("RROW-" + id
);
1582 if (elem
&& Element
.visible(elem
))
1587 exception_error("getVisibleArticleIds", e
);
1593 function cdmClicked(event
, id
) {
1595 //var shift_key = event.shiftKey;
1599 if (!event
.ctrlKey
) {
1601 if (!getInitParam("cdm_expanded")) {
1602 return cdmExpandArticle(id
);
1605 selectArticles("none");
1608 var elem
= $("RROW-" + id
);
1609 var article_is_unread
= elem
.hasClassName("Unread");
1612 elem
.removeClassName("Unread");
1614 active_post_id
= id
;
1616 if (article_is_unread
) {
1617 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1620 var query
= "?op=rpc&method=catchupSelected" +
1621 "&cmode=0&ids=" + param_escape(id
);
1623 new Ajax
.Request("backend.php", {
1625 onComplete: function(transport
) {
1626 handle_rpc_json(transport
);
1633 toggleSelected(id
, true);
1635 var elem
= $("RROW-" + id
);
1636 var article_is_unread
= elem
.hasClassName("Unread");
1638 if (article_is_unread
) {
1639 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1642 toggleUnread(id
, 0, false);
1643 zoomToArticle(event
, id
);
1647 exception_error("cdmClicked");
1653 function postClicked(event
, id
) {
1656 if (!event
.ctrlKey
) {
1659 postOpenInNewTab(event
, id
);
1664 exception_error("postClicked");
1668 function hlOpenInNewTab(event
, id
) {
1669 toggleUnread(id
, 0, false);
1670 zoomToArticle(event
, id
);
1673 function postOpenInNewTab(event
, id
) {
1674 closeArticlePanel(id
);
1675 zoomToArticle(event
, id
);
1678 function hlClicked(event
, id
) {
1680 if (event
.which
== 2) {
1683 } else if (event
.altKey
) {
1684 openArticleInNewWindow(id
);
1685 } else if (!event
.ctrlKey
) {
1690 toggleUnread(id
, 0, false);
1691 zoomToArticle(event
, id
);
1696 exception_error("hlClicked");
1700 function getFirstVisibleHeadlineId() {
1701 var rows
= getVisibleArticleIds();
1706 function getLastVisibleHeadlineId() {
1707 var rows
= getVisibleArticleIds();
1708 return rows
[rows
.length
-1];
1711 function openArticleInNewWindow(id
) {
1712 toggleUnread(id
, 0, false);
1713 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1716 function isCdmMode() {
1717 return getInitParam("combined_display_mode");
1720 function markHeadline(id
) {
1721 var row
= $("RROW-" + id
);
1723 var check
= dijit
.byId("RCHK-" + id
);
1726 check
.attr("checked", true);
1729 row
.addClassName("Selected");
1733 function getRelativePostIds(id
, limit
) {
1739 if (!limit
) limit
= 6; //3
1741 var ids
= getVisibleArticleIds();
1743 for (var i
= 0; i
< ids
.length
; i
++) {
1745 for (var k
= 1; k
<= limit
; k
++) {
1746 //if (i > k-1) tmp.push(ids[i-k]);
1747 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1754 exception_error("getRelativePostIds", e
);
1760 function correctHeadlinesOffset(id
) {
1764 var container
= $("headlines-frame");
1765 var row
= $("RROW-" + id
);
1767 if (!container
|| !row
) return;
1769 var viewport
= container
.offsetHeight
;
1771 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1772 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1774 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1775 //console.log("Vport: " + viewport);
1777 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1778 container
.scrollTop
= row
.offsetTop
;
1779 } else if (rel_offset_bottom
> viewport
) {
1781 /* doesn't properly work with Opera in some cases because
1782 Opera fucks up element scrolling */
1784 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1788 exception_error("correctHeadlinesOffset", e
);
1793 function headlineActionsChange(elem
) {
1796 elem
.attr('value', 'false');
1798 exception_error("headlineActionsChange", e
);
1802 function closeArticlePanel() {
1804 var tabs
= dijit
.byId("content-tabs");
1805 var child
= tabs
.selectedChildWidget
;
1807 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1808 tabs
.removeChild(child
);
1811 if (dijit
.byId("content-insert"))
1812 dijit
.byId("headlines-wrap-inner").removeChild(
1813 dijit
.byId("content-insert"));
1817 function initHeadlinesMenu() {
1819 if (dijit
.byId("headlinesMenu"))
1820 dijit
.byId("headlinesMenu").destroyRecursive();
1825 nodes
= $$("#headlines-frame > div[id*=RROW]");
1827 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1830 nodes
.each(function(node
) {
1834 var menu
= new dijit
.Menu({
1835 id
: "headlinesMenu",
1839 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1840 var callerNode
= event
.target
, match
= null, tries
= 0;
1842 while (match
== null && callerNode
&& tries
<= 3) {
1843 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1844 callerNode
= callerNode
.parentNode
;
1848 if (match
) this.callerRowId
= parseInt(match
[1]);
1852 /* if (!isCdmMode())
1853 menu.addChild(new dijit.MenuItem({
1854 label: __("View article"),
1855 onClick: function(event) {
1856 view(this.getParent().callerRowId);
1859 menu
.addChild(new dijit
.MenuItem({
1860 label
: __("Open original article"),
1861 onClick: function(event
) {
1862 openArticleInNewWindow(this.getParent().callerRowId
);
1865 menu
.addChild(new dijit
.MenuItem({
1866 label
: __("View in a tt-rss tab"),
1867 onClick: function(event
) {
1868 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1871 menu
.addChild(new dijit
.MenuSeparator());
1873 menu
.addChild(new dijit
.MenuItem({
1874 label
: __("Mark above as read"),
1875 onClick: function(event
) {
1876 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1879 menu
.addChild(new dijit
.MenuItem({
1880 label
: __("Mark below as read"),
1881 onClick: function(event
) {
1882 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1886 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1890 menu
.addChild(new dijit
.MenuSeparator());
1892 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1893 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1895 labels
.each(function(label
) {
1896 var id
= label
.id
[0];
1897 var bare_id
= id
.substr(id
.indexOf(":")+1);
1898 var name
= label
.name
[0];
1900 bare_id
= -11-bare_id
;
1902 labelAddMenu
.addChild(new dijit
.MenuItem({
1905 onClick: function(event
) {
1906 var ids
= getSelectedArticleIds2();
1908 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1910 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1912 selectionAssignLabel(this.labelId
, ids
);
1915 labelDelMenu
.addChild(new dijit
.MenuItem({
1918 onClick: function(event
) {
1919 var ids
= getSelectedArticleIds2();
1921 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1923 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1925 selectionRemoveLabel(this.labelId
, ids
);
1930 menu
.addChild(new dijit
.PopupMenuItem({
1931 label
: __("Assign label"),
1932 popup
: labelAddMenu
,
1935 menu
.addChild(new dijit
.PopupMenuItem({
1936 label
: __("Remove label"),
1937 popup
: labelDelMenu
,
1945 exception_error("initHeadlinesMenu", e
);
1950 function player(elem
) {
1951 var aid
= elem
.getAttribute("audio-id");
1952 var status
= elem
.getAttribute("status");
1960 elem
.innerHTML
= __("Playing...");
1961 elem
.title
= __("Click to pause");
1962 elem
.addClassName("playing");
1966 elem
.innerHTML
= __("Play");
1967 elem
.title
= __("Click to play");
1968 elem
.removeClassName("playing");
1971 elem
.setAttribute("status", status
);
1973 alert("Your browser doesn't seem to support HTML5 audio.");
1977 function cache_set(id
, obj
) {
1978 //console.log("cache_set: " + id);
1981 sessionStorage
[id
] = obj
;
1983 sessionStorage
.clear();
1987 function cache_get(id
) {
1989 return sessionStorage
[id
];
1992 function cache_clear() {
1994 sessionStorage
.clear();
1997 function cache_delete(id
) {
1999 sessionStorage
.removeItem(id
);
2002 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2003 if (toolbar_obj
&& content_obj
) {
2004 cache_set("feed:" + feed
+ ":" + is_cat
,
2005 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2008 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2011 obj
= JSON
.parse(obj
);
2013 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2014 if (content_obj
) obj
.content
= content_obj
;
2016 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2020 console
.warn("cache_headlines failed: " + e
);
2025 function render_local_headlines(feed
, is_cat
, obj
) {
2028 dijit
.byId("headlines-toolbar").attr('content',
2031 dijit
.byId("headlines-frame").attr('content',
2034 dojo
.parser
.parse('headlines-toolbar');
2036 $("headlines-frame").scrollTop
= 0;
2037 selectArticles('none');
2038 setActiveFeedId(feed
, is_cat
);
2039 initHeadlinesMenu();
2041 dijit
.getEnclosingWidget(
2042 document
.forms
["main_toolbar_form"].update
).attr('disabled',
2043 is_cat
|| feed
<= 0);
2045 precache_headlines();
2048 exception_error("render_local_headlines", e
);
2052 function precache_headlines_idle() {
2054 if (!feed_precache_timeout_id
) {
2055 if (get_timestamp() - _viewfeed_last
> 120) {
2057 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2060 feeds
.each(function(item
) {
2061 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2062 uncached
.push(item
);
2065 if (uncached
.length
> 0) {
2066 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2067 viewfeed(rf
[0], '', rf
[1], 0, true);
2071 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2074 exception_error("precache_headlines_idle", e
);
2078 function precache_headlines() {
2081 if (!feed_precache_timeout_id
) {
2082 feed_precache_timeout_id
= window
.setTimeout(function() {
2083 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2084 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2086 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2087 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2089 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2090 viewfeed(nf
[0], '', nf
[1], 0, true);
2092 window
.setTimeout(function() {
2093 feed_precache_timeout_id
= false;
2099 exception_error("precache_headlines", e
);
2103 function cancelSearch() {
2108 exception_error("cancelSearch", e
);
2112 function setSelectionScore() {
2114 var ids
= getSelectedArticleIds2();
2116 if (ids
.length
> 0) {
2119 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2121 if (score
!= undefined) {
2122 var query
= "op=rpc&method=setScore&id=" + param_escape(ids
.toString()) +
2123 "&score=" + param_escape(score
);
2125 new Ajax
.Request("backend.php", {
2127 onComplete: function(transport
) {
2128 var reply
= JSON
.parse(transport
.responseText
);
2132 ids
.each(function(id
) {
2133 var row
= $("RROW-" + id
);
2136 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2139 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2140 reply
["score_pic"]);
2141 pic
.setAttribute("score", score
);
2150 alert(__("No articles are selected."));
2153 exception_error("setSelectionScore", e
);
2157 function changeScore(id
, pic
) {
2159 var score
= pic
.getAttribute("score");
2161 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2163 if (new_score
!= undefined) {
2165 var query
= "op=rpc&method=setScore&id=" + param_escape(id
) +
2166 "&score=" + param_escape(new_score
);
2168 new Ajax
.Request("backend.php", {
2170 onComplete: function(transport
) {
2171 var reply
= JSON
.parse(transport
.responseText
);
2174 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2175 pic
.setAttribute("score", new_score
);
2180 exception_error("changeScore", e
);