]>
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
);
57 if (offset
== 0 && infscroll_req
== false) {
58 $("headlines-frame").scrollTop
= 0;
62 var headlines_count
= reply
['headlines-info']['count'];
64 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
66 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
67 _infscroll_disable
= 1;
69 _infscroll_disable
= 0;
72 var counters
= reply
['counters'];
73 var articles
= reply
['articles'];
74 //var runtime_info = reply['runtime-info'];
76 if (offset
== 0 && infscroll_req
== false) {
77 dijit
.byId("headlines-frame").attr('content',
78 reply
['headlines']['content']);
80 dijit
.byId("headlines-toolbar").attr('content',
81 reply
['headlines']['toolbar']);
83 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
84 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
> 1) {
85 row
.parentNode
.removeChild(row
);
89 if (getInitParam("cdm_auto_catchup") == 1) {
90 var hsp
= $("headlines-spacer");
91 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
92 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
99 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
100 console
.log("adding some more headlines: " + headlines_count
);
102 var c
= dijit
.byId("headlines-frame");
103 var ids
= getSelectedArticleIds2();
106 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
108 var hsp
= $("headlines-spacer");
111 c
.domNode
.removeChild(hsp
);
113 $$("#headlines-tmp > div").each(function(row
) {
114 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
115 row
.style
.display
= 'none';
116 c
.domNode
.appendChild(row
);
119 row
.parentNode
.removeChild(row
);
123 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
125 fixHeadlinesOrder(getLoadedArticleIds());
127 if (getInitParam("cdm_auto_catchup") == 1) {
128 c
.domNode
.appendChild(hsp
);
131 console
.log("added " + num_added
+ " headlines");
133 console
.log("restore selected ids: " + ids
);
135 for (var i
= 0; i
< ids
.length
; i
++) {
136 markHeadline(ids
[i
]);
141 $$("#headlines-frame > div[id*=RROW]").each(
143 if (!Element
.visible(child
))
144 new Effect
.Appear(child
, { duration
: 0.5 });
148 console
.log("no new headlines received");
150 var hsp
= $("headlines-spacer");
152 if (hsp
) hsp
.innerHTML
= "";
156 if (headlines_count
> 0)
157 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
160 for (var i
= 0; i
< articles
.length
; i
++) {
161 var a_id
= articles
[i
]['id'];
162 cache_set("article:" + a_id
, articles
[i
]['content']);
165 console
.log("no cached articles received");
168 // do not precache stuff after fresh feed
170 precache_headlines();
173 parse_counters(counters
);
178 console
.error("Invalid object received: " + transport
.responseText
);
179 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
180 __('Could not update headlines (invalid object received - see error console for details)') +
184 _infscroll_request_sent
= 0;
189 exception_error("headlines_callback2", e
, transport
);
193 function render_article(article
) {
195 dijit
.byId("headlines-wrap-inner").addChild(
196 dijit
.byId("content-insert"));
198 var c
= dijit
.byId("content-insert");
201 c
.domNode
.scrollTop
= 0;
204 c
.attr('content', article
);
206 correctHeadlinesOffset(getActiveArticleId());
213 exception_error("render_article", e
);
217 function showArticleInHeadlines(id
) {
221 selectArticles("none");
223 var crow
= $("RROW-" + id
);
227 var article_is_unread
= crow
.hasClassName("Unread");
229 crow
.removeClassName("Unread");
231 selectArticles('none');
233 var upd_img_pic
= $("FUPDPIC-" + id
);
235 var view_mode
= false;
238 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
239 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
244 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
245 upd_img_pic
.src
.match("fresh_sign.png"))) {
247 upd_img_pic
.src
= "images/blank_icon.gif";
249 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
251 } else if (article_is_unread
&& view_mode
== "all_articles") {
252 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
257 if (article_is_unread
)
258 _force_scheduled_update
= true;
261 exception_error("showArticleInHeadlines", e
);
265 function article_callback2(transport
, id
) {
267 console
.log("article_callback2 " + id
);
269 handle_rpc_json(transport
);
274 reply
= JSON
.parse(transport
.responseText
);
281 var upic
= $('FUPDPIC-' + id
);
283 if (upic
) upic
.src
= 'images/blank_icon.gif';
285 reply
.each(function(article
) {
286 if (active_post_id
== article
['id']) {
287 render_article(article
['content']);
289 cids_requested
.remove(article
['id']);
291 cache_set("article:" + article
['id'], article
['content']);
294 // if (id != last_requested_article) {
295 // console.log("requested article id is out of sequence, aborting");
300 console
.error("Invalid object received: " + transport
.responseText
);
302 render_article("<div class='whiteBox'>" +
303 __('Could not display article (invalid object received - see error console for details)') + "</div>");
308 headlines_scroll_handler($("headlines-frame"));
311 if (!_infscroll_disable &&
312 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
322 exception_error("article_callback2", e
, transport
);
328 console
.log("loading article: " + id
);
330 var cached_article
= cache_get("article:" + id
);
332 console
.log("cache check result: " + (cached_article
!= false));
336 var query
= "?op=article&method=view&id=" + param_escape(id
);
338 var neighbor_ids
= getRelativePostIds(id
);
340 /* only request uncached articles */
342 var cids_to_request
= [];
344 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
345 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
346 if (!cache_get("article:" + neighbor_ids
[i
])) {
347 cids_to_request
.push(neighbor_ids
[i
]);
348 cids_requested
.push(neighbor_ids
[i
]);
352 console
.log("additional ids: " + cids_to_request
.toString());
354 query
= query
+ "&cids=" + cids_to_request
.toString();
356 var crow
= $("RROW-" + id
);
357 var article_is_unread
= crow
.hasClassName("Unread");
360 showArticleInHeadlines(id
);
362 precache_headlines();
364 if (!cached_article
) {
366 var upic
= $('FUPDPIC-' + id
);
369 upic
.src
= getInitParam("sign_progress");
372 } else if (cached_article
&& article_is_unread
) {
374 query
= query
+ "&mode=prefetch";
376 render_article(cached_article
);
378 } else if (cached_article
) {
380 query
= query
+ "&mode=prefetch_old";
381 render_article(cached_article
);
383 // if we don't need to request any relative ids, we might as well skip
384 // the server roundtrip altogether
385 if (cids_to_request
.length
== 0) {
388 if (!_infscroll_disable &&
389 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
397 headlines_scroll_handler($("headlines-frame"));
403 last_requested_article
= id
;
407 if (article_is_unread
) {
408 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
411 new Ajax
.Request("backend.php", {
413 onComplete: function(transport
) {
414 article_callback2(transport
, id
);
420 exception_error("view", e
);
424 function toggleMark(id
, client_only
) {
426 var query
= "?op=rpc&id=" + id
+ "&method=mark";
428 var img
= $("FMPIC-" + id
);
432 if (img
.src
.match("mark_unset")) {
433 img
.src
= img
.src
.replace("mark_unset", "mark_set");
434 img
.alt
= __("Unstar article");
435 query
= query
+ "&mark=1";
438 img
.src
= img
.src
.replace("mark_set", "mark_unset");
439 img
.alt
= __("Star article");
440 query
= query
+ "&mark=0";
443 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
446 new Ajax
.Request("backend.php", {
448 onComplete: function(transport
) {
449 handle_rpc_json(transport
);
454 exception_error("toggleMark", e
);
458 function togglePub(id
, client_only
, no_effects
, note
) {
460 var query
= "?op=rpc&id=" + id
+ "&method=publ";
462 if (note
!= undefined) {
463 query
= query
+ "¬e=" + param_escape(note
);
465 query
= query
+ "¬e=undefined";
468 var img
= $("FPPIC-" + id
);
472 if (img
.src
.match("pub_unset") || note
!= undefined) {
473 img
.src
= img
.src
.replace("pub_unset", "pub_set");
474 img
.alt
= __("Unpublish article");
475 query
= query
+ "&pub=1";
478 img
.src
= img
.src
.replace("pub_set", "pub_unset");
479 img
.alt
= __("Publish article");
481 query
= query
+ "&pub=0";
484 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
487 new Ajax
.Request("backend.php", {
489 onComplete: function(transport
) {
490 handle_rpc_json(transport
);
495 exception_error("togglePub", e
);
499 function moveToPost(mode
) {
503 var rows
= getVisibleArticleIds();
508 if (!$('RROW-' + active_post_id
)) {
509 active_post_id
= false;
512 if (active_post_id
== false) {
514 prev_id
= rows
[rows
.length
-1]
516 for (var i
= 0; i
< rows
.length
; i
++) {
517 if (rows
[i
] == active_post_id
) {
519 // Account for adjacent identical article ids.
520 if (i
> 0) prev_id
= rows
[i
-1];
522 for (var j
= i
+1; j
< rows
.length
; j
++) {
523 if (rows
[j
] != active_post_id
) {
533 if (mode
== "next") {
537 cdmExpandArticle(next_id
);
538 cdmScrollToArticleId(next_id
);
541 correctHeadlinesOffset(next_id
);
542 view(next_id
, getActiveFeedId());
547 if (mode
== "prev") {
550 cdmExpandArticle(prev_id
);
551 cdmScrollToArticleId(prev_id
);
553 correctHeadlinesOffset(prev_id
);
554 view(prev_id
, getActiveFeedId());
560 exception_error("moveToPost", e
);
564 function toggleSelected(id
, force_on
) {
567 var cb
= $("RCHK-" + id
);
568 var row
= $("RROW-" + id
);
571 if (row
.hasClassName('Selected') && !force_on
) {
572 row
.removeClassName('Selected');
573 if (cb
) cb
.checked
= false;
575 row
.addClassName('Selected');
576 if (cb
) cb
.checked
= true;
580 exception_error("toggleSelected", e
);
584 function toggleUnread_afh(effect
) {
587 var elem
= effect
.element
;
588 elem
.style
.backgroundColor
= "";
591 exception_error("toggleUnread_afh", e
);
595 function toggleUnread(id
, cmode
, effect
) {
598 var row
= $("RROW-" + id
);
600 if (cmode
== undefined || cmode
== 2) {
601 if (row
.hasClassName("Unread")) {
602 row
.removeClassName("Unread");
605 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
606 afterFinish
: toggleUnread_afh
,
607 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
611 row
.addClassName("Unread");
614 } else if (cmode
== 0) {
616 row
.removeClassName("Unread");
619 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
620 afterFinish
: toggleUnread_afh
,
621 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
624 } else if (cmode
== 1) {
625 row
.addClassName("Unread");
628 if (cmode
== undefined) cmode
= 2;
630 var query
= "?op=rpc&method=catchupSelected" +
631 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
633 // notify_progress("Loading, please wait...");
635 new Ajax
.Request("backend.php", {
637 onComplete: function(transport
) {
638 handle_rpc_json(transport
);
644 exception_error("toggleUnread", e
);
648 function selectionRemoveLabel(id
, ids
) {
651 if (!ids
) ids
= getSelectedArticleIds2();
653 if (ids
.length
== 0) {
654 alert(__("No articles are selected."));
658 var query
= "?op=rpc&method=removeFromLabel&ids=" +
659 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
663 new Ajax
.Request("backend.php", {
665 onComplete: function(transport
) {
666 handle_rpc_json(transport
);
667 show_labels_in_headlines(transport
);
671 exception_error("selectionAssignLabel", e
);
676 function selectionAssignLabel(id
, ids
) {
679 if (!ids
) ids
= getSelectedArticleIds2();
681 if (ids
.length
== 0) {
682 alert(__("No articles are selected."));
686 var query
= "?op=rpc&method=assignToLabel&ids=" +
687 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
691 new Ajax
.Request("backend.php", {
693 onComplete: function(transport
) {
694 handle_rpc_json(transport
);
695 show_labels_in_headlines(transport
);
699 exception_error("selectionAssignLabel", e
);
704 function selectionToggleUnread(set_state
, callback
, no_error
) {
706 var rows
= getSelectedArticleIds2();
708 if (rows
.length
== 0 && !no_error
) {
709 alert(__("No articles are selected."));
713 for (var i
= 0; i
< rows
.length
; i
++) {
714 var row
= $("RROW-" + rows
[i
]);
716 if (set_state
== undefined) {
717 if (row
.hasClassName("Unread")) {
718 row
.removeClassName("Unread");
720 row
.addClassName("Unread");
724 if (set_state
== false) {
725 row
.removeClassName("Unread");
728 if (set_state
== true) {
729 row
.addClassName("Unread");
734 if (rows
.length
> 0) {
738 if (set_state
== undefined) {
740 } else if (set_state
== true) {
742 } else if (set_state
== false) {
746 var query
= "?op=rpc&method=catchupSelected" +
747 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
749 notify_progress("Loading, please wait...");
751 new Ajax
.Request("backend.php", {
753 onComplete: function(transport
) {
754 handle_rpc_json(transport
);
755 if (callback
) callback(transport
);
761 exception_error("selectionToggleUnread", e
);
765 function selectionToggleMarked() {
768 var rows
= getSelectedArticleIds2();
770 if (rows
.length
== 0) {
771 alert(__("No articles are selected."));
775 for (var i
= 0; i
< rows
.length
; i
++) {
776 toggleMark(rows
[i
], true, true);
779 if (rows
.length
> 0) {
781 var query
= "?op=rpc&method=markSelected&ids=" +
782 param_escape(rows
.toString()) + "&cmode=2";
784 new Ajax
.Request("backend.php", {
786 onComplete: function(transport
) {
787 handle_rpc_json(transport
);
793 exception_error("selectionToggleMarked", e
);
797 function selectionTogglePublished() {
800 var rows
= getSelectedArticleIds2();
802 if (rows
.length
== 0) {
803 alert(__("No articles are selected."));
807 for (var i
= 0; i
< rows
.length
; i
++) {
808 togglePub(rows
[i
], true, true);
811 if (rows
.length
> 0) {
813 var query
= "?op=rpc&method=publishSelected&ids=" +
814 param_escape(rows
.toString()) + "&cmode=2";
816 new Ajax
.Request("backend.php", {
818 onComplete: function(transport
) {
819 handle_rpc_json(transport
);
825 exception_error("selectionToggleMarked", e
);
829 function getSelectedArticleIds2() {
833 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
835 rv
.push(child
.id
.replace("RROW-", ""));
841 function getLoadedArticleIds() {
844 var children
= $$("#headlines-frame > div[id*=RROW-]");
846 children
.each(function(child
) {
847 rv
.push(child
.id
.replace("RROW-", ""));
854 // mode = all,none,unread,invert,marked,published
855 function selectArticles(mode
) {
858 var children
= $$("#headlines-frame > div[id*=RROW]");
860 children
.each(function(child
) {
861 var id
= child
.id
.replace("RROW-", "");
862 var cb
= $("RCHK-" + id
);
865 child
.addClassName("Selected");
867 } else if (mode
== "unread") {
868 if (child
.hasClassName("Unread")) {
869 child
.addClassName("Selected");
872 child
.removeClassName("Selected");
875 } else if (mode
== "marked") {
876 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
878 if (img
&& img
.src
.match("mark_set")) {
879 child
.addClassName("Selected");
882 child
.removeClassName("Selected");
885 } else if (mode
== "published") {
886 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
888 if (img
&& img
.src
.match("pub_set")) {
889 child
.addClassName("Selected");
892 child
.removeClassName("Selected");
896 } else if (mode
== "invert") {
897 if (child
.hasClassName("Selected")) {
898 child
.removeClassName("Selected");
901 child
.addClassName("Selected");
906 child
.removeClassName("Selected");
912 exception_error("selectArticles", e
);
916 function catchupPage() {
918 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
920 var str
= __("Mark all visible articles in %s as read?");
922 str
= str
.replace("%s", fn
);
924 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
928 selectArticles('all');
929 selectionToggleUnread(false, 'viewCurrentFeed()', true);
930 selectArticles('none');
933 function deleteSelection() {
937 var rows
= getSelectedArticleIds2();
939 if (rows
.length
== 0) {
940 alert(__("No articles are selected."));
944 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
947 if (getActiveFeedId() != 0) {
948 str
= __("Delete %d selected articles in %s?");
950 str
= __("Delete %d selected articles?");
953 str
= str
.replace("%d", rows
.length
);
954 str
= str
.replace("%s", fn
);
956 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
960 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
964 new Ajax
.Request("backend.php", {
966 onComplete: function(transport
) {
967 handle_rpc_json(transport
);
972 exception_error("deleteSelection", e
);
976 function archiveSelection() {
980 var rows
= getSelectedArticleIds2();
982 if (rows
.length
== 0) {
983 alert(__("No articles are selected."));
987 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
991 if (getActiveFeedId() != 0) {
992 str
= __("Archive %d selected articles in %s?");
995 str
= __("Move %d archived articles back?");
999 str
= str
.replace("%d", rows
.length
);
1000 str
= str
.replace("%s", fn
);
1002 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1006 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1010 for (var i
= 0; i
< rows
.length
; i
++) {
1011 cache_delete("article:" + rows
[i
]);
1014 new Ajax
.Request("backend.php", {
1016 onComplete: function(transport
) {
1017 handle_rpc_json(transport
);
1022 exception_error("archiveSelection", e
);
1026 function catchupSelection() {
1030 var rows
= getSelectedArticleIds2();
1032 if (rows
.length
== 0) {
1033 alert(__("No articles are selected."));
1037 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1039 var str
= __("Mark %d selected articles in %s as read?");
1041 str
= str
.replace("%d", rows
.length
);
1042 str
= str
.replace("%s", fn
);
1044 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1048 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1051 exception_error("catchupSelection", e
);
1055 function editArticleTags(id
) {
1056 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1058 if (dijit
.byId("editTagsDlg"))
1059 dijit
.byId("editTagsDlg").destroyRecursive();
1061 dialog
= new dijit
.Dialog({
1063 title
: __("Edit article Tags"),
1064 style
: "width: 600px",
1065 execute: function() {
1066 if (this.validate()) {
1067 var query
= dojo
.objectToQuery(this.attr('value'));
1069 notify_progress("Saving article tags...", true);
1071 new Ajax
.Request("backend.php", {
1073 onComplete: function(transport
) {
1077 var data
= JSON
.parse(transport
.responseText
);
1080 var tags_str
= article
.tags
;
1081 var id
= tags_str
.id
;
1083 var tags
= $("ATSTR-" + id
);
1084 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1086 if (tags
) tags
.innerHTML
= tags_str
.content
;
1087 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1089 cache_delete("article:" + id
);
1098 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1099 dojo
.disconnect(tmph
);
1101 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1102 "backend.php?op=rpc&method=completeTags",
1103 { tokens
: ',', paramName
: "search" });
1110 function cdmScrollToArticleId(id
) {
1112 var ctr
= $("headlines-frame");
1113 var e
= $("RROW-" + id
);
1115 if (!e
|| !ctr
) return;
1117 ctr
.scrollTop
= e
.offsetTop
;
1120 exception_error("cdmScrollToArticleId", e
);
1124 function getActiveArticleId() {
1125 return active_post_id
;
1128 function postMouseIn(id
) {
1129 post_under_pointer
= id
;
1132 function postMouseOut(id
) {
1133 post_under_pointer
= false;
1136 function headlines_scroll_handler(e
) {
1138 var hsp
= $("headlines-spacer");
1140 if (!_infscroll_disable
) {
1141 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1142 (e
.scrollHeight
!= 0 &&
1143 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1146 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1147 __("Loading, please wait...");
1149 loadMoreHeadlines();
1154 if (hsp
) hsp
.innerHTML
= "";
1157 if (getInitParam("cdm_auto_catchup") == 1) {
1159 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1161 if ($("headlines-frame").scrollTop
>
1162 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1164 var id
= child
.id
.replace("RROW-", "");
1166 if (catchup_id_batch
.indexOf(id
) == -1)
1167 catchup_id_batch
.push(id
);
1169 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1173 if (catchup_id_batch
.length
> 0) {
1174 window
.clearTimeout(catchup_timeout_id
);
1176 if (!_infscroll_request_sent
) {
1177 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1184 console
.warn("headlines_scroll_handler: " + e
);
1188 function catchupBatchedArticles() {
1190 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1192 // make a copy of the array
1193 var batch
= catchup_id_batch
.slice();
1194 var query
= "?op=rpc&method=catchupSelected" +
1195 "&cmode=0&ids=" + param_escape(batch
.toString());
1199 new Ajax
.Request("backend.php", {
1201 onComplete: function(transport
) {
1202 handle_rpc_json(transport
);
1204 batch
.each(function(id
) {
1205 var elem
= $("RROW-" + id
);
1206 if (elem
) elem
.removeClassName("Unread");
1207 catchup_id_batch
.remove(id
);
1214 exception_error("catchupBatchedArticles", e
);
1218 function catchupRelativeToArticle(below
, id
) {
1222 if (!id
) id
= getActiveArticleId();
1225 alert(__("No article is selected."));
1229 var visible_ids
= getVisibleArticleIds();
1231 var ids_to_mark
= new Array();
1234 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1235 if (visible_ids
[i
] != id
) {
1236 var e
= $("RROW-" + visible_ids
[i
]);
1238 if (e
&& e
.hasClassName("Unread")) {
1239 ids_to_mark
.push(visible_ids
[i
]);
1246 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1247 if (visible_ids
[i
] != id
) {
1248 var e
= $("RROW-" + visible_ids
[i
]);
1250 if (e
&& e
.hasClassName("Unread")) {
1251 ids_to_mark
.push(visible_ids
[i
]);
1259 if (ids_to_mark
.length
== 0) {
1260 alert(__("No articles found to mark"));
1262 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1264 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1266 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1267 var e
= $("RROW-" + ids_to_mark
[i
]);
1268 e
.removeClassName("Unread");
1271 var query
= "?op=rpc&method=catchupSelected" +
1272 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1274 new Ajax
.Request("backend.php", {
1276 onComplete: function(transport
) {
1277 handle_rpc_json(transport
);
1284 exception_error("catchupRelativeToArticle", e
);
1288 function cdmExpandArticle(id
) {
1293 var elem
= $("CICD-" + active_post_id
);
1295 var upd_img_pic
= $("FUPDPIC-" + id
);
1297 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1298 upd_img_pic
.src
.match("fresh_sign.png"))) {
1300 upd_img_pic
.src
= "images/blank_icon.gif";
1303 if (id
== active_post_id
&& Element
.visible(elem
))
1306 selectArticles("none");
1308 var old_offset
= $("RROW-" + id
).offsetTop
;
1310 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1312 Element
.show("CEXC-" + active_post_id
);
1315 active_post_id
= id
;
1317 elem
= $("CICD-" + id
);
1319 if (!Element
.visible(elem
)) {
1321 Element
.hide("CEXC-" + id
);
1323 if ($("CWRAP-" + id
).innerHTML
== "") {
1325 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1327 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1328 __("Loading, please wait...") + "</div>";
1330 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1332 var neighbor_ids
= getRelativePostIds(id
);
1334 /* only request uncached articles */
1335 var cids_to_request
= [];
1337 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1338 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1339 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1340 cids_to_request
.push(neighbor_ids
[i
]);
1341 cids_requested
.push(neighbor_ids
[i
]);
1345 console
.log("additional ids: " + cids_to_request
.toString());
1347 query
= query
+ "&cids=" + cids_to_request
.toString();
1351 new Ajax
.Request("backend.php", {
1353 onComplete: function(transport
) {
1355 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1357 handle_rpc_json(transport
);
1359 var reply
= JSON
.parse(transport
.responseText
);
1361 reply
.each(function(article
) {
1362 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1363 cids_requested
.remove(article
['id']);
1370 var new_offset
= $("RROW-" + id
).offsetTop
;
1372 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1374 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1375 $("headlines-frame").scrollTop
= new_offset
;
1377 toggleUnread(id
, 0, true);
1381 exception_error("cdmExpandArticle", e
);
1387 function fixHeadlinesOrder(ids
) {
1389 for (var i
= 0; i
< ids
.length
; i
++) {
1390 var e
= $("RROW-" + ids
[i
]);
1394 e
.removeClassName("even");
1395 e
.addClassName("odd");
1397 e
.removeClassName("odd");
1398 e
.addClassName("even");
1403 exception_error("fixHeadlinesOrder", e
);
1407 function getArticleUnderPointer() {
1408 return post_under_pointer
;
1411 function zoomToArticle(event
, id
) {
1413 var cached_article
= cache_get("article: " + id
);
1415 if (dijit
.byId("ATAB-" + id
))
1416 if (!event
|| !event
.shiftKey
)
1417 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1419 if (dijit
.byId("ATSTRTIP-" + id
))
1420 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1422 if (cached_article
) {
1423 //closeArticlePanel();
1425 var article_pane
= new dijit
.layout
.ContentPane({
1426 title
: __("Loading...") , content
: cached_article
,
1427 style
: 'padding : 0px;',
1431 dijit
.byId("content-tabs").addChild(article_pane
);
1433 if (!event
|| !event
.shiftKey
)
1434 dijit
.byId("content-tabs").selectChild(article_pane
);
1436 if ($("PTITLE-" + id
))
1437 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1441 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1443 notify_progress("Loading, please wait...", true);
1445 new Ajax
.Request("backend.php", {
1447 onComplete: function(transport
) {
1450 var reply
= JSON
.parse(transport
.responseText
);
1453 //closeArticlePanel();
1455 var content
= reply
[0]['content'];
1457 var article_pane
= new dijit
.layout
.ContentPane({
1458 title
: "article-" + id
, content
: content
,
1459 style
: 'padding : 0px;',
1463 dijit
.byId("content-tabs").addChild(article_pane
);
1465 if (!event
|| !event
.shiftKey
)
1466 dijit
.byId("content-tabs").selectChild(article_pane
);
1468 if ($("PTITLE-" + id
))
1469 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1476 exception_error("zoomToArticle", e
);
1480 function scrollArticle(offset
) {
1483 var ci
= $("content-insert");
1485 ci
.scrollTop
+= offset
;
1488 var hi
= $("headlines-frame");
1490 hi
.scrollTop
+= offset
;
1495 exception_error("scrollArticle", e
);
1499 function show_labels_in_headlines(transport
) {
1501 var data
= JSON
.parse(transport
.responseText
);
1504 data
['info-for-headlines'].each(function(elem
) {
1505 var ctr
= $("HLLCTR-" + elem
.id
);
1507 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1510 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1514 exception_error("show_labels_in_headlines", e
);
1518 /* function toggleHeadlineActions() {
1520 var e = $("headlineActionsBody");
1521 var p = $("headlineActionsDrop");
1523 if (!Element.visible(e)) {
1530 e.style.left = (p.offsetLeft + 1) + "px";
1531 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1534 exception_error("toggleHeadlineActions", e);
1538 /* function publishWithNote(id, def_note) {
1540 if (!def_note) def_note = '';
1542 var note = prompt(__("Please enter a note for this article:"), def_note);
1544 if (note != undefined) {
1545 togglePub(id, false, false, note);
1549 exception_error("publishWithNote", e);
1553 function dismissArticle(id
) {
1555 var elem
= $("RROW-" + id
);
1557 toggleUnread(id
, 0, true);
1559 new Effect
.Fade(elem
, {duration
: 0.5});
1561 active_post_id
= false;
1564 exception_error("dismissArticle", e
);
1568 function dismissSelectedArticles() {
1571 var ids
= getVisibleArticleIds();
1575 for (var i
= 0; i
< ids
.length
; i
++) {
1576 var elem
= $("RROW-" + ids
[i
]);
1578 if (elem
.className
&& elem
.hasClassName("Selected") &&
1579 ids
[i
] != active_post_id
) {
1580 new Effect
.Fade(elem
, {duration
: 0.5});
1588 selectionToggleUnread(false);
1590 fixHeadlinesOrder(tmp
);
1593 exception_error("dismissSelectedArticles", e
);
1597 function dismissReadArticles() {
1600 var ids
= getVisibleArticleIds();
1603 for (var i
= 0; i
< ids
.length
; i
++) {
1604 var elem
= $("RROW-" + ids
[i
]);
1606 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1607 !elem
.hasClassName("Selected")) {
1609 new Effect
.Fade(elem
, {duration
: 0.5});
1615 fixHeadlinesOrder(tmp
);
1618 exception_error("dismissSelectedArticles", e
);
1622 function getVisibleArticleIds() {
1627 getLoadedArticleIds().each(function(id
) {
1628 var elem
= $("RROW-" + id
);
1629 if (elem
&& Element
.visible(elem
))
1634 exception_error("getVisibleArticleIds", e
);
1640 function cdmClicked(event
, id
) {
1642 //var shift_key = event.shiftKey;
1646 if (!event
.ctrlKey
) {
1648 if (!getInitParam("cdm_expanded")) {
1649 return cdmExpandArticle(id
);
1652 selectArticles("none");
1655 var elem
= $("RROW-" + id
);
1656 var article_is_unread
= elem
.hasClassName("Unread");
1659 elem
.removeClassName("Unread");
1661 var upd_img_pic
= $("FUPDPIC-" + id
);
1663 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1664 upd_img_pic
.src
.match("fresh_sign.png"))) {
1666 upd_img_pic
.src
= "images/blank_icon.gif";
1669 active_post_id
= id
;
1671 if (article_is_unread
) {
1672 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1675 var query
= "?op=rpc&method=catchupSelected" +
1676 "&cmode=0&ids=" + param_escape(id
);
1678 new Ajax
.Request("backend.php", {
1680 onComplete: function(transport
) {
1681 handle_rpc_json(transport
);
1688 toggleSelected(id
, true);
1690 var elem
= $("RROW-" + id
);
1691 var article_is_unread
= elem
.hasClassName("Unread");
1693 if (article_is_unread
) {
1694 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1697 toggleUnread(id
, 0, false);
1698 zoomToArticle(event
, id
);
1702 exception_error("cdmClicked");
1708 function postClicked(event
, id
) {
1711 if (!event
.ctrlKey
) {
1714 postOpenInNewTab(event
, id
);
1719 exception_error("postClicked");
1723 function hlOpenInNewTab(event
, id
) {
1724 toggleUnread(id
, 0, false);
1725 zoomToArticle(event
, id
);
1728 function postOpenInNewTab(event
, id
) {
1729 closeArticlePanel(id
);
1730 zoomToArticle(event
, id
);
1733 function hlClicked(event
, id
) {
1735 if (event
.which
== 2) {
1738 } else if (event
.altKey
) {
1739 openArticleInNewWindow(id
);
1740 } else if (!event
.ctrlKey
) {
1745 toggleUnread(id
, 0, false);
1746 zoomToArticle(event
, id
);
1751 exception_error("hlClicked");
1755 function getFirstVisibleHeadlineId() {
1756 var rows
= getVisibleArticleIds();
1761 function getLastVisibleHeadlineId() {
1762 var rows
= getVisibleArticleIds();
1763 return rows
[rows
.length
-1];
1766 function openArticleInNewWindow(id
) {
1767 toggleUnread(id
, 0, false);
1768 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1771 function isCdmMode() {
1772 return getInitParam("combined_display_mode");
1775 function markHeadline(id
) {
1776 var row
= $("RROW-" + id
);
1778 var check
= $("RCHK-" + id
);
1781 check
.checked
= true;
1784 row
.addClassName("Selected");
1788 function getRelativePostIds(id
, limit
) {
1794 if (!limit
) limit
= 6; //3
1796 var ids
= getVisibleArticleIds();
1798 for (var i
= 0; i
< ids
.length
; i
++) {
1800 for (var k
= 1; k
<= limit
; k
++) {
1801 //if (i > k-1) tmp.push(ids[i-k]);
1802 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1809 exception_error("getRelativePostIds", e
);
1815 function correctHeadlinesOffset(id
) {
1819 var container
= $("headlines-frame");
1820 var row
= $("RROW-" + id
);
1822 if (!container
|| !row
) return;
1824 var viewport
= container
.offsetHeight
;
1826 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1827 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1829 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1830 //console.log("Vport: " + viewport);
1832 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1833 container
.scrollTop
= row
.offsetTop
;
1834 } else if (rel_offset_bottom
> viewport
) {
1836 /* doesn't properly work with Opera in some cases because
1837 Opera fucks up element scrolling */
1839 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1843 exception_error("correctHeadlinesOffset", e
);
1848 function headlineActionsChange(elem
) {
1851 elem
.attr('value', 'false');
1853 exception_error("headlineActionsChange", e
);
1857 function closeArticlePanel() {
1859 var tabs
= dijit
.byId("content-tabs");
1860 var child
= tabs
.selectedChildWidget
;
1862 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1863 tabs
.removeChild(child
);
1866 if (dijit
.byId("content-insert"))
1867 dijit
.byId("headlines-wrap-inner").removeChild(
1868 dijit
.byId("content-insert"));
1872 function initHeadlinesMenu() {
1874 if (dijit
.byId("headlinesMenu"))
1875 dijit
.byId("headlinesMenu").destroyRecursive();
1880 nodes
= $$("#headlines-frame > div[id*=RROW]");
1882 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1885 nodes
.each(function(node
) {
1889 var menu
= new dijit
.Menu({
1890 id
: "headlinesMenu",
1894 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1895 var callerNode
= event
.target
, match
= null, tries
= 0;
1897 while (match
== null && callerNode
&& tries
<= 3) {
1898 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1899 callerNode
= callerNode
.parentNode
;
1903 if (match
) this.callerRowId
= parseInt(match
[1]);
1907 /* if (!isCdmMode())
1908 menu.addChild(new dijit.MenuItem({
1909 label: __("View article"),
1910 onClick: function(event) {
1911 view(this.getParent().callerRowId);
1914 menu
.addChild(new dijit
.MenuItem({
1915 label
: __("Open original article"),
1916 onClick: function(event
) {
1917 openArticleInNewWindow(this.getParent().callerRowId
);
1920 menu
.addChild(new dijit
.MenuItem({
1921 label
: __("View in a tt-rss tab"),
1922 onClick: function(event
) {
1923 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1926 menu
.addChild(new dijit
.MenuSeparator());
1928 menu
.addChild(new dijit
.MenuItem({
1929 label
: __("Mark above as read"),
1930 onClick: function(event
) {
1931 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1934 menu
.addChild(new dijit
.MenuItem({
1935 label
: __("Mark below as read"),
1936 onClick: function(event
) {
1937 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1941 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1945 menu
.addChild(new dijit
.MenuSeparator());
1947 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1948 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1950 labels
.each(function(label
) {
1951 var id
= label
.id
[0];
1952 var bare_id
= id
.substr(id
.indexOf(":")+1);
1953 var name
= label
.name
[0];
1955 bare_id
= -11-bare_id
;
1957 labelAddMenu
.addChild(new dijit
.MenuItem({
1960 onClick: function(event
) {
1961 var ids
= getSelectedArticleIds2();
1963 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1965 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1967 selectionAssignLabel(this.labelId
, ids
);
1970 labelDelMenu
.addChild(new dijit
.MenuItem({
1973 onClick: function(event
) {
1974 var ids
= getSelectedArticleIds2();
1976 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1978 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1980 selectionRemoveLabel(this.labelId
, ids
);
1985 menu
.addChild(new dijit
.PopupMenuItem({
1986 label
: __("Assign label"),
1987 popup
: labelAddMenu
,
1990 menu
.addChild(new dijit
.PopupMenuItem({
1991 label
: __("Remove label"),
1992 popup
: labelDelMenu
,
2000 exception_error("initHeadlinesMenu", e
);
2005 function player(elem
) {
2006 var aid
= elem
.getAttribute("audio-id");
2007 var status
= elem
.getAttribute("status");
2015 elem
.innerHTML
= __("Playing...");
2016 elem
.title
= __("Click to pause");
2017 elem
.addClassName("playing");
2021 elem
.innerHTML
= __("Play");
2022 elem
.title
= __("Click to play");
2023 elem
.removeClassName("playing");
2026 elem
.setAttribute("status", status
);
2028 alert("Your browser doesn't seem to support HTML5 audio.");
2032 function cache_set(id
, obj
) {
2033 //console.log("cache_set: " + id);
2036 sessionStorage
[id
] = obj
;
2038 sessionStorage
.clear();
2042 function cache_get(id
) {
2044 return sessionStorage
[id
];
2047 function cache_clear() {
2049 sessionStorage
.clear();
2052 function cache_delete(id
) {
2054 sessionStorage
.removeItem(id
);
2057 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2058 if (toolbar_obj
&& content_obj
) {
2059 cache_set("feed:" + feed
+ ":" + is_cat
,
2060 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2063 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2066 obj
= JSON
.parse(obj
);
2068 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2069 if (content_obj
) obj
.content
= content_obj
;
2071 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2075 console
.warn("cache_headlines failed: " + e
);
2080 function render_local_headlines(feed
, is_cat
, obj
) {
2083 dijit
.byId("headlines-toolbar").attr('content',
2086 dijit
.byId("headlines-frame").attr('content',
2089 dojo
.parser
.parse('headlines-toolbar');
2091 $("headlines-frame").scrollTop
= 0;
2092 selectArticles('none');
2093 setActiveFeedId(feed
, is_cat
);
2094 initHeadlinesMenu();
2096 precache_headlines();
2099 exception_error("render_local_headlines", e
);
2103 function precache_headlines_idle() {
2105 if (!feed_precache_timeout_id
) {
2106 if (get_timestamp() - _viewfeed_last
> 120) {
2108 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2111 feeds
.each(function(item
) {
2112 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2113 uncached
.push(item
);
2116 if (uncached
.length
> 0) {
2117 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2118 viewfeed(rf
[0], '', rf
[1], 0, true);
2122 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2125 exception_error("precache_headlines_idle", e
);
2129 function precache_headlines() {
2132 if (!feed_precache_timeout_id
) {
2133 feed_precache_timeout_id
= window
.setTimeout(function() {
2134 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2135 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2137 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2138 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2140 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2141 viewfeed(nf
[0], '', nf
[1], 0, true);
2143 window
.setTimeout(function() {
2144 feed_precache_timeout_id
= false;
2150 exception_error("precache_headlines", e
);