]>
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) {
496 next_id
= getFirstVisibleHeadlineId();
497 prev_id
= getLastVisibleHeadlineId();
499 for (var i
= 0; i
< rows
.length
; i
++) {
500 if (rows
[i
] == active_post_id
) {
507 if (mode
== "next") {
511 cdmExpandArticle(next_id
);
512 cdmScrollToArticleId(next_id
);
515 correctHeadlinesOffset(next_id
);
516 view(next_id
, getActiveFeedId());
521 if (mode
== "prev") {
524 cdmExpandArticle(prev_id
);
525 cdmScrollToArticleId(prev_id
);
527 correctHeadlinesOffset(prev_id
);
528 view(prev_id
, getActiveFeedId());
534 exception_error("moveToPost", e
);
538 function toggleSelected(id
, force_on
) {
541 var cb
= $("RCHK-" + id
);
542 var row
= $("RROW-" + id
);
545 if (row
.hasClassName('Selected') && !force_on
) {
546 row
.removeClassName('Selected');
547 if (cb
) cb
.checked
= false;
549 row
.addClassName('Selected');
550 if (cb
) cb
.checked
= true;
554 exception_error("toggleSelected", e
);
558 function toggleUnread_afh(effect
) {
561 var elem
= effect
.element
;
562 elem
.style
.backgroundColor
= "";
565 exception_error("toggleUnread_afh", e
);
569 function toggleUnread(id
, cmode
, effect
) {
572 var row
= $("RROW-" + id
);
574 if (cmode
== undefined || cmode
== 2) {
575 if (row
.hasClassName("Unread")) {
576 row
.removeClassName("Unread");
579 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
580 afterFinish
: toggleUnread_afh
,
581 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
585 row
.addClassName("Unread");
588 } else if (cmode
== 0) {
590 row
.removeClassName("Unread");
593 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
594 afterFinish
: toggleUnread_afh
,
595 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
598 } else if (cmode
== 1) {
599 row
.addClassName("Unread");
602 if (cmode
== undefined) cmode
= 2;
604 var query
= "?op=rpc&method=catchupSelected" +
605 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
607 // notify_progress("Loading, please wait...");
609 new Ajax
.Request("backend.php", {
611 onComplete: function(transport
) {
612 handle_rpc_json(transport
);
618 exception_error("toggleUnread", e
);
622 function selectionRemoveLabel(id
, ids
) {
625 if (!ids
) ids
= getSelectedArticleIds2();
627 if (ids
.length
== 0) {
628 alert(__("No articles are selected."));
632 var query
= "?op=rpc&method=removeFromLabel&ids=" +
633 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
637 new Ajax
.Request("backend.php", {
639 onComplete: function(transport
) {
640 handle_rpc_json(transport
);
641 show_labels_in_headlines(transport
);
645 exception_error("selectionAssignLabel", e
);
650 function selectionAssignLabel(id
, ids
) {
653 if (!ids
) ids
= getSelectedArticleIds2();
655 if (ids
.length
== 0) {
656 alert(__("No articles are selected."));
660 var query
= "?op=rpc&method=assignToLabel&ids=" +
661 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
665 new Ajax
.Request("backend.php", {
667 onComplete: function(transport
) {
668 handle_rpc_json(transport
);
669 show_labels_in_headlines(transport
);
673 exception_error("selectionAssignLabel", e
);
678 function selectionToggleUnread(set_state
, callback
, no_error
) {
680 var rows
= getSelectedArticleIds2();
682 if (rows
.length
== 0 && !no_error
) {
683 alert(__("No articles are selected."));
687 for (var i
= 0; i
< rows
.length
; i
++) {
688 var row
= $("RROW-" + rows
[i
]);
690 if (set_state
== undefined) {
691 if (row
.hasClassName("Unread")) {
692 row
.removeClassName("Unread");
694 row
.addClassName("Unread");
698 if (set_state
== false) {
699 row
.removeClassName("Unread");
702 if (set_state
== true) {
703 row
.addClassName("Unread");
708 if (rows
.length
> 0) {
712 if (set_state
== undefined) {
714 } else if (set_state
== true) {
716 } else if (set_state
== false) {
720 var query
= "?op=rpc&method=catchupSelected" +
721 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
723 notify_progress("Loading, please wait...");
725 new Ajax
.Request("backend.php", {
727 onComplete: function(transport
) {
728 handle_rpc_json(transport
);
729 if (callback
) callback(transport
);
735 exception_error("selectionToggleUnread", e
);
739 function selectionToggleMarked() {
742 var rows
= getSelectedArticleIds2();
744 if (rows
.length
== 0) {
745 alert(__("No articles are selected."));
749 for (var i
= 0; i
< rows
.length
; i
++) {
750 toggleMark(rows
[i
], true, true);
753 if (rows
.length
> 0) {
755 var query
= "?op=rpc&method=markSelected&ids=" +
756 param_escape(rows
.toString()) + "&cmode=2";
758 new Ajax
.Request("backend.php", {
760 onComplete: function(transport
) {
761 handle_rpc_json(transport
);
767 exception_error("selectionToggleMarked", e
);
771 function selectionTogglePublished() {
774 var rows
= getSelectedArticleIds2();
776 if (rows
.length
== 0) {
777 alert(__("No articles are selected."));
781 for (var i
= 0; i
< rows
.length
; i
++) {
782 togglePub(rows
[i
], true, true);
785 if (rows
.length
> 0) {
787 var query
= "?op=rpc&method=publishSelected&ids=" +
788 param_escape(rows
.toString()) + "&cmode=2";
790 new Ajax
.Request("backend.php", {
792 onComplete: function(transport
) {
793 handle_rpc_json(transport
);
799 exception_error("selectionToggleMarked", e
);
803 function getSelectedArticleIds2() {
807 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
809 rv
.push(child
.id
.replace("RROW-", ""));
815 function getLoadedArticleIds() {
818 var children
= $$("#headlines-frame > div[id*=RROW-]");
820 children
.each(function(child
) {
821 rv
.push(child
.id
.replace("RROW-", ""));
828 // mode = all,none,unread,invert
829 function selectArticles(mode
) {
832 var children
= $$("#headlines-frame > div[id*=RROW]");
834 children
.each(function(child
) {
835 var id
= child
.id
.replace("RROW-", "");
836 var cb
= $("RCHK-" + id
);
839 child
.addClassName("Selected");
841 } else if (mode
== "unread") {
842 if (child
.hasClassName("Unread")) {
843 child
.addClassName("Selected");
846 child
.removeClassName("Selected");
849 } else if (mode
== "invert") {
850 if (child
.hasClassName("Selected")) {
851 child
.removeClassName("Selected");
854 child
.addClassName("Selected");
859 child
.removeClassName("Selected");
865 exception_error("selectArticles", e
);
869 function catchupPage() {
871 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
873 var str
= __("Mark all visible articles in %s as read?");
875 str
= str
.replace("%s", fn
);
877 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
881 selectArticles('all');
882 selectionToggleUnread(false, 'viewCurrentFeed()', true);
883 selectArticles('none');
886 function deleteSelection() {
890 var rows
= getSelectedArticleIds2();
892 if (rows
.length
== 0) {
893 alert(__("No articles are selected."));
897 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
900 if (getActiveFeedId() != 0) {
901 str
= __("Delete %d selected articles in %s?");
903 str
= __("Delete %d selected articles?");
906 str
= str
.replace("%d", rows
.length
);
907 str
= str
.replace("%s", fn
);
909 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
913 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
917 new Ajax
.Request("backend.php", {
919 onComplete: function(transport
) {
920 handle_rpc_json(transport
);
925 exception_error("deleteSelection", e
);
929 function archiveSelection() {
933 var rows
= getSelectedArticleIds2();
935 if (rows
.length
== 0) {
936 alert(__("No articles are selected."));
940 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
944 if (getActiveFeedId() != 0) {
945 str
= __("Archive %d selected articles in %s?");
948 str
= __("Move %d archived articles back?");
952 str
= str
.replace("%d", rows
.length
);
953 str
= str
.replace("%s", fn
);
955 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
959 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
963 for (var i
= 0; i
< rows
.length
; i
++) {
964 cache_delete("article:" + rows
[i
]);
967 new Ajax
.Request("backend.php", {
969 onComplete: function(transport
) {
970 handle_rpc_json(transport
);
975 exception_error("archiveSelection", e
);
979 function catchupSelection() {
983 var rows
= getSelectedArticleIds2();
985 if (rows
.length
== 0) {
986 alert(__("No articles are selected."));
990 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
992 var str
= __("Mark %d selected articles in %s as read?");
994 str
= str
.replace("%d", rows
.length
);
995 str
= str
.replace("%s", fn
);
997 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1001 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1004 exception_error("catchupSelection", e
);
1008 function editArticleTags(id
) {
1009 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1011 if (dijit
.byId("editTagsDlg"))
1012 dijit
.byId("editTagsDlg").destroyRecursive();
1014 dialog
= new dijit
.Dialog({
1016 title
: __("Edit article Tags"),
1017 style
: "width: 600px",
1018 execute: function() {
1019 if (this.validate()) {
1020 var query
= dojo
.objectToQuery(this.attr('value'));
1022 notify_progress("Saving article tags...", true);
1024 new Ajax
.Request("backend.php", {
1026 onComplete: function(transport
) {
1030 var data
= JSON
.parse(transport
.responseText
);
1033 var tags_str
= article
.tags
;
1034 var id
= tags_str
.id
;
1036 var tags
= $("ATSTR-" + id
);
1037 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1039 if (tags
) tags
.innerHTML
= tags_str
.content
;
1040 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1042 cache_delete("article:" + id
);
1051 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1052 dojo
.disconnect(tmph
);
1054 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1055 "backend.php?op=rpc&method=completeTags",
1056 { tokens
: ',', paramName
: "search" });
1063 function cdmScrollToArticleId(id
) {
1065 var ctr
= $("headlines-frame");
1066 var e
= $("RROW-" + id
);
1068 if (!e
|| !ctr
) return;
1070 ctr
.scrollTop
= e
.offsetTop
;
1073 exception_error("cdmScrollToArticleId", e
);
1077 function getActiveArticleId() {
1078 return active_post_id
;
1081 function postMouseIn(id
) {
1082 post_under_pointer
= id
;
1085 function postMouseOut(id
) {
1086 post_under_pointer
= false;
1089 function headlines_scroll_handler(e
) {
1091 var hsp
= $("headlines-spacer");
1093 if (!_infscroll_disable
) {
1094 if (hsp
&& (e
.scrollTop
+ e
.offsetHeight
> hsp
.offsetTop
) ||
1095 e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1098 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1099 __("Loading, please wait...");
1101 loadMoreHeadlines();
1106 if (hsp
) hsp
.innerHTML
= "";
1109 if (getInitParam("cdm_auto_catchup") == 1) {
1111 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1113 if ($("headlines-frame").scrollTop
>
1114 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1116 var id
= child
.id
.replace("RROW-", "");
1118 if (catchup_id_batch
.indexOf(id
) == -1)
1119 catchup_id_batch
.push(id
);
1121 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1125 if (catchup_id_batch
.length
> 0) {
1126 window
.clearTimeout(catchup_timeout_id
);
1128 if (!_infscroll_request_sent
) {
1129 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1136 console
.warn("headlines_scroll_handler: " + e
);
1140 function catchupBatchedArticles() {
1142 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1144 var query
= "?op=rpc&method=catchupSelected" +
1145 "&cmode=0&ids=" + param_escape(catchup_id_batch
.toString());
1147 new Ajax
.Request("backend.php", {
1149 onComplete: function(transport
) {
1150 handle_rpc_json(transport
);
1152 catchup_id_batch
.each(function(id
) {
1153 var elem
= $("RROW-" + id
);
1154 if (elem
) elem
.removeClassName("Unread");
1157 catchup_id_batch
= [];
1162 exception_error("catchupBatchedArticles", e
);
1166 function catchupRelativeToArticle(below
, id
) {
1170 if (!id
) id
= getActiveArticleId();
1173 alert(__("No article is selected."));
1177 var visible_ids
= getVisibleArticleIds();
1179 var ids_to_mark
= new Array();
1182 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1183 if (visible_ids
[i
] != id
) {
1184 var e
= $("RROW-" + visible_ids
[i
]);
1186 if (e
&& e
.hasClassName("Unread")) {
1187 ids_to_mark
.push(visible_ids
[i
]);
1194 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1195 if (visible_ids
[i
] != id
) {
1196 var e
= $("RROW-" + visible_ids
[i
]);
1198 if (e
&& e
.hasClassName("Unread")) {
1199 ids_to_mark
.push(visible_ids
[i
]);
1207 if (ids_to_mark
.length
== 0) {
1208 alert(__("No articles found to mark"));
1210 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1212 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1214 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1215 var e
= $("RROW-" + ids_to_mark
[i
]);
1216 e
.removeClassName("Unread");
1219 var query
= "?op=rpc&method=catchupSelected" +
1220 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1222 new Ajax
.Request("backend.php", {
1224 onComplete: function(transport
) {
1225 handle_rpc_json(transport
);
1232 exception_error("catchupRelativeToArticle", e
);
1236 function cdmExpandArticle(id
) {
1241 var elem
= $("CICD-" + active_post_id
);
1243 var upd_img_pic
= $("FUPDPIC-" + id
);
1245 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1246 upd_img_pic
.src
.match("fresh_sign.png"))) {
1248 upd_img_pic
.src
= "images/blank_icon.gif";
1251 if (id
== active_post_id
&& Element
.visible(elem
))
1254 selectArticles("none");
1256 var old_offset
= $("RROW-" + id
).offsetTop
;
1258 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1260 Element
.show("CEXC-" + active_post_id
);
1263 active_post_id
= id
;
1265 elem
= $("CICD-" + id
);
1267 if (!Element
.visible(elem
)) {
1269 Element
.hide("CEXC-" + id
);
1271 if ($("CWRAP-" + id
).innerHTML
== "") {
1273 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1275 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1276 __("Loading, please wait...") + "</div>";
1278 var query
= "?op=rpc&method=cdmGetArticle&id=" + param_escape(id
);
1280 var neighbor_ids
= getRelativePostIds(id
);
1282 /* only request uncached articles */
1283 var cids_to_request
= [];
1285 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1286 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1287 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1288 cids_to_request
.push(neighbor_ids
[i
]);
1289 cids_requested
.push(neighbor_ids
[i
]);
1293 console
.log("additional ids: " + cids_to_request
.toString());
1295 query
= query
+ "&cids=" + cids_to_request
.toString();
1299 new Ajax
.Request("backend.php", {
1301 onComplete: function(transport
) {
1303 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1305 handle_rpc_json(transport
);
1307 var reply
= JSON
.parse(transport
.responseText
);
1309 reply
.each(function(article
) {
1310 $("CWRAP-" + article
['id']).innerHTML
= article
['content'];
1311 cids_requested
.remove(article
['id']);
1318 var new_offset
= $("RROW-" + id
).offsetTop
;
1320 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1322 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1323 $("headlines-frame").scrollTop
= new_offset
;
1325 toggleUnread(id
, 0, true);
1329 exception_error("cdmExpandArticle", e
);
1335 function fixHeadlinesOrder(ids
) {
1337 for (var i
= 0; i
< ids
.length
; i
++) {
1338 var e
= $("RROW-" + ids
[i
]);
1342 e
.removeClassName("even");
1343 e
.addClassName("odd");
1345 e
.removeClassName("odd");
1346 e
.addClassName("even");
1351 exception_error("fixHeadlinesOrder", e
);
1355 function getArticleUnderPointer() {
1356 return post_under_pointer
;
1359 function zoomToArticle(event
, id
) {
1361 var cached_article
= cache_get("article: " + id
);
1363 if (dijit
.byId("ATAB-" + id
))
1364 if (!event
|| !event
.shiftKey
)
1365 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1367 if (dijit
.byId("ATSTRTIP-" + id
))
1368 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1370 if (cached_article
) {
1371 //closeArticlePanel();
1373 var article_pane
= new dijit
.layout
.ContentPane({
1374 title
: __("Loading...") , content
: cached_article
,
1375 style
: 'padding : 0px;',
1379 dijit
.byId("content-tabs").addChild(article_pane
);
1381 if (!event
|| !event
.shiftKey
)
1382 dijit
.byId("content-tabs").selectChild(article_pane
);
1384 if ($("PTITLE-" + id
))
1385 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1389 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1391 notify_progress("Loading, please wait...", true);
1393 new Ajax
.Request("backend.php", {
1395 onComplete: function(transport
) {
1398 var reply
= JSON
.parse(transport
.responseText
);
1401 //closeArticlePanel();
1403 var content
= reply
[0]['content'];
1405 var article_pane
= new dijit
.layout
.ContentPane({
1406 title
: "article-" + id
, content
: content
,
1407 style
: 'padding : 0px;',
1411 dijit
.byId("content-tabs").addChild(article_pane
);
1413 if (!event
|| !event
.shiftKey
)
1414 dijit
.byId("content-tabs").selectChild(article_pane
);
1416 if ($("PTITLE-" + id
))
1417 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1424 exception_error("zoomToArticle", e
);
1428 function scrollArticle(offset
) {
1431 var ci
= $("content-insert");
1433 ci
.scrollTop
+= offset
;
1436 var hi
= $("headlines-frame");
1438 hi
.scrollTop
+= offset
;
1443 exception_error("scrollArticle", e
);
1447 function show_labels_in_headlines(transport
) {
1449 var data
= JSON
.parse(transport
.responseText
);
1452 data
['info-for-headlines'].each(function(elem
) {
1453 var ctr
= $("HLLCTR-" + elem
.id
);
1455 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1458 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1462 exception_error("show_labels_in_headlines", e
);
1466 /* function toggleHeadlineActions() {
1468 var e = $("headlineActionsBody");
1469 var p = $("headlineActionsDrop");
1471 if (!Element.visible(e)) {
1478 e.style.left = (p.offsetLeft + 1) + "px";
1479 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1482 exception_error("toggleHeadlineActions", e);
1486 /* function publishWithNote(id, def_note) {
1488 if (!def_note) def_note = '';
1490 var note = prompt(__("Please enter a note for this article:"), def_note);
1492 if (note != undefined) {
1493 togglePub(id, false, false, note);
1497 exception_error("publishWithNote", e);
1501 function dismissArticle(id
) {
1503 var elem
= $("RROW-" + id
);
1505 toggleUnread(id
, 0, true);
1507 new Effect
.Fade(elem
, {duration
: 0.5});
1509 active_post_id
= false;
1512 exception_error("dismissArticle", e
);
1516 function dismissSelectedArticles() {
1519 var ids
= getVisibleArticleIds();
1523 for (var i
= 0; i
< ids
.length
; i
++) {
1524 var elem
= $("RROW-" + ids
[i
]);
1526 if (elem
.className
&& elem
.hasClassName("Selected") &&
1527 ids
[i
] != active_post_id
) {
1528 new Effect
.Fade(elem
, {duration
: 0.5});
1536 selectionToggleUnread(false);
1538 fixHeadlinesOrder(tmp
);
1541 exception_error("dismissSelectedArticles", e
);
1545 function dismissReadArticles() {
1548 var ids
= getVisibleArticleIds();
1551 for (var i
= 0; i
< ids
.length
; i
++) {
1552 var elem
= $("RROW-" + ids
[i
]);
1554 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1555 !elem
.hasClassName("Selected")) {
1557 new Effect
.Fade(elem
, {duration
: 0.5});
1563 fixHeadlinesOrder(tmp
);
1566 exception_error("dismissSelectedArticles", e
);
1570 function getVisibleArticleIds() {
1575 getLoadedArticleIds().each(function(id
) {
1576 var elem
= $("RROW-" + id
);
1577 if (elem
&& Element
.visible(elem
))
1582 exception_error("getVisibleArticleIds", e
);
1588 function cdmClicked(event
, id
) {
1590 //var shift_key = event.shiftKey;
1594 if (!event
.ctrlKey
) {
1596 if (!getInitParam("cdm_expanded")) {
1597 return cdmExpandArticle(id
);
1600 selectArticles("none");
1603 var elem
= $("RROW-" + id
);
1606 elem
.removeClassName("Unread");
1608 var upd_img_pic
= $("FUPDPIC-" + id
);
1610 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1611 upd_img_pic
.src
.match("fresh_sign.png"))) {
1613 upd_img_pic
.src
= "images/blank_icon.gif";
1616 active_post_id
= id
;
1618 var query
= "?op=rpc&method=catchupSelected" +
1619 "&cmode=0&ids=" + param_escape(id
);
1621 new Ajax
.Request("backend.php", {
1623 onComplete: function(transport
) {
1624 handle_rpc_json(transport
);
1631 toggleSelected(id
, true);
1632 toggleUnread(id
, 0, false);
1633 zoomToArticle(event
, id
);
1637 exception_error("cdmClicked");
1643 function postClicked(event
, id
) {
1646 if (!event
.ctrlKey
) {
1649 postOpenInNewTab(event
, id
);
1654 exception_error("postClicked");
1658 function hlOpenInNewTab(event
, id
) {
1659 toggleUnread(id
, 0, false);
1660 zoomToArticle(event
, id
);
1663 function postOpenInNewTab(event
, id
) {
1664 closeArticlePanel(id
);
1665 zoomToArticle(event
, id
);
1668 function hlClicked(event
, id
) {
1670 if (event
.which
== 2) {
1673 } else if (event
.altKey
) {
1674 openArticleInNewWindow(id
);
1675 } else if (!event
.ctrlKey
) {
1680 toggleUnread(id
, 0, false);
1681 zoomToArticle(event
, id
);
1686 exception_error("hlClicked");
1690 function getFirstVisibleHeadlineId() {
1691 var rows
= getVisibleArticleIds();
1696 function getLastVisibleHeadlineId() {
1697 var rows
= getVisibleArticleIds();
1698 return rows
[rows
.length
-1];
1701 function openArticleInNewWindow(id
) {
1702 toggleUnread(id
, 0, false);
1703 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1706 function isCdmMode() {
1707 return getInitParam("combined_display_mode");
1710 function markHeadline(id
) {
1711 var row
= $("RROW-" + id
);
1713 var check
= $("RCHK-" + id
);
1716 check
.checked
= true;
1719 row
.addClassName("Selected");
1723 function getRelativePostIds(id
, limit
) {
1729 if (!limit
) limit
= 6; //3
1731 var ids
= getVisibleArticleIds();
1733 for (var i
= 0; i
< ids
.length
; i
++) {
1735 for (var k
= 1; k
<= limit
; k
++) {
1736 //if (i > k-1) tmp.push(ids[i-k]);
1737 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1744 exception_error("getRelativePostIds", e
);
1750 function correctHeadlinesOffset(id
) {
1754 var container
= $("headlines-frame");
1755 var row
= $("RROW-" + id
);
1757 var viewport
= container
.offsetHeight
;
1759 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1760 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1762 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1763 //console.log("Vport: " + viewport);
1765 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1766 container
.scrollTop
= row
.offsetTop
;
1767 } else if (rel_offset_bottom
> viewport
) {
1769 /* doesn't properly work with Opera in some cases because
1770 Opera fucks up element scrolling */
1772 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1776 exception_error("correctHeadlinesOffset", e
);
1781 function headlineActionsChange(elem
) {
1784 elem
.attr('value', 'false');
1786 exception_error("headlineActionsChange", e
);
1790 function closeArticlePanel() {
1792 var tabs
= dijit
.byId("content-tabs");
1793 var child
= tabs
.selectedChildWidget
;
1795 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1796 tabs
.removeChild(child
);
1799 if (dijit
.byId("content-insert"))
1800 dijit
.byId("headlines-wrap-inner").removeChild(
1801 dijit
.byId("content-insert"));
1805 function initHeadlinesMenu() {
1807 if (dijit
.byId("headlinesMenu"))
1808 dijit
.byId("headlinesMenu").destroyRecursive();
1813 nodes
= $$("#headlines-frame > div[id*=RROW]");
1815 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1818 nodes
.each(function(node
) {
1822 var menu
= new dijit
.Menu({
1823 id
: "headlinesMenu",
1827 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1828 var callerNode
= event
.target
, match
= null, tries
= 0;
1830 while (match
== null && callerNode
&& tries
<= 3) {
1831 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1832 callerNode
= callerNode
.parentNode
;
1836 if (match
) this.callerRowId
= parseInt(match
[1]);
1840 /* if (!isCdmMode())
1841 menu.addChild(new dijit.MenuItem({
1842 label: __("View article"),
1843 onClick: function(event) {
1844 view(this.getParent().callerRowId);
1847 menu
.addChild(new dijit
.MenuItem({
1848 label
: __("Open original article"),
1849 onClick: function(event
) {
1850 openArticleInNewWindow(this.getParent().callerRowId
);
1853 menu
.addChild(new dijit
.MenuItem({
1854 label
: __("View in a tt-rss tab"),
1855 onClick: function(event
) {
1856 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1859 menu
.addChild(new dijit
.MenuSeparator());
1861 menu
.addChild(new dijit
.MenuItem({
1862 label
: __("Mark above as read"),
1863 onClick: function(event
) {
1864 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1867 menu
.addChild(new dijit
.MenuItem({
1868 label
: __("Mark below as read"),
1869 onClick: function(event
) {
1870 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1874 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1878 menu
.addChild(new dijit
.MenuSeparator());
1880 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1881 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1883 labels
.each(function(label
) {
1884 var id
= label
.id
[0];
1885 var bare_id
= id
.substr(id
.indexOf(":")+1);
1886 var name
= label
.name
[0];
1888 bare_id
= -11-bare_id
;
1890 labelAddMenu
.addChild(new dijit
.MenuItem({
1893 onClick: function(event
) {
1894 selectionAssignLabel(this.labelId
,
1895 [this.getParent().ownerMenu
.callerRowId
]);
1898 labelDelMenu
.addChild(new dijit
.MenuItem({
1901 onClick: function(event
) {
1902 selectionRemoveLabel(this.labelId
,
1903 [this.getParent().ownerMenu
.callerRowId
]);
1908 menu
.addChild(new dijit
.PopupMenuItem({
1909 label
: __("Assign label"),
1910 popup
: labelAddMenu
,
1913 menu
.addChild(new dijit
.PopupMenuItem({
1914 label
: __("Remove label"),
1915 popup
: labelDelMenu
,
1923 exception_error("initHeadlinesMenu", e
);
1927 function editArticleNote(id
) {
1930 var query
= "backend.php?op=dlg&method=editArticleNote¶m=" + param_escape(id
);
1932 if (dijit
.byId("editNoteDlg"))
1933 dijit
.byId("editNoteDlg").destroyRecursive();
1935 dialog
= new dijit
.Dialog({
1937 title
: __("Edit article note"),
1938 style
: "width: 600px",
1939 execute: function() {
1940 if (this.validate()) {
1941 var query
= dojo
.objectToQuery(this.attr('value'));
1943 notify_progress("Saving article note...", true);
1945 new Ajax
.Request("backend.php", {
1947 onComplete: function(transport
) {
1951 var reply
= JSON
.parse(transport
.responseText
);
1953 cache_delete("article:" + id
);
1955 var elem
= $("POSTNOTE-" + id
);
1959 elem
.innerHTML
= reply
.note
;
1961 if (reply
.raw_length
!= 0)
1962 new Effect
.Appear(elem
);
1974 exception_error("editArticleNote", e
);
1978 function player(elem
) {
1979 var aid
= elem
.getAttribute("audio-id");
1980 var status
= elem
.getAttribute("status");
1988 elem
.innerHTML
= __("Playing...");
1989 elem
.title
= __("Click to pause");
1990 elem
.addClassName("playing");
1994 elem
.innerHTML
= __("Play");
1995 elem
.title
= __("Click to play");
1996 elem
.removeClassName("playing");
1999 elem
.setAttribute("status", status
);
2001 alert("Your browser doesn't seem to support HTML5 audio.");
2005 function cache_set(id
, obj
) {
2006 //console.log("cache_set: " + id);
2009 sessionStorage
[id
] = obj
;
2011 sessionStorage
.clear();
2015 function cache_get(id
) {
2017 return sessionStorage
[id
];
2020 function cache_clear() {
2022 sessionStorage
.clear();
2025 function cache_delete(id
) {
2027 sessionStorage
.removeItem(id
);
2030 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2031 if (toolbar_obj
&& content_obj
) {
2032 cache_set("feed:" + feed
+ ":" + is_cat
,
2033 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2036 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2039 obj
= JSON
.parse(obj
);
2041 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2042 if (content_obj
) obj
.content
= content_obj
;
2044 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2048 console
.warn("cache_headlines failed: " + e
);
2053 function render_local_headlines(feed
, is_cat
, obj
) {
2056 dijit
.byId("headlines-toolbar").attr('content',
2059 dijit
.byId("headlines-frame").attr('content',
2062 dojo
.parser
.parse('headlines-toolbar');
2064 $("headlines-frame").scrollTop
= 0;
2065 selectArticles('none');
2066 setActiveFeedId(feed
, is_cat
);
2067 initHeadlinesMenu();
2069 precache_headlines();
2072 exception_error("render_local_headlines", e
);
2076 function precache_headlines_idle() {
2078 if (!feed_precache_timeout_id
) {
2079 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2082 feeds
.each(function(item
) {
2083 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2084 uncached
.push(item
);
2087 if (uncached
.length
> 0) {
2088 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2089 viewfeed(rf
[0], '', rf
[1], 0, true);
2092 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2095 exception_error("precache_headlines_idle", e
);
2099 function precache_headlines() {
2102 if (!feed_precache_timeout_id
) {
2103 feed_precache_timeout_id
= window
.setTimeout(function() {
2104 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2105 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2107 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2108 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2110 if (nf
!= nuf
&& nf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2111 viewfeed(nf
[0], '', nf
[1], 0, true);
2113 window
.setTimeout(function() {
2114 feed_precache_timeout_id
= false;
2120 exception_error("precache_headlines", e
);