]>
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']);
84 if (getInitParam("cdm_auto_catchup") == 1) {
85 var hsp
= $("headlines-spacer");
86 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
87 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
94 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
95 console
.log("adding some more headlines...");
97 var c
= dijit
.byId("headlines-frame");
98 var ids
= getSelectedArticleIds2();
100 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
102 var hsp
= $("headlines-spacer");
105 c
.domNode
.removeChild(hsp
);
107 $$("#headlines-tmp > div").each(function(row
) {
108 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
109 row
.style
.display
= 'none';
110 c
.domNode
.appendChild(row
);
112 row
.parentNode
.removeChild(row
);
116 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
118 fixHeadlinesOrder(getLoadedArticleIds());
120 if (getInitParam("cdm_auto_catchup") == 1) {
121 c
.domNode
.appendChild(hsp
);
124 console
.log("restore selected ids: " + ids
);
126 for (var i
= 0; i
< ids
.length
; i
++) {
127 markHeadline(ids
[i
]);
132 $$("#headlines-frame > div[id*=RROW]").each(
134 if (!Element
.visible(child
))
135 new Effect
.Appear(child
, { duration
: 0.5 });
139 console
.log("no new headlines received");
141 var hsp
= $("headlines-spacer");
143 if (hsp
) hsp
.innerHTML
= "";
147 if (headlines_count
> 0)
148 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
151 for (var i
= 0; i
< articles
.length
; i
++) {
152 var a_id
= articles
[i
]['id'];
153 cache_set("article:" + a_id
, articles
[i
]['content']);
156 console
.log("no cached articles received");
159 // do not precache stuff after fresh feed
161 precache_headlines();
164 parse_counters(counters
);
169 console
.error("Invalid object received: " + transport
.responseText
);
170 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
171 __('Could not update headlines (invalid object received - see error console for details)') +
175 _infscroll_request_sent
= 0;
180 exception_error("headlines_callback2", e
, transport
);
184 function render_article(article
) {
186 dijit
.byId("headlines-wrap-inner").addChild(
187 dijit
.byId("content-insert"));
189 var c
= dijit
.byId("content-insert");
192 c
.domNode
.scrollTop
= 0;
195 c
.attr('content', article
);
197 correctHeadlinesOffset(getActiveArticleId());
204 exception_error("render_article", e
);
208 function showArticleInHeadlines(id
) {
212 selectArticles("none");
214 var crow
= $("RROW-" + id
);
218 var article_is_unread
= crow
.hasClassName("Unread");
220 crow
.removeClassName("Unread");
222 selectArticles('none');
224 var upd_img_pic
= $("FUPDPIC-" + id
);
226 var view_mode
= false;
229 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
230 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
235 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
236 upd_img_pic
.src
.match("fresh_sign.png"))) {
238 upd_img_pic
.src
= "images/blank_icon.gif";
240 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
242 } else if (article_is_unread
&& view_mode
== "all_articles") {
243 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
248 if (article_is_unread
)
249 _force_scheduled_update
= true;
252 exception_error("showArticleInHeadlines", e
);
256 function article_callback2(transport
, id
) {
258 console
.log("article_callback2 " + id
);
260 handle_rpc_json(transport
);
265 reply
= JSON
.parse(transport
.responseText
);
272 var upic
= $('FUPDPIC-' + id
);
274 if (upic
) upic
.src
= 'images/blank_icon.gif';
276 reply
.each(function(article
) {
277 if (active_post_id
== article
['id']) {
278 render_article(article
['content']);
280 cids_requested
.remove(article
['id']);
282 cache_set("article:" + article
['id'], article
['content']);
285 // if (id != last_requested_article) {
286 // console.log("requested article id is out of sequence, aborting");
291 console
.error("Invalid object received: " + transport
.responseText
);
293 render_article("<div class='whiteBox'>" +
294 __('Could not display article (invalid object received - see error console for details)') + "</div>");
300 if (!_infscroll_disable
&&
301 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
311 exception_error("article_callback2", e
, transport
);
317 console
.log("loading article: " + id
);
319 var cached_article
= cache_get("article:" + id
);
321 console
.log("cache check result: " + (cached_article
!= false));
325 var query
= "?op=article&method=view&id=" + param_escape(id
);
327 var neighbor_ids
= getRelativePostIds(id
);
329 /* only request uncached articles */
331 var cids_to_request
= [];
333 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
334 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
335 if (!cache_get("article:" + neighbor_ids
[i
])) {
336 cids_to_request
.push(neighbor_ids
[i
]);
337 cids_requested
.push(neighbor_ids
[i
]);
341 console
.log("additional ids: " + cids_to_request
.toString());
343 query
= query
+ "&cids=" + cids_to_request
.toString();
345 var crow
= $("RROW-" + id
);
346 var article_is_unread
= crow
.hasClassName("Unread");
349 showArticleInHeadlines(id
);
351 precache_headlines();
353 if (!cached_article
) {
355 var upic
= $('FUPDPIC-' + id
);
358 upic
.src
= getInitParam("sign_progress");
361 } else if (cached_article
&& article_is_unread
) {
363 query
= query
+ "&mode=prefetch";
365 render_article(cached_article
);
367 } else if (cached_article
) {
369 query
= query
+ "&mode=prefetch_old";
370 render_article(cached_article
);
372 // if we don't need to request any relative ids, we might as well skip
373 // the server roundtrip altogether
374 if (cids_to_request
.length
== 0) {
377 if (!_infscroll_disable
&&
378 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
390 last_requested_article
= id
;
394 new Ajax
.Request("backend.php", {
396 onComplete: function(transport
) {
397 article_callback2(transport
, id
);
403 exception_error("view", e
);
407 function toggleMark(id
, client_only
) {
409 var query
= "?op=rpc&id=" + id
+ "&method=mark";
411 var img
= $("FMPIC-" + id
);
415 if (img
.src
.match("mark_unset")) {
416 img
.src
= img
.src
.replace("mark_unset", "mark_set");
417 img
.alt
= __("Unstar article");
418 query
= query
+ "&mark=1";
421 img
.src
= img
.src
.replace("mark_set", "mark_unset");
422 img
.alt
= __("Star article");
423 query
= query
+ "&mark=0";
426 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
429 new Ajax
.Request("backend.php", {
431 onComplete: function(transport
) {
432 handle_rpc_json(transport
);
437 exception_error("toggleMark", e
);
441 function togglePub(id
, client_only
, no_effects
, note
) {
443 var query
= "?op=rpc&id=" + id
+ "&method=publ";
445 if (note
!= undefined) {
446 query
= query
+ "¬e=" + param_escape(note
);
448 query
= query
+ "¬e=undefined";
451 var img
= $("FPPIC-" + id
);
455 if (img
.src
.match("pub_unset") || note
!= undefined) {
456 img
.src
= img
.src
.replace("pub_unset", "pub_set");
457 img
.alt
= __("Unpublish article");
458 query
= query
+ "&pub=1";
461 img
.src
= img
.src
.replace("pub_set", "pub_unset");
462 img
.alt
= __("Publish article");
464 query
= query
+ "&pub=0";
467 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
470 new Ajax
.Request("backend.php", {
472 onComplete: function(transport
) {
473 handle_rpc_json(transport
);
478 exception_error("togglePub", e
);
482 function moveToPost(mode
) {
486 var rows
= getVisibleArticleIds();
491 if (!$('RROW-' + active_post_id
)) {
492 active_post_id
= false;
495 if (active_post_id
== false) {
497 prev_id
= rows
[rows
.length
-1]
499 for (var i
= 0; i
< rows
.length
; i
++) {
500 if (rows
[i
] == active_post_id
) {
502 // Account for adjacent identical article ids.
503 if (i
> 0) prev_id
= rows
[i
-1];
505 for (var j
= i
+1; j
< rows
.length
; j
++) {
506 if (rows
[j
] != active_post_id
) {
516 if (mode
== "next") {
520 cdmExpandArticle(next_id
);
521 cdmScrollToArticleId(next_id
);
524 correctHeadlinesOffset(next_id
);
525 view(next_id
, getActiveFeedId());
530 if (mode
== "prev") {
533 cdmExpandArticle(prev_id
);
534 cdmScrollToArticleId(prev_id
);
536 correctHeadlinesOffset(prev_id
);
537 view(prev_id
, getActiveFeedId());
543 exception_error("moveToPost", e
);
547 function toggleSelected(id
, force_on
) {
550 var cb
= $("RCHK-" + id
);
551 var row
= $("RROW-" + id
);
554 if (row
.hasClassName('Selected') && !force_on
) {
555 row
.removeClassName('Selected');
556 if (cb
) cb
.checked
= false;
558 row
.addClassName('Selected');
559 if (cb
) cb
.checked
= true;
563 exception_error("toggleSelected", e
);
567 function toggleUnread_afh(effect
) {
570 var elem
= effect
.element
;
571 elem
.style
.backgroundColor
= "";
574 exception_error("toggleUnread_afh", e
);
578 function toggleUnread(id
, cmode
, effect
) {
581 var row
= $("RROW-" + id
);
583 if (cmode
== undefined || cmode
== 2) {
584 if (row
.hasClassName("Unread")) {
585 row
.removeClassName("Unread");
588 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
589 afterFinish
: toggleUnread_afh
,
590 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
594 row
.addClassName("Unread");
597 } else if (cmode
== 0) {
599 row
.removeClassName("Unread");
602 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
603 afterFinish
: toggleUnread_afh
,
604 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
607 } else if (cmode
== 1) {
608 row
.addClassName("Unread");
611 if (cmode
== undefined) cmode
= 2;
613 var query
= "?op=rpc&method=catchupSelected" +
614 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
616 // notify_progress("Loading, please wait...");
618 new Ajax
.Request("backend.php", {
620 onComplete: function(transport
) {
621 handle_rpc_json(transport
);
627 exception_error("toggleUnread", e
);
631 function selectionRemoveLabel(id
, ids
) {
634 if (!ids
) ids
= getSelectedArticleIds2();
636 if (ids
.length
== 0) {
637 alert(__("No articles are selected."));
641 var query
= "?op=rpc&method=removeFromLabel&ids=" +
642 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
646 new Ajax
.Request("backend.php", {
648 onComplete: function(transport
) {
649 handle_rpc_json(transport
);
650 show_labels_in_headlines(transport
);
654 exception_error("selectionAssignLabel", e
);
659 function selectionAssignLabel(id
, ids
) {
662 if (!ids
) ids
= getSelectedArticleIds2();
664 if (ids
.length
== 0) {
665 alert(__("No articles are selected."));
669 var query
= "?op=rpc&method=assignToLabel&ids=" +
670 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
674 new Ajax
.Request("backend.php", {
676 onComplete: function(transport
) {
677 handle_rpc_json(transport
);
678 show_labels_in_headlines(transport
);
682 exception_error("selectionAssignLabel", e
);
687 function selectionToggleUnread(set_state
, callback
, no_error
) {
689 var rows
= getSelectedArticleIds2();
691 if (rows
.length
== 0 && !no_error
) {
692 alert(__("No articles are selected."));
696 for (var i
= 0; i
< rows
.length
; i
++) {
697 var row
= $("RROW-" + rows
[i
]);
699 if (set_state
== undefined) {
700 if (row
.hasClassName("Unread")) {
701 row
.removeClassName("Unread");
703 row
.addClassName("Unread");
707 if (set_state
== false) {
708 row
.removeClassName("Unread");
711 if (set_state
== true) {
712 row
.addClassName("Unread");
717 if (rows
.length
> 0) {
721 if (set_state
== undefined) {
723 } else if (set_state
== true) {
725 } else if (set_state
== false) {
729 var query
= "?op=rpc&method=catchupSelected" +
730 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
732 notify_progress("Loading, please wait...");
734 new Ajax
.Request("backend.php", {
736 onComplete: function(transport
) {
737 handle_rpc_json(transport
);
738 if (callback
) callback(transport
);
744 exception_error("selectionToggleUnread", e
);
748 function selectionToggleMarked() {
751 var rows
= getSelectedArticleIds2();
753 if (rows
.length
== 0) {
754 alert(__("No articles are selected."));
758 for (var i
= 0; i
< rows
.length
; i
++) {
759 toggleMark(rows
[i
], true, true);
762 if (rows
.length
> 0) {
764 var query
= "?op=rpc&method=markSelected&ids=" +
765 param_escape(rows
.toString()) + "&cmode=2";
767 new Ajax
.Request("backend.php", {
769 onComplete: function(transport
) {
770 handle_rpc_json(transport
);
776 exception_error("selectionToggleMarked", e
);
780 function selectionTogglePublished() {
783 var rows
= getSelectedArticleIds2();
785 if (rows
.length
== 0) {
786 alert(__("No articles are selected."));
790 for (var i
= 0; i
< rows
.length
; i
++) {
791 togglePub(rows
[i
], true, true);
794 if (rows
.length
> 0) {
796 var query
= "?op=rpc&method=publishSelected&ids=" +
797 param_escape(rows
.toString()) + "&cmode=2";
799 new Ajax
.Request("backend.php", {
801 onComplete: function(transport
) {
802 handle_rpc_json(transport
);
808 exception_error("selectionToggleMarked", e
);
812 function getSelectedArticleIds2() {
816 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
818 rv
.push(child
.id
.replace("RROW-", ""));
824 function getLoadedArticleIds() {
827 var children
= $$("#headlines-frame > div[id*=RROW-]");
829 children
.each(function(child
) {
830 rv
.push(child
.id
.replace("RROW-", ""));
837 // mode = all,none,unread,invert
838 function selectArticles(mode
) {
841 var children
= $$("#headlines-frame > div[id*=RROW]");
843 children
.each(function(child
) {
844 var id
= child
.id
.replace("RROW-", "");
845 var cb
= $("RCHK-" + id
);
848 child
.addClassName("Selected");
850 } else if (mode
== "unread") {
851 if (child
.hasClassName("Unread")) {
852 child
.addClassName("Selected");
855 child
.removeClassName("Selected");
858 } else if (mode
== "invert") {
859 if (child
.hasClassName("Selected")) {
860 child
.removeClassName("Selected");
863 child
.addClassName("Selected");
868 child
.removeClassName("Selected");
874 exception_error("selectArticles", e
);
878 function catchupPage() {
880 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
882 var str
= __("Mark all visible articles in %s as read?");
884 str
= str
.replace("%s", fn
);
886 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
890 selectArticles('all');
891 selectionToggleUnread(false, 'viewCurrentFeed()', true);
892 selectArticles('none');
895 function deleteSelection() {
899 var rows
= getSelectedArticleIds2();
901 if (rows
.length
== 0) {
902 alert(__("No articles are selected."));
906 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
909 if (getActiveFeedId() != 0) {
910 str
= __("Delete %d selected articles in %s?");
912 str
= __("Delete %d selected articles?");
915 str
= str
.replace("%d", rows
.length
);
916 str
= str
.replace("%s", fn
);
918 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
922 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
926 new Ajax
.Request("backend.php", {
928 onComplete: function(transport
) {
929 handle_rpc_json(transport
);
934 exception_error("deleteSelection", e
);
938 function archiveSelection() {
942 var rows
= getSelectedArticleIds2();
944 if (rows
.length
== 0) {
945 alert(__("No articles are selected."));
949 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
953 if (getActiveFeedId() != 0) {
954 str
= __("Archive %d selected articles in %s?");
957 str
= __("Move %d archived articles back?");
961 str
= str
.replace("%d", rows
.length
);
962 str
= str
.replace("%s", fn
);
964 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
968 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
972 for (var i
= 0; i
< rows
.length
; i
++) {
973 cache_delete("article:" + rows
[i
]);
976 new Ajax
.Request("backend.php", {
978 onComplete: function(transport
) {
979 handle_rpc_json(transport
);
984 exception_error("archiveSelection", e
);
988 function catchupSelection() {
992 var rows
= getSelectedArticleIds2();
994 if (rows
.length
== 0) {
995 alert(__("No articles are selected."));
999 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1001 var str
= __("Mark %d selected articles in %s as read?");
1003 str
= str
.replace("%d", rows
.length
);
1004 str
= str
.replace("%s", fn
);
1006 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1010 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1013 exception_error("catchupSelection", e
);
1017 function editArticleTags(id
) {
1018 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1020 if (dijit
.byId("editTagsDlg"))
1021 dijit
.byId("editTagsDlg").destroyRecursive();
1023 dialog
= new dijit
.Dialog({
1025 title
: __("Edit article Tags"),
1026 style
: "width: 600px",
1027 execute: function() {
1028 if (this.validate()) {
1029 var query
= dojo
.objectToQuery(this.attr('value'));
1031 notify_progress("Saving article tags...", true);
1033 new Ajax
.Request("backend.php", {
1035 onComplete: function(transport
) {
1039 var data
= JSON
.parse(transport
.responseText
);
1042 var tags_str
= article
.tags
;
1043 var id
= tags_str
.id
;
1045 var tags
= $("ATSTR-" + id
);
1046 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1048 if (tags
) tags
.innerHTML
= tags_str
.content
;
1049 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1051 cache_delete("article:" + id
);
1060 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1061 dojo
.disconnect(tmph
);
1063 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1064 "backend.php?op=rpc&method=completeTags",
1065 { tokens
: ',', paramName
: "search" });
1072 function cdmScrollToArticleId(id
) {
1074 var ctr
= $("headlines-frame");
1075 var e
= $("RROW-" + id
);
1077 if (!e
|| !ctr
) return;
1079 ctr
.scrollTop
= e
.offsetTop
;
1082 exception_error("cdmScrollToArticleId", e
);
1086 function getActiveArticleId() {
1087 return active_post_id
;
1090 function postMouseIn(id
) {
1091 post_under_pointer
= id
;
1094 function postMouseOut(id
) {
1095 post_under_pointer
= false;
1098 function headlines_scroll_handler(e
) {
1100 var hsp
= $("headlines-spacer");
1102 if (!_infscroll_disable
) {
1103 if (hsp
&& (e
.scrollTop
+ e
.offsetHeight
> hsp
.offsetTop
) ||
1104 e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1107 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1108 __("Loading, please wait...");
1110 loadMoreHeadlines();
1115 if (hsp
) hsp
.innerHTML
= "";
1118 if (getInitParam("cdm_auto_catchup") == 1) {
1120 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1122 if ($("headlines-frame").scrollTop
>
1123 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1125 var id
= child
.id
.replace("RROW-", "");
1127 if (catchup_id_batch
.indexOf(id
) == -1)
1128 catchup_id_batch
.push(id
);
1130 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1134 if (catchup_id_batch
.length
> 0) {
1135 window
.clearTimeout(catchup_timeout_id
);
1137 if (!_infscroll_request_sent
) {
1138 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1145 console
.warn("headlines_scroll_handler: " + e
);
1149 function catchupBatchedArticles() {
1151 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1153 var query
= "?op=rpc&method=catchupSelected" +
1154 "&cmode=0&ids=" + param_escape(catchup_id_batch
.toString());
1156 new Ajax
.Request("backend.php", {
1158 onComplete: function(transport
) {
1159 handle_rpc_json(transport
);
1161 catchup_id_batch
.each(function(id
) {
1162 var elem
= $("RROW-" + id
);
1163 if (elem
) elem
.removeClassName("Unread");
1166 catchup_id_batch
= [];
1171 exception_error("catchupBatchedArticles", e
);
1175 function catchupRelativeToArticle(below
, id
) {
1179 if (!id
) id
= getActiveArticleId();
1182 alert(__("No article is selected."));
1186 var visible_ids
= getVisibleArticleIds();
1188 var ids_to_mark
= new Array();
1191 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1192 if (visible_ids
[i
] != id
) {
1193 var e
= $("RROW-" + visible_ids
[i
]);
1195 if (e
&& e
.hasClassName("Unread")) {
1196 ids_to_mark
.push(visible_ids
[i
]);
1203 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1204 if (visible_ids
[i
] != id
) {
1205 var e
= $("RROW-" + visible_ids
[i
]);
1207 if (e
&& e
.hasClassName("Unread")) {
1208 ids_to_mark
.push(visible_ids
[i
]);
1216 if (ids_to_mark
.length
== 0) {
1217 alert(__("No articles found to mark"));
1219 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1221 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1223 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1224 var e
= $("RROW-" + ids_to_mark
[i
]);
1225 e
.removeClassName("Unread");
1228 var query
= "?op=rpc&method=catchupSelected" +
1229 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1231 new Ajax
.Request("backend.php", {
1233 onComplete: function(transport
) {
1234 handle_rpc_json(transport
);
1241 exception_error("catchupRelativeToArticle", e
);
1245 function cdmExpandArticle(id
) {
1250 var elem
= $("CICD-" + active_post_id
);
1252 var upd_img_pic
= $("FUPDPIC-" + id
);
1254 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1255 upd_img_pic
.src
.match("fresh_sign.png"))) {
1257 upd_img_pic
.src
= "images/blank_icon.gif";
1260 if (id
== active_post_id
&& Element
.visible(elem
))
1263 selectArticles("none");
1265 var old_offset
= $("RROW-" + id
).offsetTop
;
1267 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1269 Element
.show("CEXC-" + active_post_id
);
1272 active_post_id
= id
;
1274 elem
= $("CICD-" + id
);
1276 if (!Element
.visible(elem
)) {
1278 Element
.hide("CEXC-" + id
);
1280 if ($("CWRAP-" + id
).innerHTML
== "") {
1282 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1284 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1285 __("Loading, please wait...") + "</div>";
1287 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1289 var neighbor_ids
= getRelativePostIds(id
);
1291 /* only request uncached articles */
1292 var cids_to_request
= [];
1294 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1295 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1296 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1297 cids_to_request
.push(neighbor_ids
[i
]);
1298 cids_requested
.push(neighbor_ids
[i
]);
1302 console
.log("additional ids: " + cids_to_request
.toString());
1304 query
= query
+ "&cids=" + cids_to_request
.toString();
1308 new Ajax
.Request("backend.php", {
1310 onComplete: function(transport
) {
1312 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1314 handle_rpc_json(transport
);
1316 var reply
= JSON
.parse(transport
.responseText
);
1318 reply
.each(function(article
) {
1319 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1320 cids_requested
.remove(article
['id']);
1327 var new_offset
= $("RROW-" + id
).offsetTop
;
1329 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1331 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1332 $("headlines-frame").scrollTop
= new_offset
;
1334 toggleUnread(id
, 0, true);
1338 exception_error("cdmExpandArticle", e
);
1344 function fixHeadlinesOrder(ids
) {
1346 for (var i
= 0; i
< ids
.length
; i
++) {
1347 var e
= $("RROW-" + ids
[i
]);
1351 e
.removeClassName("even");
1352 e
.addClassName("odd");
1354 e
.removeClassName("odd");
1355 e
.addClassName("even");
1360 exception_error("fixHeadlinesOrder", e
);
1364 function getArticleUnderPointer() {
1365 return post_under_pointer
;
1368 function zoomToArticle(event
, id
) {
1370 var cached_article
= cache_get("article: " + id
);
1372 if (dijit
.byId("ATAB-" + id
))
1373 if (!event
|| !event
.shiftKey
)
1374 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1376 if (dijit
.byId("ATSTRTIP-" + id
))
1377 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1379 if (cached_article
) {
1380 //closeArticlePanel();
1382 var article_pane
= new dijit
.layout
.ContentPane({
1383 title
: __("Loading...") , content
: cached_article
,
1384 style
: 'padding : 0px;',
1388 dijit
.byId("content-tabs").addChild(article_pane
);
1390 if (!event
|| !event
.shiftKey
)
1391 dijit
.byId("content-tabs").selectChild(article_pane
);
1393 if ($("PTITLE-" + id
))
1394 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1398 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1400 notify_progress("Loading, please wait...", true);
1402 new Ajax
.Request("backend.php", {
1404 onComplete: function(transport
) {
1407 var reply
= JSON
.parse(transport
.responseText
);
1410 //closeArticlePanel();
1412 var content
= reply
[0]['content'];
1414 var article_pane
= new dijit
.layout
.ContentPane({
1415 title
: "article-" + id
, content
: content
,
1416 style
: 'padding : 0px;',
1420 dijit
.byId("content-tabs").addChild(article_pane
);
1422 if (!event
|| !event
.shiftKey
)
1423 dijit
.byId("content-tabs").selectChild(article_pane
);
1425 if ($("PTITLE-" + id
))
1426 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1433 exception_error("zoomToArticle", e
);
1437 function scrollArticle(offset
) {
1440 var ci
= $("content-insert");
1442 ci
.scrollTop
+= offset
;
1445 var hi
= $("headlines-frame");
1447 hi
.scrollTop
+= offset
;
1452 exception_error("scrollArticle", e
);
1456 function show_labels_in_headlines(transport
) {
1458 var data
= JSON
.parse(transport
.responseText
);
1461 data
['info-for-headlines'].each(function(elem
) {
1462 var ctr
= $("HLLCTR-" + elem
.id
);
1464 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1467 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1471 exception_error("show_labels_in_headlines", e
);
1475 /* function toggleHeadlineActions() {
1477 var e = $("headlineActionsBody");
1478 var p = $("headlineActionsDrop");
1480 if (!Element.visible(e)) {
1487 e.style.left = (p.offsetLeft + 1) + "px";
1488 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1491 exception_error("toggleHeadlineActions", e);
1495 /* function publishWithNote(id, def_note) {
1497 if (!def_note) def_note = '';
1499 var note = prompt(__("Please enter a note for this article:"), def_note);
1501 if (note != undefined) {
1502 togglePub(id, false, false, note);
1506 exception_error("publishWithNote", e);
1510 function dismissArticle(id
) {
1512 var elem
= $("RROW-" + id
);
1514 toggleUnread(id
, 0, true);
1516 new Effect
.Fade(elem
, {duration
: 0.5});
1518 active_post_id
= false;
1521 exception_error("dismissArticle", e
);
1525 function dismissSelectedArticles() {
1528 var ids
= getVisibleArticleIds();
1532 for (var i
= 0; i
< ids
.length
; i
++) {
1533 var elem
= $("RROW-" + ids
[i
]);
1535 if (elem
.className
&& elem
.hasClassName("Selected") &&
1536 ids
[i
] != active_post_id
) {
1537 new Effect
.Fade(elem
, {duration
: 0.5});
1545 selectionToggleUnread(false);
1547 fixHeadlinesOrder(tmp
);
1550 exception_error("dismissSelectedArticles", e
);
1554 function dismissReadArticles() {
1557 var ids
= getVisibleArticleIds();
1560 for (var i
= 0; i
< ids
.length
; i
++) {
1561 var elem
= $("RROW-" + ids
[i
]);
1563 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1564 !elem
.hasClassName("Selected")) {
1566 new Effect
.Fade(elem
, {duration
: 0.5});
1572 fixHeadlinesOrder(tmp
);
1575 exception_error("dismissSelectedArticles", e
);
1579 function getVisibleArticleIds() {
1584 getLoadedArticleIds().each(function(id
) {
1585 var elem
= $("RROW-" + id
);
1586 if (elem
&& Element
.visible(elem
))
1591 exception_error("getVisibleArticleIds", e
);
1597 function cdmClicked(event
, id
) {
1599 //var shift_key = event.shiftKey;
1603 if (!event
.ctrlKey
) {
1605 if (!getInitParam("cdm_expanded")) {
1606 return cdmExpandArticle(id
);
1609 selectArticles("none");
1612 var elem
= $("RROW-" + id
);
1615 elem
.removeClassName("Unread");
1617 var upd_img_pic
= $("FUPDPIC-" + id
);
1619 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1620 upd_img_pic
.src
.match("fresh_sign.png"))) {
1622 upd_img_pic
.src
= "images/blank_icon.gif";
1625 active_post_id
= id
;
1627 var query
= "?op=rpc&method=catchupSelected" +
1628 "&cmode=0&ids=" + param_escape(id
);
1630 new Ajax
.Request("backend.php", {
1632 onComplete: function(transport
) {
1633 handle_rpc_json(transport
);
1640 toggleSelected(id
, true);
1641 toggleUnread(id
, 0, false);
1642 zoomToArticle(event
, id
);
1646 exception_error("cdmClicked");
1652 function postClicked(event
, id
) {
1655 if (!event
.ctrlKey
) {
1658 postOpenInNewTab(event
, id
);
1663 exception_error("postClicked");
1667 function hlOpenInNewTab(event
, id
) {
1668 toggleUnread(id
, 0, false);
1669 zoomToArticle(event
, id
);
1672 function postOpenInNewTab(event
, id
) {
1673 closeArticlePanel(id
);
1674 zoomToArticle(event
, id
);
1677 function hlClicked(event
, id
) {
1679 if (event
.which
== 2) {
1682 } else if (event
.altKey
) {
1683 openArticleInNewWindow(id
);
1684 } else if (!event
.ctrlKey
) {
1689 toggleUnread(id
, 0, false);
1690 zoomToArticle(event
, id
);
1695 exception_error("hlClicked");
1699 function getFirstVisibleHeadlineId() {
1700 var rows
= getVisibleArticleIds();
1705 function getLastVisibleHeadlineId() {
1706 var rows
= getVisibleArticleIds();
1707 return rows
[rows
.length
-1];
1710 function openArticleInNewWindow(id
) {
1711 toggleUnread(id
, 0, false);
1712 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1715 function isCdmMode() {
1716 return getInitParam("combined_display_mode");
1719 function markHeadline(id
) {
1720 var row
= $("RROW-" + id
);
1722 var check
= $("RCHK-" + id
);
1725 check
.checked
= true;
1728 row
.addClassName("Selected");
1732 function getRelativePostIds(id
, limit
) {
1738 if (!limit
) limit
= 6; //3
1740 var ids
= getVisibleArticleIds();
1742 for (var i
= 0; i
< ids
.length
; i
++) {
1744 for (var k
= 1; k
<= limit
; k
++) {
1745 //if (i > k-1) tmp.push(ids[i-k]);
1746 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1753 exception_error("getRelativePostIds", e
);
1759 function correctHeadlinesOffset(id
) {
1763 var container
= $("headlines-frame");
1764 var row
= $("RROW-" + id
);
1766 var viewport
= container
.offsetHeight
;
1768 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1769 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1771 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1772 //console.log("Vport: " + viewport);
1774 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1775 container
.scrollTop
= row
.offsetTop
;
1776 } else if (rel_offset_bottom
> viewport
) {
1778 /* doesn't properly work with Opera in some cases because
1779 Opera fucks up element scrolling */
1781 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1785 exception_error("correctHeadlinesOffset", e
);
1790 function headlineActionsChange(elem
) {
1793 elem
.attr('value', 'false');
1795 exception_error("headlineActionsChange", e
);
1799 function closeArticlePanel() {
1801 var tabs
= dijit
.byId("content-tabs");
1802 var child
= tabs
.selectedChildWidget
;
1804 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1805 tabs
.removeChild(child
);
1808 if (dijit
.byId("content-insert"))
1809 dijit
.byId("headlines-wrap-inner").removeChild(
1810 dijit
.byId("content-insert"));
1814 function initHeadlinesMenu() {
1816 if (dijit
.byId("headlinesMenu"))
1817 dijit
.byId("headlinesMenu").destroyRecursive();
1822 nodes
= $$("#headlines-frame > div[id*=RROW]");
1824 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1827 nodes
.each(function(node
) {
1831 var menu
= new dijit
.Menu({
1832 id
: "headlinesMenu",
1836 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1837 var callerNode
= event
.target
, match
= null, tries
= 0;
1839 while (match
== null && callerNode
&& tries
<= 3) {
1840 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1841 callerNode
= callerNode
.parentNode
;
1845 if (match
) this.callerRowId
= parseInt(match
[1]);
1849 /* if (!isCdmMode())
1850 menu.addChild(new dijit.MenuItem({
1851 label: __("View article"),
1852 onClick: function(event) {
1853 view(this.getParent().callerRowId);
1856 menu
.addChild(new dijit
.MenuItem({
1857 label
: __("Open original article"),
1858 onClick: function(event
) {
1859 openArticleInNewWindow(this.getParent().callerRowId
);
1862 menu
.addChild(new dijit
.MenuItem({
1863 label
: __("View in a tt-rss tab"),
1864 onClick: function(event
) {
1865 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1868 menu
.addChild(new dijit
.MenuSeparator());
1870 menu
.addChild(new dijit
.MenuItem({
1871 label
: __("Mark above as read"),
1872 onClick: function(event
) {
1873 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1876 menu
.addChild(new dijit
.MenuItem({
1877 label
: __("Mark below as read"),
1878 onClick: function(event
) {
1879 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1883 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1887 menu
.addChild(new dijit
.MenuSeparator());
1889 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1890 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1892 labels
.each(function(label
) {
1893 var id
= label
.id
[0];
1894 var bare_id
= id
.substr(id
.indexOf(":")+1);
1895 var name
= label
.name
[0];
1897 bare_id
= -11-bare_id
;
1899 labelAddMenu
.addChild(new dijit
.MenuItem({
1902 onClick: function(event
) {
1903 selectionAssignLabel(this.labelId
,
1904 [this.getParent().ownerMenu
.callerRowId
]);
1907 labelDelMenu
.addChild(new dijit
.MenuItem({
1910 onClick: function(event
) {
1911 selectionRemoveLabel(this.labelId
,
1912 [this.getParent().ownerMenu
.callerRowId
]);
1917 menu
.addChild(new dijit
.PopupMenuItem({
1918 label
: __("Assign label"),
1919 popup
: labelAddMenu
,
1922 menu
.addChild(new dijit
.PopupMenuItem({
1923 label
: __("Remove label"),
1924 popup
: labelDelMenu
,
1932 exception_error("initHeadlinesMenu", e
);
1937 function player(elem
) {
1938 var aid
= elem
.getAttribute("audio-id");
1939 var status
= elem
.getAttribute("status");
1947 elem
.innerHTML
= __("Playing...");
1948 elem
.title
= __("Click to pause");
1949 elem
.addClassName("playing");
1953 elem
.innerHTML
= __("Play");
1954 elem
.title
= __("Click to play");
1955 elem
.removeClassName("playing");
1958 elem
.setAttribute("status", status
);
1960 alert("Your browser doesn't seem to support HTML5 audio.");
1964 function cache_set(id
, obj
) {
1965 //console.log("cache_set: " + id);
1968 sessionStorage
[id
] = obj
;
1970 sessionStorage
.clear();
1974 function cache_get(id
) {
1976 return sessionStorage
[id
];
1979 function cache_clear() {
1981 sessionStorage
.clear();
1984 function cache_delete(id
) {
1986 sessionStorage
.removeItem(id
);
1989 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
1990 if (toolbar_obj
&& content_obj
) {
1991 cache_set("feed:" + feed
+ ":" + is_cat
,
1992 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
1995 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
1998 obj
= JSON
.parse(obj
);
2000 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2001 if (content_obj
) obj
.content
= content_obj
;
2003 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2007 console
.warn("cache_headlines failed: " + e
);
2012 function render_local_headlines(feed
, is_cat
, obj
) {
2015 dijit
.byId("headlines-toolbar").attr('content',
2018 dijit
.byId("headlines-frame").attr('content',
2021 dojo
.parser
.parse('headlines-toolbar');
2023 $("headlines-frame").scrollTop
= 0;
2024 selectArticles('none');
2025 setActiveFeedId(feed
, is_cat
);
2026 initHeadlinesMenu();
2028 precache_headlines();
2031 exception_error("render_local_headlines", e
);
2035 function precache_headlines_idle() {
2037 if (!feed_precache_timeout_id
) {
2038 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2041 feeds
.each(function(item
) {
2042 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2043 uncached
.push(item
);
2046 if (uncached
.length
> 0) {
2047 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2048 viewfeed(rf
[0], '', rf
[1], 0, true);
2051 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2054 exception_error("precache_headlines_idle", e
);
2058 function precache_headlines() {
2061 if (!feed_precache_timeout_id
) {
2062 feed_precache_timeout_id
= window
.setTimeout(function() {
2063 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2064 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2066 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2067 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2069 if (nf
!= nuf
&& nf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2070 viewfeed(nf
[0], '', nf
[1], 0, true);
2072 window
.setTimeout(function() {
2073 feed_precache_timeout_id
= false;
2079 exception_error("precache_headlines", e
);