]>
git.wh0rd.org - tt-rss.git/blob - js/viewfeed.js
cbb10c3f14a2eed78893b1acf6b1bcbdd61104b3
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
);
56 dijit
.getEnclosingWidget(
57 document
.forms
["main_toolbar_form"].update
).attr('disabled',
58 is_cat
|| feed_id
<= 0);
61 if (offset
== 0 && infscroll_req
== false) {
62 $("headlines-frame").scrollTop
= 0;
66 var headlines_count
= reply
['headlines-info']['count'];
68 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
70 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
71 _infscroll_disable
= 1;
73 _infscroll_disable
= 0;
76 var counters
= reply
['counters'];
77 var articles
= reply
['articles'];
78 //var runtime_info = reply['runtime-info'];
80 if (offset
== 0 && infscroll_req
== false) {
81 dijit
.byId("headlines-frame").attr('content',
82 reply
['headlines']['content']);
84 dijit
.byId("headlines-toolbar").attr('content',
85 reply
['headlines']['toolbar']);
87 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
88 if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
> 1) {
89 row
.parentNode
.removeChild(row
);
93 if (getInitParam("cdm_auto_catchup") == 1) {
94 var hsp
= $("headlines-spacer");
95 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
96 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
102 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
103 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
109 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
110 console
.log("adding some more headlines: " + headlines_count
);
112 var c
= dijit
.byId("headlines-frame");
113 var ids
= getSelectedArticleIds2();
116 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
118 var hsp
= $("headlines-spacer");
121 c
.domNode
.removeChild(hsp
);
123 $$("#headlines-tmp > div").each(function(row
) {
124 if (row
.className
== 'cdmFeedTitle') {
125 row
.addClassName('new');
126 row
.style
.display
= 'none';
127 c
.domNode
.appendChild(row
);
129 } else if ($$("#headlines-frame DIV[id="+row
.id
+"]").length
== 0) {
130 row
.style
.display
= 'none';
131 row
.addClassName('new');
132 c
.domNode
.appendChild(row
);
135 row
.parentNode
.removeChild(row
);
139 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
141 fixHeadlinesOrder(getLoadedArticleIds());
143 if (getInitParam("cdm_auto_catchup") == 1) {
144 c
.domNode
.appendChild(hsp
);
147 console
.log("added " + num_added
+ " headlines");
150 _infscroll_disable
= true;
152 console
.log("restore selected ids: " + ids
);
154 for (var i
= 0; i
< ids
.length
; i
++) {
155 markHeadline(ids
[i
]);
160 $$("#headlines-frame > div[class*=new]").each(
162 child
.removeClassName('new');
163 if (!Element
.visible(child
))
164 new Effect
.Appear(child
, { duration
: 0.5 });
168 console
.log("no new headlines received");
170 var hsp
= $("headlines-spacer");
172 if (hsp
) hsp
.innerHTML
= "";
176 if (headlines_count
> 0)
177 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
180 for (var i
= 0; i
< articles
.length
; i
++) {
181 var a_id
= articles
[i
]['id'];
182 cache_set("article:" + a_id
, articles
[i
]['content']);
185 console
.log("no cached articles received");
188 // do not precache stuff after fresh feed
190 precache_headlines();
193 parse_counters(counters
);
198 console
.error("Invalid object received: " + transport
.responseText
);
199 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
200 __('Could not update headlines (invalid object received - see error console for details)') +
204 _infscroll_request_sent
= 0;
209 exception_error("headlines_callback2", e
, transport
);
213 function render_article(article
) {
215 dijit
.byId("headlines-wrap-inner").addChild(
216 dijit
.byId("content-insert"));
218 var c
= dijit
.byId("content-insert");
221 c
.domNode
.scrollTop
= 0;
224 c
.attr('content', article
);
226 correctHeadlinesOffset(getActiveArticleId());
233 exception_error("render_article", e
);
237 function showArticleInHeadlines(id
) {
241 selectArticles("none");
243 var crow
= $("RROW-" + id
);
247 var article_is_unread
= crow
.hasClassName("Unread");
249 crow
.removeClassName("Unread");
251 selectArticles('none');
253 var upd_img_pic
= $("FUPDPIC-" + id
);
255 var view_mode
= false;
258 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
259 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
264 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
265 upd_img_pic
.src
.match("fresh_sign.png"))) {
267 upd_img_pic
.src
= "images/blank_icon.gif";
269 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
271 } else if (article_is_unread
&& view_mode
== "all_articles") {
272 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
277 if (article_is_unread
)
278 _force_scheduled_update
= true;
281 exception_error("showArticleInHeadlines", e
);
285 function article_callback2(transport
, id
) {
287 console
.log("article_callback2 " + id
);
289 handle_rpc_json(transport
);
294 reply
= JSON
.parse(transport
.responseText
);
301 var upic
= $('FUPDPIC-' + id
);
303 if (upic
) upic
.src
= 'images/blank_icon.gif';
305 reply
.each(function(article
) {
306 if (active_post_id
== article
['id']) {
307 render_article(article
['content']);
309 cids_requested
.remove(article
['id']);
311 cache_set("article:" + article
['id'], article
['content']);
314 // if (id != last_requested_article) {
315 // console.log("requested article id is out of sequence, aborting");
320 console
.error("Invalid object received: " + transport
.responseText
);
322 render_article("<div class='whiteBox'>" +
323 __('Could not display article (invalid object received - see error console for details)') + "</div>");
328 headlines_scroll_handler($("headlines-frame"));
331 if (!_infscroll_disable &&
332 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
342 exception_error("article_callback2", e
, transport
);
348 console
.log("loading article: " + id
);
350 var cached_article
= cache_get("article:" + id
);
352 console
.log("cache check result: " + (cached_article
!= false));
356 var query
= "?op=article&method=view&id=" + param_escape(id
);
358 var neighbor_ids
= getRelativePostIds(id
);
360 /* only request uncached articles */
362 var cids_to_request
= [];
364 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
365 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
366 if (!cache_get("article:" + neighbor_ids
[i
])) {
367 cids_to_request
.push(neighbor_ids
[i
]);
368 cids_requested
.push(neighbor_ids
[i
]);
372 console
.log("additional ids: " + cids_to_request
.toString());
374 query
= query
+ "&cids=" + cids_to_request
.toString();
376 var crow
= $("RROW-" + id
);
377 var article_is_unread
= crow
.hasClassName("Unread");
380 showArticleInHeadlines(id
);
382 precache_headlines();
384 if (!cached_article
) {
386 var upic
= $('FUPDPIC-' + id
);
389 upic
.src
= getInitParam("sign_progress");
392 } else if (cached_article
&& article_is_unread
) {
394 query
= query
+ "&mode=prefetch";
396 render_article(cached_article
);
398 } else if (cached_article
) {
400 query
= query
+ "&mode=prefetch_old";
401 render_article(cached_article
);
403 // if we don't need to request any relative ids, we might as well skip
404 // the server roundtrip altogether
405 if (cids_to_request
.length
== 0) {
408 if (!_infscroll_disable &&
409 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
417 headlines_scroll_handler($("headlines-frame"));
423 last_requested_article
= id
;
427 if (article_is_unread
) {
428 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
431 new Ajax
.Request("backend.php", {
433 onComplete: function(transport
) {
434 article_callback2(transport
, id
);
440 exception_error("view", e
);
444 function toggleMark(id
, client_only
) {
446 var query
= "?op=rpc&id=" + id
+ "&method=mark";
448 var img
= $("FMPIC-" + id
);
452 if (img
.src
.match("mark_unset")) {
453 img
.src
= img
.src
.replace("mark_unset", "mark_set");
454 img
.alt
= __("Unstar article");
455 query
= query
+ "&mark=1";
458 img
.src
= img
.src
.replace("mark_set", "mark_unset");
459 img
.alt
= __("Star article");
460 query
= query
+ "&mark=0";
463 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
466 new Ajax
.Request("backend.php", {
468 onComplete: function(transport
) {
469 handle_rpc_json(transport
);
474 exception_error("toggleMark", e
);
478 function togglePub(id
, client_only
, no_effects
, note
) {
480 var query
= "?op=rpc&id=" + id
+ "&method=publ";
482 if (note
!= undefined) {
483 query
= query
+ "¬e=" + param_escape(note
);
485 query
= query
+ "¬e=undefined";
488 var img
= $("FPPIC-" + id
);
492 if (img
.src
.match("pub_unset") || note
!= undefined) {
493 img
.src
= img
.src
.replace("pub_unset", "pub_set");
494 img
.alt
= __("Unpublish article");
495 query
= query
+ "&pub=1";
498 img
.src
= img
.src
.replace("pub_set", "pub_unset");
499 img
.alt
= __("Publish article");
501 query
= query
+ "&pub=0";
504 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
507 new Ajax
.Request("backend.php", {
509 onComplete: function(transport
) {
510 handle_rpc_json(transport
);
515 exception_error("togglePub", e
);
519 function moveToPost(mode
) {
523 var rows
= getVisibleArticleIds();
528 if (!$('RROW-' + active_post_id
)) {
529 active_post_id
= false;
532 if (active_post_id
== false) {
534 prev_id
= rows
[rows
.length
-1]
536 for (var i
= 0; i
< rows
.length
; i
++) {
537 if (rows
[i
] == active_post_id
) {
539 // Account for adjacent identical article ids.
540 if (i
> 0) prev_id
= rows
[i
-1];
542 for (var j
= i
+1; j
< rows
.length
; j
++) {
543 if (rows
[j
] != active_post_id
) {
553 if (mode
== "next") {
557 cdmExpandArticle(next_id
);
558 cdmScrollToArticleId(next_id
);
561 correctHeadlinesOffset(next_id
);
562 view(next_id
, getActiveFeedId());
567 if (mode
== "prev") {
570 cdmExpandArticle(prev_id
);
571 cdmScrollToArticleId(prev_id
);
573 correctHeadlinesOffset(prev_id
);
574 view(prev_id
, getActiveFeedId());
580 exception_error("moveToPost", e
);
584 function toggleSelected(id
, force_on
) {
587 var cb
= $("RCHK-" + id
);
588 var row
= $("RROW-" + id
);
591 if (row
.hasClassName('Selected') && !force_on
) {
592 row
.removeClassName('Selected');
593 if (cb
) cb
.checked
= false;
595 row
.addClassName('Selected');
596 if (cb
) cb
.checked
= true;
600 exception_error("toggleSelected", e
);
604 function toggleUnread_afh(effect
) {
607 var elem
= effect
.element
;
608 elem
.style
.backgroundColor
= "";
611 exception_error("toggleUnread_afh", e
);
615 function toggleUnread(id
, cmode
, effect
) {
618 var row
= $("RROW-" + id
);
620 if (cmode
== undefined || cmode
== 2) {
621 if (row
.hasClassName("Unread")) {
622 row
.removeClassName("Unread");
625 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
626 afterFinish
: toggleUnread_afh
,
627 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
631 row
.addClassName("Unread");
634 } else if (cmode
== 0) {
636 row
.removeClassName("Unread");
639 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
640 afterFinish
: toggleUnread_afh
,
641 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
644 } else if (cmode
== 1) {
645 row
.addClassName("Unread");
648 if (cmode
== undefined) cmode
= 2;
650 var query
= "?op=rpc&method=catchupSelected" +
651 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
653 // notify_progress("Loading, please wait...");
655 new Ajax
.Request("backend.php", {
657 onComplete: function(transport
) {
658 handle_rpc_json(transport
);
664 exception_error("toggleUnread", e
);
668 function selectionRemoveLabel(id
, ids
) {
671 if (!ids
) ids
= getSelectedArticleIds2();
673 if (ids
.length
== 0) {
674 alert(__("No articles are selected."));
678 var query
= "?op=rpc&method=removeFromLabel&ids=" +
679 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
683 new Ajax
.Request("backend.php", {
685 onComplete: function(transport
) {
686 handle_rpc_json(transport
);
687 show_labels_in_headlines(transport
);
691 exception_error("selectionAssignLabel", e
);
696 function selectionAssignLabel(id
, ids
) {
699 if (!ids
) ids
= getSelectedArticleIds2();
701 if (ids
.length
== 0) {
702 alert(__("No articles are selected."));
706 var query
= "?op=rpc&method=assignToLabel&ids=" +
707 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
711 new Ajax
.Request("backend.php", {
713 onComplete: function(transport
) {
714 handle_rpc_json(transport
);
715 show_labels_in_headlines(transport
);
719 exception_error("selectionAssignLabel", e
);
724 function selectionToggleUnread(set_state
, callback
, no_error
) {
726 var rows
= getSelectedArticleIds2();
728 if (rows
.length
== 0 && !no_error
) {
729 alert(__("No articles are selected."));
733 for (var i
= 0; i
< rows
.length
; i
++) {
734 var row
= $("RROW-" + rows
[i
]);
736 if (set_state
== undefined) {
737 if (row
.hasClassName("Unread")) {
738 row
.removeClassName("Unread");
740 row
.addClassName("Unread");
744 if (set_state
== false) {
745 row
.removeClassName("Unread");
748 if (set_state
== true) {
749 row
.addClassName("Unread");
754 if (rows
.length
> 0) {
758 if (set_state
== undefined) {
760 } else if (set_state
== true) {
762 } else if (set_state
== false) {
766 var query
= "?op=rpc&method=catchupSelected" +
767 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
769 notify_progress("Loading, please wait...");
771 new Ajax
.Request("backend.php", {
773 onComplete: function(transport
) {
774 handle_rpc_json(transport
);
775 if (callback
) callback(transport
);
781 exception_error("selectionToggleUnread", e
);
785 function selectionToggleMarked() {
788 var rows
= getSelectedArticleIds2();
790 if (rows
.length
== 0) {
791 alert(__("No articles are selected."));
795 for (var i
= 0; i
< rows
.length
; i
++) {
796 toggleMark(rows
[i
], true, true);
799 if (rows
.length
> 0) {
801 var query
= "?op=rpc&method=markSelected&ids=" +
802 param_escape(rows
.toString()) + "&cmode=2";
804 new Ajax
.Request("backend.php", {
806 onComplete: function(transport
) {
807 handle_rpc_json(transport
);
813 exception_error("selectionToggleMarked", e
);
817 function selectionTogglePublished() {
820 var rows
= getSelectedArticleIds2();
822 if (rows
.length
== 0) {
823 alert(__("No articles are selected."));
827 for (var i
= 0; i
< rows
.length
; i
++) {
828 togglePub(rows
[i
], true, true);
831 if (rows
.length
> 0) {
833 var query
= "?op=rpc&method=publishSelected&ids=" +
834 param_escape(rows
.toString()) + "&cmode=2";
836 new Ajax
.Request("backend.php", {
838 onComplete: function(transport
) {
839 handle_rpc_json(transport
);
845 exception_error("selectionToggleMarked", e
);
849 function getSelectedArticleIds2() {
853 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
855 rv
.push(child
.id
.replace("RROW-", ""));
861 function getLoadedArticleIds() {
864 var children
= $$("#headlines-frame > div[id*=RROW-]");
866 children
.each(function(child
) {
867 rv
.push(child
.id
.replace("RROW-", ""));
874 // mode = all,none,unread,invert,marked,published
875 function selectArticles(mode
) {
878 var children
= $$("#headlines-frame > div[id*=RROW]");
880 children
.each(function(child
) {
881 var id
= child
.id
.replace("RROW-", "");
882 var cb
= $("RCHK-" + id
);
885 child
.addClassName("Selected");
887 } else if (mode
== "unread") {
888 if (child
.hasClassName("Unread")) {
889 child
.addClassName("Selected");
892 child
.removeClassName("Selected");
895 } else if (mode
== "marked") {
896 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
898 if (img
&& img
.src
.match("mark_set")) {
899 child
.addClassName("Selected");
902 child
.removeClassName("Selected");
905 } else if (mode
== "published") {
906 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
908 if (img
&& img
.src
.match("pub_set")) {
909 child
.addClassName("Selected");
912 child
.removeClassName("Selected");
916 } else if (mode
== "invert") {
917 if (child
.hasClassName("Selected")) {
918 child
.removeClassName("Selected");
921 child
.addClassName("Selected");
926 child
.removeClassName("Selected");
932 exception_error("selectArticles", e
);
936 function catchupPage() {
938 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
940 var str
= __("Mark all visible articles in %s as read?");
942 str
= str
.replace("%s", fn
);
944 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
948 selectArticles('all');
949 selectionToggleUnread(false, 'viewCurrentFeed()', true);
950 selectArticles('none');
953 function deleteSelection() {
957 var rows
= getSelectedArticleIds2();
959 if (rows
.length
== 0) {
960 alert(__("No articles are selected."));
964 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
967 if (getActiveFeedId() != 0) {
968 str
= __("Delete %d selected articles in %s?");
970 str
= __("Delete %d selected articles?");
973 str
= str
.replace("%d", rows
.length
);
974 str
= str
.replace("%s", fn
);
976 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
980 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
984 new Ajax
.Request("backend.php", {
986 onComplete: function(transport
) {
987 handle_rpc_json(transport
);
992 exception_error("deleteSelection", e
);
996 function archiveSelection() {
1000 var rows
= getSelectedArticleIds2();
1002 if (rows
.length
== 0) {
1003 alert(__("No articles are selected."));
1007 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1011 if (getActiveFeedId() != 0) {
1012 str
= __("Archive %d selected articles in %s?");
1015 str
= __("Move %d archived articles back?");
1019 str
= str
.replace("%d", rows
.length
);
1020 str
= str
.replace("%s", fn
);
1022 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1026 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1030 for (var i
= 0; i
< rows
.length
; i
++) {
1031 cache_delete("article:" + rows
[i
]);
1034 new Ajax
.Request("backend.php", {
1036 onComplete: function(transport
) {
1037 handle_rpc_json(transport
);
1042 exception_error("archiveSelection", e
);
1046 function catchupSelection() {
1050 var rows
= getSelectedArticleIds2();
1052 if (rows
.length
== 0) {
1053 alert(__("No articles are selected."));
1057 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1059 var str
= __("Mark %d selected articles in %s as read?");
1061 str
= str
.replace("%d", rows
.length
);
1062 str
= str
.replace("%s", fn
);
1064 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1068 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1071 exception_error("catchupSelection", e
);
1075 function editArticleTags(id
) {
1076 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1078 if (dijit
.byId("editTagsDlg"))
1079 dijit
.byId("editTagsDlg").destroyRecursive();
1081 dialog
= new dijit
.Dialog({
1083 title
: __("Edit article Tags"),
1084 style
: "width: 600px",
1085 execute: function() {
1086 if (this.validate()) {
1087 var query
= dojo
.objectToQuery(this.attr('value'));
1089 notify_progress("Saving article tags...", true);
1091 new Ajax
.Request("backend.php", {
1093 onComplete: function(transport
) {
1097 var data
= JSON
.parse(transport
.responseText
);
1100 var tags_str
= article
.tags
;
1101 var id
= tags_str
.id
;
1103 var tags
= $("ATSTR-" + id
);
1104 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1106 if (tags
) tags
.innerHTML
= tags_str
.content
;
1107 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1109 cache_delete("article:" + id
);
1118 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1119 dojo
.disconnect(tmph
);
1121 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1122 "backend.php?op=rpc&method=completeTags",
1123 { tokens
: ',', paramName
: "search" });
1130 function cdmScrollToArticleId(id
) {
1132 var ctr
= $("headlines-frame");
1133 var e
= $("RROW-" + id
);
1135 if (!e
|| !ctr
) return;
1137 ctr
.scrollTop
= e
.offsetTop
;
1140 exception_error("cdmScrollToArticleId", e
);
1144 function getActiveArticleId() {
1145 return active_post_id
;
1148 function postMouseIn(id
) {
1149 post_under_pointer
= id
;
1152 function postMouseOut(id
) {
1153 post_under_pointer
= false;
1156 function headlines_scroll_handler(e
) {
1158 var hsp
= $("headlines-spacer");
1160 if (!_infscroll_disable
) {
1161 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1162 (e
.scrollHeight
!= 0 &&
1163 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1166 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1167 __("Loading, please wait...");
1169 loadMoreHeadlines();
1174 if (hsp
) hsp
.innerHTML
= "";
1177 if (getInitParam("cdm_auto_catchup") == 1) {
1179 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1181 if ($("headlines-frame").scrollTop
>
1182 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1184 var id
= child
.id
.replace("RROW-", "");
1186 if (catchup_id_batch
.indexOf(id
) == -1)
1187 catchup_id_batch
.push(id
);
1189 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1193 if (catchup_id_batch
.length
> 0) {
1194 window
.clearTimeout(catchup_timeout_id
);
1196 if (!_infscroll_request_sent
) {
1197 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1204 console
.warn("headlines_scroll_handler: " + e
);
1208 function catchupBatchedArticles() {
1210 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1212 // make a copy of the array
1213 var batch
= catchup_id_batch
.slice();
1214 var query
= "?op=rpc&method=catchupSelected" +
1215 "&cmode=0&ids=" + param_escape(batch
.toString());
1219 new Ajax
.Request("backend.php", {
1221 onComplete: function(transport
) {
1222 handle_rpc_json(transport
);
1224 batch
.each(function(id
) {
1225 var elem
= $("RROW-" + id
);
1226 if (elem
) elem
.removeClassName("Unread");
1227 catchup_id_batch
.remove(id
);
1234 exception_error("catchupBatchedArticles", e
);
1238 function catchupRelativeToArticle(below
, id
) {
1242 if (!id
) id
= getActiveArticleId();
1245 alert(__("No article is selected."));
1249 var visible_ids
= getVisibleArticleIds();
1251 var ids_to_mark
= new Array();
1254 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1255 if (visible_ids
[i
] != id
) {
1256 var e
= $("RROW-" + visible_ids
[i
]);
1258 if (e
&& e
.hasClassName("Unread")) {
1259 ids_to_mark
.push(visible_ids
[i
]);
1266 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1267 if (visible_ids
[i
] != id
) {
1268 var e
= $("RROW-" + visible_ids
[i
]);
1270 if (e
&& e
.hasClassName("Unread")) {
1271 ids_to_mark
.push(visible_ids
[i
]);
1279 if (ids_to_mark
.length
== 0) {
1280 alert(__("No articles found to mark"));
1282 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1284 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1286 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1287 var e
= $("RROW-" + ids_to_mark
[i
]);
1288 e
.removeClassName("Unread");
1291 var query
= "?op=rpc&method=catchupSelected" +
1292 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1294 new Ajax
.Request("backend.php", {
1296 onComplete: function(transport
) {
1297 handle_rpc_json(transport
);
1304 exception_error("catchupRelativeToArticle", e
);
1308 function cdmExpandArticle(id
) {
1313 var elem
= $("CICD-" + active_post_id
);
1315 var upd_img_pic
= $("FUPDPIC-" + id
);
1317 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1318 upd_img_pic
.src
.match("fresh_sign.png"))) {
1320 upd_img_pic
.src
= "images/blank_icon.gif";
1323 if (id
== active_post_id
&& Element
.visible(elem
))
1326 selectArticles("none");
1328 var old_offset
= $("RROW-" + id
).offsetTop
;
1330 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1332 Element
.show("CEXC-" + active_post_id
);
1335 active_post_id
= id
;
1337 elem
= $("CICD-" + id
);
1339 if (!Element
.visible(elem
)) {
1341 Element
.hide("CEXC-" + id
);
1344 var new_offset
= $("RROW-" + id
).offsetTop
;
1346 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1348 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1349 $("headlines-frame").scrollTop
= new_offset
;
1351 toggleUnread(id
, 0, true);
1355 exception_error("cdmExpandArticle", e
);
1361 function fixHeadlinesOrder(ids
) {
1363 for (var i
= 0; i
< ids
.length
; i
++) {
1364 var e
= $("RROW-" + ids
[i
]);
1368 e
.removeClassName("even");
1369 e
.addClassName("odd");
1371 e
.removeClassName("odd");
1372 e
.addClassName("even");
1377 exception_error("fixHeadlinesOrder", e
);
1381 function getArticleUnderPointer() {
1382 return post_under_pointer
;
1385 function zoomToArticle(event
, id
) {
1387 var cached_article
= cache_get("article: " + id
);
1389 if (dijit
.byId("ATAB-" + id
))
1390 if (!event
|| !event
.shiftKey
)
1391 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1393 if (dijit
.byId("ATSTRTIP-" + id
))
1394 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1396 if (cached_article
) {
1397 //closeArticlePanel();
1399 var article_pane
= new dijit
.layout
.ContentPane({
1400 title
: __("Loading...") , content
: cached_article
,
1401 style
: 'padding : 0px;',
1405 dijit
.byId("content-tabs").addChild(article_pane
);
1407 if (!event
|| !event
.shiftKey
)
1408 dijit
.byId("content-tabs").selectChild(article_pane
);
1410 if ($("PTITLE-" + id
))
1411 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1415 var query
= "?op=rpc&method=getArticles&ids=" + param_escape(id
);
1417 notify_progress("Loading, please wait...", true);
1419 new Ajax
.Request("backend.php", {
1421 onComplete: function(transport
) {
1424 var reply
= JSON
.parse(transport
.responseText
);
1427 //closeArticlePanel();
1429 var content
= reply
[0]['content'];
1431 var article_pane
= new dijit
.layout
.ContentPane({
1432 title
: "article-" + id
, content
: content
,
1433 style
: 'padding : 0px;',
1437 dijit
.byId("content-tabs").addChild(article_pane
);
1439 if (!event
|| !event
.shiftKey
)
1440 dijit
.byId("content-tabs").selectChild(article_pane
);
1442 if ($("PTITLE-" + id
))
1443 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1450 exception_error("zoomToArticle", e
);
1454 function scrollArticle(offset
) {
1457 var ci
= $("content-insert");
1459 ci
.scrollTop
+= offset
;
1462 var hi
= $("headlines-frame");
1464 hi
.scrollTop
+= offset
;
1469 exception_error("scrollArticle", e
);
1473 function show_labels_in_headlines(transport
) {
1475 var data
= JSON
.parse(transport
.responseText
);
1478 data
['info-for-headlines'].each(function(elem
) {
1479 var ctr
= $("HLLCTR-" + elem
.id
);
1481 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1484 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1488 exception_error("show_labels_in_headlines", e
);
1492 /* function toggleHeadlineActions() {
1494 var e = $("headlineActionsBody");
1495 var p = $("headlineActionsDrop");
1497 if (!Element.visible(e)) {
1504 e.style.left = (p.offsetLeft + 1) + "px";
1505 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1508 exception_error("toggleHeadlineActions", e);
1512 /* function publishWithNote(id, def_note) {
1514 if (!def_note) def_note = '';
1516 var note = prompt(__("Please enter a note for this article:"), def_note);
1518 if (note != undefined) {
1519 togglePub(id, false, false, note);
1523 exception_error("publishWithNote", e);
1527 function dismissArticle(id
) {
1529 var elem
= $("RROW-" + id
);
1531 toggleUnread(id
, 0, true);
1533 new Effect
.Fade(elem
, {duration
: 0.5});
1535 active_post_id
= false;
1538 exception_error("dismissArticle", e
);
1542 function dismissSelectedArticles() {
1545 var ids
= getVisibleArticleIds();
1549 for (var i
= 0; i
< ids
.length
; i
++) {
1550 var elem
= $("RROW-" + ids
[i
]);
1552 if (elem
.className
&& elem
.hasClassName("Selected") &&
1553 ids
[i
] != active_post_id
) {
1554 new Effect
.Fade(elem
, {duration
: 0.5});
1562 selectionToggleUnread(false);
1564 fixHeadlinesOrder(tmp
);
1567 exception_error("dismissSelectedArticles", e
);
1571 function dismissReadArticles() {
1574 var ids
= getVisibleArticleIds();
1577 for (var i
= 0; i
< ids
.length
; i
++) {
1578 var elem
= $("RROW-" + ids
[i
]);
1580 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1581 !elem
.hasClassName("Selected")) {
1583 new Effect
.Fade(elem
, {duration
: 0.5});
1589 fixHeadlinesOrder(tmp
);
1592 exception_error("dismissSelectedArticles", e
);
1596 function getVisibleArticleIds() {
1601 getLoadedArticleIds().each(function(id
) {
1602 var elem
= $("RROW-" + id
);
1603 if (elem
&& Element
.visible(elem
))
1608 exception_error("getVisibleArticleIds", e
);
1614 function cdmClicked(event
, id
) {
1616 //var shift_key = event.shiftKey;
1620 if (!event
.ctrlKey
) {
1622 if (!getInitParam("cdm_expanded")) {
1623 return cdmExpandArticle(id
);
1626 selectArticles("none");
1629 var elem
= $("RROW-" + id
);
1630 var article_is_unread
= elem
.hasClassName("Unread");
1633 elem
.removeClassName("Unread");
1635 var upd_img_pic
= $("FUPDPIC-" + id
);
1637 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1638 upd_img_pic
.src
.match("fresh_sign.png"))) {
1640 upd_img_pic
.src
= "images/blank_icon.gif";
1643 active_post_id
= id
;
1645 if (article_is_unread
) {
1646 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1649 var query
= "?op=rpc&method=catchupSelected" +
1650 "&cmode=0&ids=" + param_escape(id
);
1652 new Ajax
.Request("backend.php", {
1654 onComplete: function(transport
) {
1655 handle_rpc_json(transport
);
1662 toggleSelected(id
, true);
1664 var elem
= $("RROW-" + id
);
1665 var article_is_unread
= elem
.hasClassName("Unread");
1667 if (article_is_unread
) {
1668 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1671 toggleUnread(id
, 0, false);
1672 zoomToArticle(event
, id
);
1676 exception_error("cdmClicked");
1682 function postClicked(event
, id
) {
1685 if (!event
.ctrlKey
) {
1688 postOpenInNewTab(event
, id
);
1693 exception_error("postClicked");
1697 function hlOpenInNewTab(event
, id
) {
1698 toggleUnread(id
, 0, false);
1699 zoomToArticle(event
, id
);
1702 function postOpenInNewTab(event
, id
) {
1703 closeArticlePanel(id
);
1704 zoomToArticle(event
, id
);
1707 function hlClicked(event
, id
) {
1709 if (event
.which
== 2) {
1712 } else if (event
.altKey
) {
1713 openArticleInNewWindow(id
);
1714 } else if (!event
.ctrlKey
) {
1719 toggleUnread(id
, 0, false);
1720 zoomToArticle(event
, id
);
1725 exception_error("hlClicked");
1729 function getFirstVisibleHeadlineId() {
1730 var rows
= getVisibleArticleIds();
1735 function getLastVisibleHeadlineId() {
1736 var rows
= getVisibleArticleIds();
1737 return rows
[rows
.length
-1];
1740 function openArticleInNewWindow(id
) {
1741 toggleUnread(id
, 0, false);
1742 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1745 function isCdmMode() {
1746 return getInitParam("combined_display_mode");
1749 function markHeadline(id
) {
1750 var row
= $("RROW-" + id
);
1752 var check
= $("RCHK-" + id
);
1755 check
.checked
= true;
1758 row
.addClassName("Selected");
1762 function getRelativePostIds(id
, limit
) {
1768 if (!limit
) limit
= 6; //3
1770 var ids
= getVisibleArticleIds();
1772 for (var i
= 0; i
< ids
.length
; i
++) {
1774 for (var k
= 1; k
<= limit
; k
++) {
1775 //if (i > k-1) tmp.push(ids[i-k]);
1776 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1783 exception_error("getRelativePostIds", e
);
1789 function correctHeadlinesOffset(id
) {
1793 var container
= $("headlines-frame");
1794 var row
= $("RROW-" + id
);
1796 if (!container
|| !row
) return;
1798 var viewport
= container
.offsetHeight
;
1800 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1801 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1803 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1804 //console.log("Vport: " + viewport);
1806 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1807 container
.scrollTop
= row
.offsetTop
;
1808 } else if (rel_offset_bottom
> viewport
) {
1810 /* doesn't properly work with Opera in some cases because
1811 Opera fucks up element scrolling */
1813 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1817 exception_error("correctHeadlinesOffset", e
);
1822 function headlineActionsChange(elem
) {
1825 elem
.attr('value', 'false');
1827 exception_error("headlineActionsChange", e
);
1831 function closeArticlePanel() {
1833 var tabs
= dijit
.byId("content-tabs");
1834 var child
= tabs
.selectedChildWidget
;
1836 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1837 tabs
.removeChild(child
);
1840 if (dijit
.byId("content-insert"))
1841 dijit
.byId("headlines-wrap-inner").removeChild(
1842 dijit
.byId("content-insert"));
1846 function initHeadlinesMenu() {
1848 if (dijit
.byId("headlinesMenu"))
1849 dijit
.byId("headlinesMenu").destroyRecursive();
1854 nodes
= $$("#headlines-frame > div[id*=RROW]");
1856 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1859 nodes
.each(function(node
) {
1863 var menu
= new dijit
.Menu({
1864 id
: "headlinesMenu",
1868 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1869 var callerNode
= event
.target
, match
= null, tries
= 0;
1871 while (match
== null && callerNode
&& tries
<= 3) {
1872 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1873 callerNode
= callerNode
.parentNode
;
1877 if (match
) this.callerRowId
= parseInt(match
[1]);
1881 /* if (!isCdmMode())
1882 menu.addChild(new dijit.MenuItem({
1883 label: __("View article"),
1884 onClick: function(event) {
1885 view(this.getParent().callerRowId);
1888 menu
.addChild(new dijit
.MenuItem({
1889 label
: __("Open original article"),
1890 onClick: function(event
) {
1891 openArticleInNewWindow(this.getParent().callerRowId
);
1894 menu
.addChild(new dijit
.MenuItem({
1895 label
: __("View in a tt-rss tab"),
1896 onClick: function(event
) {
1897 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1900 menu
.addChild(new dijit
.MenuSeparator());
1902 menu
.addChild(new dijit
.MenuItem({
1903 label
: __("Mark above as read"),
1904 onClick: function(event
) {
1905 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1908 menu
.addChild(new dijit
.MenuItem({
1909 label
: __("Mark below as read"),
1910 onClick: function(event
) {
1911 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1915 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1919 menu
.addChild(new dijit
.MenuSeparator());
1921 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1922 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1924 labels
.each(function(label
) {
1925 var id
= label
.id
[0];
1926 var bare_id
= id
.substr(id
.indexOf(":")+1);
1927 var name
= label
.name
[0];
1929 bare_id
= -11-bare_id
;
1931 labelAddMenu
.addChild(new dijit
.MenuItem({
1934 onClick: function(event
) {
1935 var ids
= getSelectedArticleIds2();
1937 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1939 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1941 selectionAssignLabel(this.labelId
, ids
);
1944 labelDelMenu
.addChild(new dijit
.MenuItem({
1947 onClick: function(event
) {
1948 var ids
= getSelectedArticleIds2();
1950 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1952 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1954 selectionRemoveLabel(this.labelId
, ids
);
1959 menu
.addChild(new dijit
.PopupMenuItem({
1960 label
: __("Assign label"),
1961 popup
: labelAddMenu
,
1964 menu
.addChild(new dijit
.PopupMenuItem({
1965 label
: __("Remove label"),
1966 popup
: labelDelMenu
,
1974 exception_error("initHeadlinesMenu", e
);
1979 function player(elem
) {
1980 var aid
= elem
.getAttribute("audio-id");
1981 var status
= elem
.getAttribute("status");
1989 elem
.innerHTML
= __("Playing...");
1990 elem
.title
= __("Click to pause");
1991 elem
.addClassName("playing");
1995 elem
.innerHTML
= __("Play");
1996 elem
.title
= __("Click to play");
1997 elem
.removeClassName("playing");
2000 elem
.setAttribute("status", status
);
2002 alert("Your browser doesn't seem to support HTML5 audio.");
2006 function cache_set(id
, obj
) {
2007 //console.log("cache_set: " + id);
2010 sessionStorage
[id
] = obj
;
2012 sessionStorage
.clear();
2016 function cache_get(id
) {
2018 return sessionStorage
[id
];
2021 function cache_clear() {
2023 sessionStorage
.clear();
2026 function cache_delete(id
) {
2028 sessionStorage
.removeItem(id
);
2031 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2032 if (toolbar_obj
&& content_obj
) {
2033 cache_set("feed:" + feed
+ ":" + is_cat
,
2034 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2037 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2040 obj
= JSON
.parse(obj
);
2042 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2043 if (content_obj
) obj
.content
= content_obj
;
2045 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2049 console
.warn("cache_headlines failed: " + e
);
2054 function render_local_headlines(feed
, is_cat
, obj
) {
2057 dijit
.byId("headlines-toolbar").attr('content',
2060 dijit
.byId("headlines-frame").attr('content',
2063 dojo
.parser
.parse('headlines-toolbar');
2065 $("headlines-frame").scrollTop
= 0;
2066 selectArticles('none');
2067 setActiveFeedId(feed
, is_cat
);
2068 initHeadlinesMenu();
2070 dijit
.getEnclosingWidget(
2071 document
.forms
["main_toolbar_form"].update
).attr('disabled',
2072 is_cat
|| feed
<= 0);
2074 precache_headlines();
2077 exception_error("render_local_headlines", e
);
2081 function precache_headlines_idle() {
2083 if (!feed_precache_timeout_id
) {
2084 if (get_timestamp() - _viewfeed_last
> 120) {
2086 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2089 feeds
.each(function(item
) {
2090 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2091 uncached
.push(item
);
2094 if (uncached
.length
> 0) {
2095 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2096 viewfeed(rf
[0], '', rf
[1], 0, true);
2100 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
2103 exception_error("precache_headlines_idle", e
);
2107 function precache_headlines() {
2110 if (!feed_precache_timeout_id
) {
2111 feed_precache_timeout_id
= window
.setTimeout(function() {
2112 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2113 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2115 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2116 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2118 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2119 viewfeed(nf
[0], '', nf
[1], 0, true);
2121 window
.setTimeout(function() {
2122 feed_precache_timeout_id
= false;
2128 exception_error("precache_headlines", e
);
2132 function cancelSearch() {
2137 exception_error("cancelSearch", e
);
2141 function changeScore(id
, pic
) {
2143 var score
= pic
.getAttribute("score");
2145 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2147 if (new_score
!= undefined) {
2149 var query
= "op=rpc&method=setScore&id=" + param_escape(id
) +
2150 "&score=" + param_escape(new_score
);
2152 new Ajax
.Request("backend.php", {
2154 onComplete: function(transport
) {
2155 var reply
= JSON
.parse(transport
.responseText
);
2158 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2159 pic
.setAttribute("score", new_score
);
2164 exception_error("changeScore", e
);