]>
git.wh0rd.org - tt-rss.git/blob - js/viewfeed.js
1 var active_post_id
= false;
3 var article_cache
= new Array();
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
12 var feed_precache_timeout_id
= false;
13 var precache_idle_timeout_id
= false;
15 var cids_requested
= [];
16 var loaded_article_ids
= [];
18 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
20 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
22 handle_rpc_json(transport
);
24 loading_set_progress(25);
26 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
34 reply
= JSON
.parse(transport
.responseText
);
41 is_cat
= reply
['headlines']['is_cat'];
42 feed_id
= reply
['headlines']['id'];
45 var content
= reply
['headlines']['content'];
47 if (getInitParam("cdm_auto_catchup") == 1) {
48 content
= content
+ "<div id='headlines-spacer'></div>";
51 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], content
);
55 setActiveFeedId(feed_id
, is_cat
);
57 dijit
.getEnclosingWidget(
58 document
.forms
["main_toolbar_form"].update
).attr('disabled',
59 is_cat
|| feed_id
<= 0);
62 if (offset
== 0 && infscroll_req
== false) {
63 $("headlines-frame").scrollTop
= 0;
67 var headlines_count
= reply
['headlines-info']['count'];
69 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
71 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
72 _infscroll_disable
= 1;
74 _infscroll_disable
= 0;
77 var counters
= reply
['counters'];
78 var articles
= reply
['articles'];
79 //var runtime_info = reply['runtime-info'];
81 if (offset
== 0 && infscroll_req
== false) {
82 loaded_article_ids
= [];
84 dijit
.byId("headlines-frame").attr('content',
85 reply
['headlines']['content']);
87 dijit
.byId("headlines-toolbar").attr('content',
88 reply
['headlines']['toolbar']);
90 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
91 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
92 row
.parentNode
.removeChild(row
);
94 loaded_article_ids
.push(row
.id
);
98 if (getInitParam("cdm_auto_catchup") == 1) {
99 var hsp
= $("headlines-spacer");
100 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
101 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
107 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
108 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
114 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
115 console
.log("adding some more headlines: " + headlines_count
);
117 var c
= dijit
.byId("headlines-frame");
118 var ids
= getSelectedArticleIds2();
121 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
123 var hsp
= $("headlines-spacer");
126 c
.domNode
.removeChild(hsp
);
128 $$("#headlines-tmp > div").each(function(row
) {
129 if (row
.className
== 'cdmFeedTitle') {
130 row
.style
.display
= 'none';
131 c
.domNode
.appendChild(row
);
133 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
134 row
.style
.display
= 'none';
135 c
.domNode
.appendChild(row
);
137 loaded_article_ids
.push(row
.id
);
139 row
.parentNode
.removeChild(row
);
143 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
145 fixHeadlinesOrder(getLoadedArticleIds());
147 if (getInitParam("cdm_auto_catchup") == 1) {
148 c
.domNode
.appendChild(hsp
);
151 console
.log("added " + new_elems
.size() + " headlines");
153 if (new_elems
.size() == 0)
154 _infscroll_disable
= true;
156 console
.log("restore selected ids: " + ids
);
158 for (var i
= 0; i
< ids
.length
; i
++) {
159 markHeadline(ids
[i
]);
164 new_elems
.each(function(child
) {
165 dojo
.parser
.parse(child
);
167 if (!Element
.visible(child
))
168 new Effect
.Appear(child
, { duration
: 0.5 });
172 console
.log("no new headlines received");
174 var hsp
= $("headlines-spacer");
176 if (hsp
) hsp
.innerHTML
= "";
180 if (headlines_count
> 0)
181 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
184 for (var i
= 0; i
< articles
.length
; i
++) {
185 var a_id
= articles
[i
]['id'];
186 cache_set("article:" + a_id
, articles
[i
]['content']);
189 console
.log("no cached articles received");
192 // do not precache stuff after fresh feed
194 precache_headlines();
197 parse_counters(counters
);
202 console
.error("Invalid object received: " + transport
.responseText
);
203 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
204 __('Could not update headlines (invalid object received - see error console for details)') +
208 _infscroll_request_sent
= 0;
213 exception_error("headlines_callback2", e
, transport
);
217 function render_article(article
) {
219 dijit
.byId("headlines-wrap-inner").addChild(
220 dijit
.byId("content-insert"));
222 var c
= dijit
.byId("content-insert");
225 c
.domNode
.scrollTop
= 0;
228 c
.attr('content', article
);
230 correctHeadlinesOffset(getActiveArticleId());
237 exception_error("render_article", e
);
241 function showArticleInHeadlines(id
) {
245 selectArticles("none");
247 var crow
= $("RROW-" + id
);
251 var article_is_unread
= crow
.hasClassName("Unread");
253 crow
.removeClassName("Unread");
255 selectArticles('none');
257 var view_mode
= false;
260 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
261 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
266 if (article_is_unread
&& view_mode
== "all_articles") {
267 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
272 if (article_is_unread
)
273 _force_scheduled_update
= true;
276 exception_error("showArticleInHeadlines", e
);
280 function article_callback2(transport
, id
) {
282 console
.log("article_callback2 " + id
);
284 handle_rpc_json(transport
);
289 reply
= JSON
.parse(transport
.responseText
);
296 reply
.each(function(article
) {
297 if (active_post_id
== article
['id']) {
298 render_article(article
['content']);
300 cids_requested
.remove(article
['id']);
302 cache_set("article:" + article
['id'], article
['content']);
305 // if (id != last_requested_article) {
306 // console.log("requested article id is out of sequence, aborting");
311 console
.error("Invalid object received: " + transport
.responseText
);
313 render_article("<div class='whiteBox'>" +
314 __('Could not display article (invalid object received - see error console for details)') + "</div>");
319 headlines_scroll_handler($("headlines-frame"));
322 if (!_infscroll_disable &&
323 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
333 exception_error("article_callback2", e
, transport
);
339 console
.log("loading article: " + id
);
341 var cached_article
= cache_get("article:" + id
);
343 console
.log("cache check result: " + (cached_article
!= false));
347 var query
= "?op=article&method=view&id=" + param_escape(id
);
349 var neighbor_ids
= getRelativePostIds(id
);
351 /* only request uncached articles */
353 var cids_to_request
= [];
355 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
356 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
357 if (!cache_get("article:" + neighbor_ids
[i
])) {
358 cids_to_request
.push(neighbor_ids
[i
]);
359 cids_requested
.push(neighbor_ids
[i
]);
363 console
.log("additional ids: " + cids_to_request
.toString());
365 query
= query
+ "&cids=" + cids_to_request
.toString();
367 var crow
= $("RROW-" + id
);
368 var article_is_unread
= crow
.hasClassName("Unread");
371 showArticleInHeadlines(id
);
373 precache_headlines();
375 if (cached_article
&& article_is_unread
) {
377 query
= query
+ "&mode=prefetch";
379 render_article(cached_article
);
381 } else if (cached_article
) {
383 query
= query
+ "&mode=prefetch_old";
384 render_article(cached_article
);
386 // if we don't need to request any relative ids, we might as well skip
387 // the server roundtrip altogether
388 if (cids_to_request
.length
== 0) {
391 if (!_infscroll_disable &&
392 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
400 headlines_scroll_handler($("headlines-frame"));
406 last_requested_article
= id
;
410 if (article_is_unread
) {
411 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
414 new Ajax
.Request("backend.php", {
416 onComplete: function(transport
) {
417 article_callback2(transport
, id
);
423 exception_error("view", e
);
427 function toggleMark(id
, client_only
) {
429 var query
= "?op=rpc&id=" + id
+ "&method=mark";
431 var img
= $("FMPIC-" + id
);
435 if (img
.src
.match("mark_unset")) {
436 img
.src
= img
.src
.replace("mark_unset", "mark_set");
437 img
.alt
= __("Unstar article");
438 query
= query
+ "&mark=1";
441 img
.src
= img
.src
.replace("mark_set", "mark_unset");
442 img
.alt
= __("Star article");
443 query
= query
+ "&mark=0";
446 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
449 new Ajax
.Request("backend.php", {
451 onComplete: function(transport
) {
452 handle_rpc_json(transport
);
457 exception_error("toggleMark", e
);
461 function togglePub(id
, client_only
, no_effects
, note
) {
463 var query
= "?op=rpc&id=" + id
+ "&method=publ";
465 if (note
!= undefined) {
466 query
= query
+ "¬e=" + param_escape(note
);
468 query
= query
+ "¬e=undefined";
471 var img
= $("FPPIC-" + id
);
475 if (img
.src
.match("pub_unset") || note
!= undefined) {
476 img
.src
= img
.src
.replace("pub_unset", "pub_set");
477 img
.alt
= __("Unpublish article");
478 query
= query
+ "&pub=1";
481 img
.src
= img
.src
.replace("pub_set", "pub_unset");
482 img
.alt
= __("Publish article");
484 query
= query
+ "&pub=0";
487 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
490 new Ajax
.Request("backend.php", {
492 onComplete: function(transport
) {
493 handle_rpc_json(transport
);
498 exception_error("togglePub", e
);
502 function moveToPost(mode
) {
506 var rows
= getVisibleArticleIds();
511 if (!$('RROW-' + active_post_id
)) {
512 active_post_id
= false;
515 if (active_post_id
== false) {
517 prev_id
= rows
[rows
.length
-1]
519 for (var i
= 0; i
< rows
.length
; i
++) {
520 if (rows
[i
] == active_post_id
) {
522 // Account for adjacent identical article ids.
523 if (i
> 0) prev_id
= rows
[i
-1];
525 for (var j
= i
+1; j
< rows
.length
; j
++) {
526 if (rows
[j
] != active_post_id
) {
536 if (mode
== "next") {
540 cdmExpandArticle(next_id
);
541 cdmScrollToArticleId(next_id
);
544 correctHeadlinesOffset(next_id
);
545 view(next_id
, getActiveFeedId());
550 if (mode
== "prev") {
553 cdmExpandArticle(prev_id
);
554 cdmScrollToArticleId(prev_id
);
556 correctHeadlinesOffset(prev_id
);
557 view(prev_id
, getActiveFeedId());
563 exception_error("moveToPost", e
);
567 function toggleSelected(id
, force_on
) {
570 var cb
= dijit
.byId("RCHK-" + id
);
571 var row
= $("RROW-" + id
);
574 if (row
.hasClassName('Selected') && !force_on
) {
575 row
.removeClassName('Selected');
576 if (cb
) cb
.attr("checked", false);
578 row
.addClassName('Selected');
579 if (cb
) cb
.attr("checked", true);
583 exception_error("toggleSelected", e
);
587 function toggleUnread_afh(effect
) {
590 var elem
= effect
.element
;
591 elem
.style
.backgroundColor
= "";
594 exception_error("toggleUnread_afh", e
);
598 function toggleUnread(id
, cmode
, effect
) {
601 var row
= $("RROW-" + id
);
603 if (cmode
== undefined || cmode
== 2) {
604 if (row
.hasClassName("Unread")) {
605 row
.removeClassName("Unread");
608 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
609 afterFinish
: toggleUnread_afh
,
610 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
614 row
.addClassName("Unread");
617 } else if (cmode
== 0) {
619 row
.removeClassName("Unread");
622 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
623 afterFinish
: toggleUnread_afh
,
624 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
627 } else if (cmode
== 1) {
628 row
.addClassName("Unread");
631 if (cmode
== undefined) cmode
= 2;
633 var query
= "?op=rpc&method=catchupSelected" +
634 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
636 // notify_progress("Loading, please wait...");
638 new Ajax
.Request("backend.php", {
640 onComplete: function(transport
) {
641 handle_rpc_json(transport
);
647 exception_error("toggleUnread", e
);
651 function selectionRemoveLabel(id
, ids
) {
654 if (!ids
) ids
= getSelectedArticleIds2();
656 if (ids
.length
== 0) {
657 alert(__("No articles are selected."));
661 var query
= "?op=rpc&method=removeFromLabel&ids=" +
662 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
666 new Ajax
.Request("backend.php", {
668 onComplete: function(transport
) {
669 handle_rpc_json(transport
);
670 show_labels_in_headlines(transport
);
674 exception_error("selectionAssignLabel", e
);
679 function selectionAssignLabel(id
, ids
) {
682 if (!ids
) ids
= getSelectedArticleIds2();
684 if (ids
.length
== 0) {
685 alert(__("No articles are selected."));
689 var query
= "?op=rpc&method=assignToLabel&ids=" +
690 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
694 new Ajax
.Request("backend.php", {
696 onComplete: function(transport
) {
697 handle_rpc_json(transport
);
698 show_labels_in_headlines(transport
);
702 exception_error("selectionAssignLabel", e
);
707 function selectionToggleUnread(set_state
, callback
, no_error
) {
709 var rows
= getSelectedArticleIds2();
711 if (rows
.length
== 0 && !no_error
) {
712 alert(__("No articles are selected."));
716 for (var i
= 0; i
< rows
.length
; i
++) {
717 var row
= $("RROW-" + rows
[i
]);
719 if (set_state
== undefined) {
720 if (row
.hasClassName("Unread")) {
721 row
.removeClassName("Unread");
723 row
.addClassName("Unread");
727 if (set_state
== false) {
728 row
.removeClassName("Unread");
731 if (set_state
== true) {
732 row
.addClassName("Unread");
737 if (rows
.length
> 0) {
741 if (set_state
== undefined) {
743 } else if (set_state
== true) {
745 } else if (set_state
== false) {
749 var query
= "?op=rpc&method=catchupSelected" +
750 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
752 notify_progress("Loading, please wait...");
754 new Ajax
.Request("backend.php", {
756 onComplete: function(transport
) {
757 handle_rpc_json(transport
);
758 if (callback
) callback(transport
);
764 exception_error("selectionToggleUnread", e
);
768 function selectionToggleMarked() {
771 var rows
= getSelectedArticleIds2();
773 if (rows
.length
== 0) {
774 alert(__("No articles are selected."));
778 for (var i
= 0; i
< rows
.length
; i
++) {
779 toggleMark(rows
[i
], true, true);
782 if (rows
.length
> 0) {
784 var query
= "?op=rpc&method=markSelected&ids=" +
785 param_escape(rows
.toString()) + "&cmode=2";
787 new Ajax
.Request("backend.php", {
789 onComplete: function(transport
) {
790 handle_rpc_json(transport
);
796 exception_error("selectionToggleMarked", e
);
800 function selectionTogglePublished() {
803 var rows
= getSelectedArticleIds2();
805 if (rows
.length
== 0) {
806 alert(__("No articles are selected."));
810 for (var i
= 0; i
< rows
.length
; i
++) {
811 togglePub(rows
[i
], true, true);
814 if (rows
.length
> 0) {
816 var query
= "?op=rpc&method=publishSelected&ids=" +
817 param_escape(rows
.toString()) + "&cmode=2";
819 new Ajax
.Request("backend.php", {
821 onComplete: function(transport
) {
822 handle_rpc_json(transport
);
828 exception_error("selectionToggleMarked", e
);
832 function getSelectedArticleIds2() {
836 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
838 rv
.push(child
.id
.replace("RROW-", ""));
844 function getLoadedArticleIds() {
847 var children
= $$("#headlines-frame > div[id*=RROW-]");
849 children
.each(function(child
) {
850 rv
.push(child
.id
.replace("RROW-", ""));
857 // mode = all,none,unread,invert,marked,published
858 function selectArticles(mode
) {
861 var children
= $$("#headlines-frame > div[id*=RROW]");
863 children
.each(function(child
) {
864 var id
= child
.id
.replace("RROW-", "");
865 var cb
= dijit
.byId("RCHK-" + id
);
868 child
.addClassName("Selected");
869 if (cb
) cb
.attr("checked", true);
870 } else if (mode
== "unread") {
871 if (child
.hasClassName("Unread")) {
872 child
.addClassName("Selected");
873 if (cb
) cb
.attr("checked", true);
875 child
.removeClassName("Selected");
876 if (cb
) cb
.attr("checked", false);
878 } else if (mode
== "marked") {
879 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
881 if (img
&& img
.src
.match("mark_set")) {
882 child
.addClassName("Selected");
883 if (cb
) cb
.attr("checked", true);
885 child
.removeClassName("Selected");
886 if (cb
) cb
.attr("checked", false);
888 } else if (mode
== "published") {
889 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
891 if (img
&& img
.src
.match("pub_set")) {
892 child
.addClassName("Selected");
893 if (cb
) cb
.attr("checked", true);
895 child
.removeClassName("Selected");
896 if (cb
) cb
.attr("checked", false);
899 } else if (mode
== "invert") {
900 if (child
.hasClassName("Selected")) {
901 child
.removeClassName("Selected");
902 if (cb
) cb
.attr("checked", false);
904 child
.addClassName("Selected");
905 if (cb
) cb
.attr("checked", true);
909 child
.removeClassName("Selected");
910 if (cb
) cb
.attr("checked", false);
915 exception_error("selectArticles", e
);
919 function catchupPage() {
921 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
923 var str
= __("Mark all visible articles in %s as read?");
925 str
= str
.replace("%s", fn
);
927 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
931 selectArticles('all');
932 selectionToggleUnread(false, 'viewCurrentFeed()', true);
933 selectArticles('none');
936 function deleteSelection() {
940 var rows
= getSelectedArticleIds2();
942 if (rows
.length
== 0) {
943 alert(__("No articles are selected."));
947 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
950 if (getActiveFeedId() != 0) {
951 str
= __("Delete %d selected articles in %s?");
953 str
= __("Delete %d selected articles?");
956 str
= str
.replace("%d", rows
.length
);
957 str
= str
.replace("%s", fn
);
959 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
963 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
967 new Ajax
.Request("backend.php", {
969 onComplete: function(transport
) {
970 handle_rpc_json(transport
);
975 exception_error("deleteSelection", e
);
979 function archiveSelection() {
983 var rows
= getSelectedArticleIds2();
985 if (rows
.length
== 0) {
986 alert(__("No articles are selected."));
990 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
994 if (getActiveFeedId() != 0) {
995 str
= __("Archive %d selected articles in %s?");
998 str
= __("Move %d archived articles back?");
1002 str
= str
.replace("%d", rows
.length
);
1003 str
= str
.replace("%s", fn
);
1005 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1009 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1013 for (var i
= 0; i
< rows
.length
; i
++) {
1014 cache_delete("article:" + rows
[i
]);
1017 new Ajax
.Request("backend.php", {
1019 onComplete: function(transport
) {
1020 handle_rpc_json(transport
);
1025 exception_error("archiveSelection", e
);
1029 function catchupSelection() {
1033 var rows
= getSelectedArticleIds2();
1035 if (rows
.length
== 0) {
1036 alert(__("No articles are selected."));
1040 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1042 var str
= __("Mark %d selected articles in %s as read?");
1044 str
= str
.replace("%d", rows
.length
);
1045 str
= str
.replace("%s", fn
);
1047 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1051 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1054 exception_error("catchupSelection", e
);
1058 function editArticleTags(id
) {
1059 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1061 if (dijit
.byId("editTagsDlg"))
1062 dijit
.byId("editTagsDlg").destroyRecursive();
1064 dialog
= new dijit
.Dialog({
1066 title
: __("Edit article Tags"),
1067 style
: "width: 600px",
1068 execute: function() {
1069 if (this.validate()) {
1070 var query
= dojo
.objectToQuery(this.attr('value'));
1072 notify_progress("Saving article tags...", true);
1074 new Ajax
.Request("backend.php", {
1076 onComplete: function(transport
) {
1080 var data
= JSON
.parse(transport
.responseText
);
1083 var tags_str
= article
.tags
;
1084 var id
= tags_str
.id
;
1086 var tags
= $("ATSTR-" + id
);
1087 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1089 if (tags
) tags
.innerHTML
= tags_str
.content
;
1090 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1092 cache_delete("article:" + id
);
1101 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1102 dojo
.disconnect(tmph
);
1104 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1105 "backend.php?op=rpc&method=completeTags",
1106 { tokens
: ',', paramName
: "search" });
1113 function cdmScrollToArticleId(id
) {
1115 var ctr
= $("headlines-frame");
1116 var e
= $("RROW-" + id
);
1118 if (!e
|| !ctr
) return;
1120 ctr
.scrollTop
= e
.offsetTop
;
1123 exception_error("cdmScrollToArticleId", e
);
1127 function getActiveArticleId() {
1128 return active_post_id
;
1131 function postMouseIn(id
) {
1132 post_under_pointer
= id
;
1135 function postMouseOut(id
) {
1136 post_under_pointer
= false;
1139 function headlines_scroll_handler(e
) {
1141 var hsp
= $("headlines-spacer");
1143 if (!_infscroll_disable
) {
1144 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1145 (e
.scrollHeight
!= 0 &&
1146 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1149 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1150 __("Loading, please wait...");
1152 loadMoreHeadlines();
1157 if (hsp
) hsp
.innerHTML
= "";
1160 if (getInitParam("cdm_auto_catchup") == 1) {
1162 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1164 if ($("headlines-frame").scrollTop
>
1165 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1167 var id
= child
.id
.replace("RROW-", "");
1169 if (catchup_id_batch
.indexOf(id
) == -1)
1170 catchup_id_batch
.push(id
);
1172 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1176 if (catchup_id_batch
.length
> 0) {
1177 window
.clearTimeout(catchup_timeout_id
);
1179 if (!_infscroll_request_sent
) {
1180 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1187 console
.warn("headlines_scroll_handler: " + e
);
1191 function catchupBatchedArticles() {
1193 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1195 // make a copy of the array
1196 var batch
= catchup_id_batch
.slice();
1197 var query
= "?op=rpc&method=catchupSelected" +
1198 "&cmode=0&ids=" + param_escape(batch
.toString());
1202 new Ajax
.Request("backend.php", {
1204 onComplete: function(transport
) {
1205 handle_rpc_json(transport
);
1207 batch
.each(function(id
) {
1208 var elem
= $("RROW-" + id
);
1209 if (elem
) elem
.removeClassName("Unread");
1210 catchup_id_batch
.remove(id
);
1217 exception_error("catchupBatchedArticles", e
);
1221 function catchupRelativeToArticle(below
, id
) {
1225 if (!id
) id
= getActiveArticleId();
1228 alert(__("No article is selected."));
1232 var visible_ids
= getVisibleArticleIds();
1234 var ids_to_mark
= new Array();
1237 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1238 if (visible_ids
[i
] != id
) {
1239 var e
= $("RROW-" + visible_ids
[i
]);
1241 if (e
&& e
.hasClassName("Unread")) {
1242 ids_to_mark
.push(visible_ids
[i
]);
1249 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1250 if (visible_ids
[i
] != id
) {
1251 var e
= $("RROW-" + visible_ids
[i
]);
1253 if (e
&& e
.hasClassName("Unread")) {
1254 ids_to_mark
.push(visible_ids
[i
]);
1262 if (ids_to_mark
.length
== 0) {
1263 alert(__("No articles found to mark"));
1265 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1267 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1269 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1270 var e
= $("RROW-" + ids_to_mark
[i
]);
1271 e
.removeClassName("Unread");
1274 var query
= "?op=rpc&method=catchupSelected" +
1275 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1277 new Ajax
.Request("backend.php", {
1279 onComplete: function(transport
) {
1280 handle_rpc_json(transport
);
1287 exception_error("catchupRelativeToArticle", e
);
1291 function cdmExpandArticle(id
) {
1296 var elem
= $("CICD-" + active_post_id
);
1298 if (id
== active_post_id
&& Element
.visible(elem
))
1301 selectArticles("none");
1303 var old_offset
= $("RROW-" + id
).offsetTop
;
1305 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1307 Element
.show("CEXC-" + active_post_id
);
1310 active_post_id
= id
;
1312 elem
= $("CICD-" + id
);
1314 if (!Element
.visible(elem
)) {
1316 Element
.hide("CEXC-" + id
);
1319 var new_offset
= $("RROW-" + id
).offsetTop
;
1321 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1323 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1324 $("headlines-frame").scrollTop
= new_offset
;
1326 toggleUnread(id
, 0, true);
1330 exception_error("cdmExpandArticle", e
);
1336 function fixHeadlinesOrder(ids
) {
1338 for (var i
= 0; i
< ids
.length
; i
++) {
1339 var e
= $("RROW-" + ids
[i
]);
1343 e
.removeClassName("even");
1344 e
.addClassName("odd");
1346 e
.removeClassName("odd");
1347 e
.addClassName("even");
1352 exception_error("fixHeadlinesOrder", e
);
1356 function getArticleUnderPointer() {
1357 return post_under_pointer
;
1360 function zoomToArticle(event
, id
) {
1362 var cached_article
= cache_get("article: " + id
);
1364 if (dijit
.byId("ATAB-" + id
))
1365 if (!event
|| !event
.shiftKey
)
1366 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1368 if (dijit
.byId("ATSTRTIP-" + id
))
1369 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1371 if (cached_article
) {
1372 //closeArticlePanel();
1374 var article_pane
= new dijit
.layout
.ContentPane({
1375 title
: __("Loading...") , content
: cached_article
,
1376 style
: 'padding : 0px;',
1380 dijit
.byId("content-tabs").addChild(article_pane
);
1382 if (!event
|| !event
.shiftKey
)
1383 dijit
.byId("content-tabs").selectChild(article_pane
);
1385 if ($("PTITLE-" + id
))
1386 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1390 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1392 notify_progress("Loading, please wait...", true);
1394 new Ajax
.Request("backend.php", {
1396 onComplete: function(transport
) {
1399 var reply
= JSON
.parse(transport
.responseText
);
1402 //closeArticlePanel();
1404 var content
= reply
[0]['content'];
1406 var article_pane
= new dijit
.layout
.ContentPane({
1407 title
: "article-" + id
, content
: content
,
1408 style
: 'padding : 0px;',
1412 dijit
.byId("content-tabs").addChild(article_pane
);
1414 if (!event
|| !event
.shiftKey
)
1415 dijit
.byId("content-tabs").selectChild(article_pane
);
1417 if ($("PTITLE-" + id
))
1418 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1425 exception_error("zoomToArticle", e
);
1429 function scrollArticle(offset
) {
1432 var ci
= $("content-insert");
1434 ci
.scrollTop
+= offset
;
1437 var hi
= $("headlines-frame");
1439 hi
.scrollTop
+= offset
;
1444 exception_error("scrollArticle", e
);
1448 function show_labels_in_headlines(transport
) {
1450 var data
= JSON
.parse(transport
.responseText
);
1453 data
['info-for-headlines'].each(function(elem
) {
1454 var ctr
= $("HLLCTR-" + elem
.id
);
1456 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1459 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1463 exception_error("show_labels_in_headlines", e
);
1467 /* function toggleHeadlineActions() {
1469 var e = $("headlineActionsBody");
1470 var p = $("headlineActionsDrop");
1472 if (!Element.visible(e)) {
1479 e.style.left = (p.offsetLeft + 1) + "px";
1480 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1483 exception_error("toggleHeadlineActions", e);
1487 /* function publishWithNote(id, def_note) {
1489 if (!def_note) def_note = '';
1491 var note = prompt(__("Please enter a note for this article:"), def_note);
1493 if (note != undefined) {
1494 togglePub(id, false, false, note);
1498 exception_error("publishWithNote", e);
1502 function dismissArticle(id
) {
1504 var elem
= $("RROW-" + id
);
1506 toggleUnread(id
, 0, true);
1508 new Effect
.Fade(elem
, {duration
: 0.5});
1510 active_post_id
= false;
1513 exception_error("dismissArticle", e
);
1517 function dismissSelectedArticles() {
1520 var ids
= getVisibleArticleIds();
1524 for (var i
= 0; i
< ids
.length
; i
++) {
1525 var elem
= $("RROW-" + ids
[i
]);
1527 if (elem
.className
&& elem
.hasClassName("Selected") &&
1528 ids
[i
] != active_post_id
) {
1529 new Effect
.Fade(elem
, {duration
: 0.5});
1537 selectionToggleUnread(false);
1539 fixHeadlinesOrder(tmp
);
1542 exception_error("dismissSelectedArticles", e
);
1546 function dismissReadArticles() {
1549 var ids
= getVisibleArticleIds();
1552 for (var i
= 0; i
< ids
.length
; i
++) {
1553 var elem
= $("RROW-" + ids
[i
]);
1555 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1556 !elem
.hasClassName("Selected")) {
1558 new Effect
.Fade(elem
, {duration
: 0.5});
1564 fixHeadlinesOrder(tmp
);
1567 exception_error("dismissSelectedArticles", e
);
1571 function getVisibleArticleIds() {
1576 getLoadedArticleIds().each(function(id
) {
1577 var elem
= $("RROW-" + id
);
1578 if (elem
&& Element
.visible(elem
))
1583 exception_error("getVisibleArticleIds", e
);
1589 function cdmClicked(event
, id
) {
1591 //var shift_key = event.shiftKey;
1595 if (!event
.ctrlKey
) {
1597 if (!getInitParam("cdm_expanded")) {
1598 return cdmExpandArticle(id
);
1601 selectArticles("none");
1604 var elem
= $("RROW-" + id
);
1605 var article_is_unread
= elem
.hasClassName("Unread");
1608 elem
.removeClassName("Unread");
1610 active_post_id
= id
;
1612 if (article_is_unread
) {
1613 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1616 var query
= "?op=rpc&method=catchupSelected" +
1617 "&cmode=0&ids=" + param_escape(id
);
1619 new Ajax
.Request("backend.php", {
1621 onComplete: function(transport
) {
1622 handle_rpc_json(transport
);
1629 toggleSelected(id
, true);
1631 var elem
= $("RROW-" + id
);
1632 var article_is_unread
= elem
.hasClassName("Unread");
1634 if (article_is_unread
) {
1635 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1638 toggleUnread(id
, 0, false);
1639 zoomToArticle(event
, id
);
1643 exception_error("cdmClicked");
1649 function postClicked(event
, id
) {
1652 if (!event
.ctrlKey
) {
1655 postOpenInNewTab(event
, id
);
1660 exception_error("postClicked");
1664 function hlOpenInNewTab(event
, id
) {
1665 toggleUnread(id
, 0, false);
1666 zoomToArticle(event
, id
);
1669 function postOpenInNewTab(event
, id
) {
1670 closeArticlePanel(id
);
1671 zoomToArticle(event
, id
);
1674 function hlClicked(event
, id
) {
1676 if (event
.which
== 2) {
1679 } else if (event
.altKey
) {
1680 openArticleInNewWindow(id
);
1681 } else if (!event
.ctrlKey
) {
1686 toggleUnread(id
, 0, false);
1687 zoomToArticle(event
, id
);
1692 exception_error("hlClicked");
1696 function getFirstVisibleHeadlineId() {
1697 var rows
= getVisibleArticleIds();
1702 function getLastVisibleHeadlineId() {
1703 var rows
= getVisibleArticleIds();
1704 return rows
[rows
.length
-1];
1707 function openArticleInNewWindow(id
) {
1708 toggleUnread(id
, 0, false);
1709 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1712 function isCdmMode() {
1713 return getInitParam("combined_display_mode");
1716 function markHeadline(id
) {
1717 var row
= $("RROW-" + id
);
1719 var check
= dijit
.byId("RCHK-" + id
);
1722 check
.attr("checked", true);
1725 row
.addClassName("Selected");
1729 function getRelativePostIds(id
, limit
) {
1735 if (!limit
) limit
= 6; //3
1737 var ids
= getVisibleArticleIds();
1739 for (var i
= 0; i
< ids
.length
; i
++) {
1741 for (var k
= 1; k
<= limit
; k
++) {
1742 //if (i > k-1) tmp.push(ids[i-k]);
1743 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1750 exception_error("getRelativePostIds", e
);
1756 function correctHeadlinesOffset(id
) {
1760 var container
= $("headlines-frame");
1761 var row
= $("RROW-" + id
);
1763 if (!container
|| !row
) return;
1765 var viewport
= container
.offsetHeight
;
1767 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1768 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1770 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1771 //console.log("Vport: " + viewport);
1773 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1774 container
.scrollTop
= row
.offsetTop
;
1775 } else if (rel_offset_bottom
> viewport
) {
1777 /* doesn't properly work with Opera in some cases because
1778 Opera fucks up element scrolling */
1780 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1784 exception_error("correctHeadlinesOffset", e
);
1789 function headlineActionsChange(elem
) {
1792 elem
.attr('value', 'false');
1794 exception_error("headlineActionsChange", e
);
1798 function closeArticlePanel() {
1800 var tabs
= dijit
.byId("content-tabs");
1801 var child
= tabs
.selectedChildWidget
;
1803 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1804 tabs
.removeChild(child
);
1807 if (dijit
.byId("content-insert"))
1808 dijit
.byId("headlines-wrap-inner").removeChild(
1809 dijit
.byId("content-insert"));
1813 function initHeadlinesMenu() {
1815 if (dijit
.byId("headlinesMenu"))
1816 dijit
.byId("headlinesMenu").destroyRecursive();
1821 nodes
= $$("#headlines-frame > div[id*=RROW]");
1823 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1826 nodes
.each(function(node
) {
1830 var menu
= new dijit
.Menu({
1831 id
: "headlinesMenu",
1835 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1836 var callerNode
= event
.target
, match
= null, tries
= 0;
1838 while (match
== null && callerNode
&& tries
<= 3) {
1839 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1840 callerNode
= callerNode
.parentNode
;
1844 if (match
) this.callerRowId
= parseInt(match
[1]);
1848 /* if (!isCdmMode())
1849 menu.addChild(new dijit.MenuItem({
1850 label: __("View article"),
1851 onClick: function(event) {
1852 view(this.getParent().callerRowId);
1855 menu
.addChild(new dijit
.MenuItem({
1856 label
: __("Open original article"),
1857 onClick: function(event
) {
1858 openArticleInNewWindow(this.getParent().callerRowId
);
1861 menu
.addChild(new dijit
.MenuItem({
1862 label
: __("View in a tt-rss tab"),
1863 onClick: function(event
) {
1864 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1867 menu
.addChild(new dijit
.MenuSeparator());
1869 menu
.addChild(new dijit
.MenuItem({
1870 label
: __("Mark above as read"),
1871 onClick: function(event
) {
1872 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1875 menu
.addChild(new dijit
.MenuItem({
1876 label
: __("Mark below as read"),
1877 onClick: function(event
) {
1878 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1882 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1886 menu
.addChild(new dijit
.MenuSeparator());
1888 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1889 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1891 labels
.each(function(label
) {
1892 var id
= label
.id
[0];
1893 var bare_id
= id
.substr(id
.indexOf(":")+1);
1894 var name
= label
.name
[0];
1896 bare_id
= -11-bare_id
;
1898 labelAddMenu
.addChild(new dijit
.MenuItem({
1901 onClick: function(event
) {
1902 var ids
= getSelectedArticleIds2();
1904 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1906 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1908 selectionAssignLabel(this.labelId
, ids
);
1911 labelDelMenu
.addChild(new dijit
.MenuItem({
1914 onClick: function(event
) {
1915 var ids
= getSelectedArticleIds2();
1917 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1919 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1921 selectionRemoveLabel(this.labelId
, ids
);
1926 menu
.addChild(new dijit
.PopupMenuItem({
1927 label
: __("Assign label"),
1928 popup
: labelAddMenu
,
1931 menu
.addChild(new dijit
.PopupMenuItem({
1932 label
: __("Remove label"),
1933 popup
: labelDelMenu
,
1941 exception_error("initHeadlinesMenu", e
);
1946 function player(elem
) {
1947 var aid
= elem
.getAttribute("audio-id");
1948 var status
= elem
.getAttribute("status");
1956 elem
.innerHTML
= __("Playing...");
1957 elem
.title
= __("Click to pause");
1958 elem
.addClassName("playing");
1962 elem
.innerHTML
= __("Play");
1963 elem
.title
= __("Click to play");
1964 elem
.removeClassName("playing");
1967 elem
.setAttribute("status", status
);
1969 alert("Your browser doesn't seem to support HTML5 audio.");
1973 function cache_set(id
, obj
) {
1974 //console.log("cache_set: " + id);
1977 sessionStorage
[id
] = obj
;
1979 sessionStorage
.clear();
1983 function cache_get(id
) {
1985 return sessionStorage
[id
];
1988 function cache_clear() {
1990 sessionStorage
.clear();
1993 function cache_delete(id
) {
1995 sessionStorage
.removeItem(id
);
1998 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
1999 if (toolbar_obj
&& content_obj
) {
2000 cache_set("feed:" + feed
+ ":" + is_cat
,
2001 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2004 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2007 obj
= JSON
.parse(obj
);
2009 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2010 if (content_obj
) obj
.content
= content_obj
;
2012 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2016 console
.warn("cache_headlines failed: " + e
);
2021 function render_local_headlines(feed
, is_cat
, obj
) {
2024 dijit
.byId("headlines-toolbar").attr('content',
2027 dijit
.byId("headlines-frame").attr('content',
2030 dojo
.parser
.parse('headlines-toolbar');
2032 $("headlines-frame").scrollTop
= 0;
2033 selectArticles('none');
2034 setActiveFeedId(feed
, is_cat
);
2035 initHeadlinesMenu();
2037 dijit
.getEnclosingWidget(
2038 document
.forms
["main_toolbar_form"].update
).attr('disabled',
2039 is_cat
|| feed
<= 0);
2041 precache_headlines();
2044 exception_error("render_local_headlines", e
);
2048 function precache_headlines_idle() {
2050 if (!feed_precache_timeout_id
) {
2051 if (get_timestamp() - _viewfeed_last
> 120) {
2053 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2056 feeds
.each(function(item
) {
2057 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2058 uncached
.push(item
);
2061 if (uncached
.length
> 0) {
2062 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2063 viewfeed(rf
[0], '', rf
[1], 0, true);
2067 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2070 exception_error("precache_headlines_idle", e
);
2074 function precache_headlines() {
2077 if (!feed_precache_timeout_id
) {
2078 feed_precache_timeout_id
= window
.setTimeout(function() {
2079 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2080 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2082 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2083 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2085 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2086 viewfeed(nf
[0], '', nf
[1], 0, true);
2088 window
.setTimeout(function() {
2089 feed_precache_timeout_id
= false;
2095 exception_error("precache_headlines", e
);
2099 function cancelSearch() {
2104 exception_error("cancelSearch", e
);
2108 function setSelectionScore() {
2110 var ids
= getSelectedArticleIds2();
2112 if (ids
.length
> 0) {
2115 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2117 if (score
!= undefined) {
2118 var query
= "op=rpc&method=setScore&id=" + param_escape(ids
.toString()) +
2119 "&score=" + param_escape(score
);
2121 new Ajax
.Request("backend.php", {
2123 onComplete: function(transport
) {
2124 var reply
= JSON
.parse(transport
.responseText
);
2128 ids
.each(function(id
) {
2129 var row
= $("RROW-" + id
);
2132 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2135 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2136 reply
["score_pic"]);
2137 pic
.setAttribute("score", score
);
2146 alert(__("No articles are selected."));
2149 exception_error("setSelectionScore", e
);
2153 function changeScore(id
, pic
) {
2155 var score
= pic
.getAttribute("score");
2157 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2159 if (new_score
!= undefined) {
2161 var query
= "op=rpc&method=setScore&id=" + param_escape(id
) +
2162 "&score=" + param_escape(new_score
);
2164 new Ajax
.Request("backend.php", {
2166 onComplete: function(transport
) {
2167 var reply
= JSON
.parse(transport
.responseText
);
2170 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2171 pic
.setAttribute("score", new_score
);
2176 exception_error("changeScore", e
);