]>
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 var cb
= dijit
.byId(child
.id
.replace("RROW-", "RCHK-"));
168 dojo
.parser
.parse(child
);
170 if (!Element
.visible(child
))
171 new Effect
.Appear(child
, { duration
: 0.5 });
173 c
.domNode
.removeChild(child
);
178 console
.log("no new headlines received");
180 var hsp
= $("headlines-spacer");
182 if (hsp
) hsp
.innerHTML
= "";
186 if (headlines_count
> 0)
187 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
190 for (var i
= 0; i
< articles
.length
; i
++) {
191 var a_id
= articles
[i
]['id'];
192 cache_set("article:" + a_id
, articles
[i
]['content']);
195 console
.log("no cached articles received");
198 // do not precache stuff after fresh feed
200 precache_headlines();
203 parse_counters(counters
);
205 request_counters(true);
207 } else if (transport
.responseText
) {
208 console
.error("Invalid object received: " + transport
.responseText
);
209 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
210 __('Could not update headlines (invalid object received - see error console for details)') +
213 //notify_error("Error communicating with server.");
214 Element
.show(dijit
.byId("net-alert").domNode
);
217 _infscroll_request_sent
= 0;
222 exception_error("headlines_callback2", e
, transport
);
226 function render_article(article
) {
228 dijit
.byId("headlines-wrap-inner").addChild(
229 dijit
.byId("content-insert"));
231 var c
= dijit
.byId("content-insert");
234 c
.domNode
.scrollTop
= 0;
237 c
.attr('content', article
);
239 correctHeadlinesOffset(getActiveArticleId());
246 exception_error("render_article", e
);
250 function showArticleInHeadlines(id
) {
254 selectArticles("none");
256 var crow
= $("RROW-" + id
);
260 var article_is_unread
= crow
.hasClassName("Unread");
262 crow
.removeClassName("Unread");
264 selectArticles('none');
266 var view_mode
= false;
269 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
270 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
275 if (article_is_unread
&& view_mode
== "all_articles") {
276 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
281 if (article_is_unread
)
282 _force_scheduled_update
= true;
285 exception_error("showArticleInHeadlines", e
);
289 function article_callback2(transport
, id
) {
291 console
.log("article_callback2 " + id
);
293 handle_rpc_json(transport
);
298 reply
= JSON
.parse(transport
.responseText
);
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");
319 } else if (transport
.responseText
) {
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>");
325 Element
.show(dijit
.byId("net-alert").domNode
);
328 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
329 request_counters(unread_in_buffer
== 0);
331 headlines_scroll_handler($("headlines-frame"));
334 if (!_infscroll_disable &&
335 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
345 exception_error("article_callback2", e
, transport
);
351 var crow
= $("RROW-" + id
);
355 console
.log("loading article: " + id
);
357 var cached_article
= cache_get("article:" + id
);
359 console
.log("cache check result: " + (cached_article
!= false));
363 var query
= "?op=article&method=view&id=" + param_escape(id
);
365 var neighbor_ids
= getRelativePostIds(id
);
367 /* only request uncached articles */
369 var cids_to_request
= [];
371 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
372 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
373 if (!cache_get("article:" + neighbor_ids
[i
])) {
374 cids_to_request
.push(neighbor_ids
[i
]);
375 cids_requested
.push(neighbor_ids
[i
]);
379 console
.log("additional ids: " + cids_to_request
.toString());
381 query
= query
+ "&cids=" + cids_to_request
.toString();
383 var article_is_unread
= crow
.hasClassName("Unread");
386 showArticleInHeadlines(id
);
388 precache_headlines();
390 if (cached_article
&& article_is_unread
) {
392 query
= query
+ "&mode=prefetch";
394 render_article(cached_article
);
396 } else if (cached_article
) {
398 query
= query
+ "&mode=prefetch_old";
399 render_article(cached_article
);
401 // if we don't need to request any relative ids, we might as well skip
402 // the server roundtrip altogether
403 if (cids_to_request
.length
== 0) {
406 if (!_infscroll_disable &&
407 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
415 headlines_scroll_handler($("headlines-frame"));
421 last_requested_article
= id
;
425 if (article_is_unread
) {
426 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
429 new Ajax
.Request("backend.php", {
431 onComplete: function(transport
) {
432 article_callback2(transport
, id
);
438 exception_error("view", e
);
442 function toggleMark(id
, client_only
) {
444 var query
= "?op=rpc&id=" + id
+ "&method=mark";
446 var img
= $("FMPIC-" + id
);
450 if (img
.src
.match("mark_unset")) {
451 img
.src
= img
.src
.replace("mark_unset", "mark_set");
452 img
.alt
= __("Unstar article");
453 query
= query
+ "&mark=1";
456 img
.src
= img
.src
.replace("mark_set", "mark_unset");
457 img
.alt
= __("Star article");
458 query
= query
+ "&mark=0";
461 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
464 new Ajax
.Request("backend.php", {
466 onComplete: function(transport
) {
467 handle_rpc_json(transport
);
472 exception_error("toggleMark", e
);
476 function togglePub(id
, client_only
, no_effects
, note
) {
478 var query
= "?op=rpc&id=" + id
+ "&method=publ";
480 if (note
!= undefined) {
481 query
= query
+ "¬e=" + param_escape(note
);
483 query
= query
+ "¬e=undefined";
486 var img
= $("FPPIC-" + id
);
490 if (img
.src
.match("pub_unset") || note
!= undefined) {
491 img
.src
= img
.src
.replace("pub_unset", "pub_set");
492 img
.alt
= __("Unpublish article");
493 query
= query
+ "&pub=1";
496 img
.src
= img
.src
.replace("pub_set", "pub_unset");
497 img
.alt
= __("Publish article");
499 query
= query
+ "&pub=0";
502 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
505 new Ajax
.Request("backend.php", {
507 onComplete: function(transport
) {
508 handle_rpc_json(transport
);
513 exception_error("togglePub", e
);
517 function moveToPost(mode
) {
521 var rows
= getVisibleArticleIds();
526 if (!$('RROW-' + active_post_id
)) {
527 active_post_id
= false;
530 if (active_post_id
== false) {
532 prev_id
= rows
[rows
.length
-1]
534 for (var i
= 0; i
< rows
.length
; i
++) {
535 if (rows
[i
] == active_post_id
) {
537 // Account for adjacent identical article ids.
538 if (i
> 0) prev_id
= rows
[i
-1];
540 for (var j
= i
+1; j
< rows
.length
; j
++) {
541 if (rows
[j
] != active_post_id
) {
551 if (mode
== "next") {
555 cdmExpandArticle(next_id
);
556 cdmScrollToArticleId(next_id
);
559 correctHeadlinesOffset(next_id
);
560 view(next_id
, getActiveFeedId());
565 if (mode
== "prev") {
568 cdmExpandArticle(prev_id
);
569 cdmScrollToArticleId(prev_id
);
571 correctHeadlinesOffset(prev_id
);
572 view(prev_id
, getActiveFeedId());
578 exception_error("moveToPost", e
);
582 function toggleSelected(id
, force_on
) {
585 var cb
= dijit
.byId("RCHK-" + id
);
586 var row
= $("RROW-" + id
);
589 if (row
.hasClassName('Selected') && !force_on
) {
590 row
.removeClassName('Selected');
591 if (cb
) cb
.attr("checked", false);
593 row
.addClassName('Selected');
594 if (cb
) cb
.attr("checked", true);
598 exception_error("toggleSelected", e
);
602 function toggleUnread_afh(effect
) {
605 var elem
= effect
.element
;
606 elem
.style
.backgroundColor
= "";
609 exception_error("toggleUnread_afh", e
);
613 function toggleUnread(id
, cmode
, effect
) {
616 var row
= $("RROW-" + id
);
618 if (cmode
== undefined || cmode
== 2) {
619 if (row
.hasClassName("Unread")) {
620 row
.removeClassName("Unread");
623 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
624 afterFinish
: toggleUnread_afh
,
625 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
629 row
.addClassName("Unread");
632 } else if (cmode
== 0) {
634 row
.removeClassName("Unread");
637 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
638 afterFinish
: toggleUnread_afh
,
639 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
642 } else if (cmode
== 1) {
643 row
.addClassName("Unread");
646 if (cmode
== undefined) cmode
= 2;
648 var query
= "?op=rpc&method=catchupSelected" +
649 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
651 // notify_progress("Loading, please wait...");
653 new Ajax
.Request("backend.php", {
655 onComplete: function(transport
) {
656 handle_rpc_json(transport
);
662 exception_error("toggleUnread", e
);
666 function selectionRemoveLabel(id
, ids
) {
669 if (!ids
) ids
= getSelectedArticleIds2();
671 if (ids
.length
== 0) {
672 alert(__("No articles are selected."));
676 var query
= "?op=rpc&method=removeFromLabel&ids=" +
677 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
681 new Ajax
.Request("backend.php", {
683 onComplete: function(transport
) {
684 handle_rpc_json(transport
);
685 show_labels_in_headlines(transport
);
689 exception_error("selectionAssignLabel", e
);
694 function selectionAssignLabel(id
, ids
) {
697 if (!ids
) ids
= getSelectedArticleIds2();
699 if (ids
.length
== 0) {
700 alert(__("No articles are selected."));
704 var query
= "?op=rpc&method=assignToLabel&ids=" +
705 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
709 new Ajax
.Request("backend.php", {
711 onComplete: function(transport
) {
712 handle_rpc_json(transport
);
713 show_labels_in_headlines(transport
);
717 exception_error("selectionAssignLabel", e
);
722 function selectionToggleUnread(set_state
, callback
, no_error
) {
724 var rows
= getSelectedArticleIds2();
726 if (rows
.length
== 0 && !no_error
) {
727 alert(__("No articles are selected."));
731 for (var i
= 0; i
< rows
.length
; i
++) {
732 var row
= $("RROW-" + rows
[i
]);
734 if (set_state
== undefined) {
735 if (row
.hasClassName("Unread")) {
736 row
.removeClassName("Unread");
738 row
.addClassName("Unread");
742 if (set_state
== false) {
743 row
.removeClassName("Unread");
746 if (set_state
== true) {
747 row
.addClassName("Unread");
752 if (rows
.length
> 0) {
756 if (set_state
== undefined) {
758 } else if (set_state
== true) {
760 } else if (set_state
== false) {
764 var query
= "?op=rpc&method=catchupSelected" +
765 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
767 notify_progress("Loading, please wait...");
769 new Ajax
.Request("backend.php", {
771 onComplete: function(transport
) {
772 handle_rpc_json(transport
);
773 if (callback
) callback(transport
);
779 exception_error("selectionToggleUnread", e
);
783 function selectionToggleMarked() {
786 var rows
= getSelectedArticleIds2();
788 if (rows
.length
== 0) {
789 alert(__("No articles are selected."));
793 for (var i
= 0; i
< rows
.length
; i
++) {
794 toggleMark(rows
[i
], true, true);
797 if (rows
.length
> 0) {
799 var query
= "?op=rpc&method=markSelected&ids=" +
800 param_escape(rows
.toString()) + "&cmode=2";
802 new Ajax
.Request("backend.php", {
804 onComplete: function(transport
) {
805 handle_rpc_json(transport
);
811 exception_error("selectionToggleMarked", e
);
815 function selectionTogglePublished() {
818 var rows
= getSelectedArticleIds2();
820 if (rows
.length
== 0) {
821 alert(__("No articles are selected."));
825 for (var i
= 0; i
< rows
.length
; i
++) {
826 togglePub(rows
[i
], true, true);
829 if (rows
.length
> 0) {
831 var query
= "?op=rpc&method=publishSelected&ids=" +
832 param_escape(rows
.toString()) + "&cmode=2";
834 new Ajax
.Request("backend.php", {
836 onComplete: function(transport
) {
837 handle_rpc_json(transport
);
843 exception_error("selectionToggleMarked", e
);
847 function getSelectedArticleIds2() {
851 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
853 rv
.push(child
.id
.replace("RROW-", ""));
859 function getLoadedArticleIds() {
862 var children
= $$("#headlines-frame > div[id*=RROW-]");
864 children
.each(function(child
) {
865 rv
.push(child
.id
.replace("RROW-", ""));
872 // mode = all,none,unread,invert,marked,published
873 function selectArticles(mode
) {
876 var children
= $$("#headlines-frame > div[id*=RROW]");
878 children
.each(function(child
) {
879 var id
= child
.id
.replace("RROW-", "");
880 var cb
= dijit
.byId("RCHK-" + id
);
883 child
.addClassName("Selected");
884 if (cb
) cb
.attr("checked", true);
885 } else if (mode
== "unread") {
886 if (child
.hasClassName("Unread")) {
887 child
.addClassName("Selected");
888 if (cb
) cb
.attr("checked", true);
890 child
.removeClassName("Selected");
891 if (cb
) cb
.attr("checked", false);
893 } else if (mode
== "marked") {
894 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
896 if (img
&& img
.src
.match("mark_set")) {
897 child
.addClassName("Selected");
898 if (cb
) cb
.attr("checked", true);
900 child
.removeClassName("Selected");
901 if (cb
) cb
.attr("checked", false);
903 } else if (mode
== "published") {
904 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
906 if (img
&& img
.src
.match("pub_set")) {
907 child
.addClassName("Selected");
908 if (cb
) cb
.attr("checked", true);
910 child
.removeClassName("Selected");
911 if (cb
) cb
.attr("checked", false);
914 } else if (mode
== "invert") {
915 if (child
.hasClassName("Selected")) {
916 child
.removeClassName("Selected");
917 if (cb
) cb
.attr("checked", false);
919 child
.addClassName("Selected");
920 if (cb
) cb
.attr("checked", true);
924 child
.removeClassName("Selected");
925 if (cb
) cb
.attr("checked", false);
930 exception_error("selectArticles", e
);
934 function catchupPage() {
936 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
938 var str
= __("Mark all visible articles in %s as read?");
940 str
= str
.replace("%s", fn
);
942 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
946 selectArticles('all');
947 selectionToggleUnread(false, 'viewCurrentFeed()', true);
948 selectArticles('none');
951 function deleteSelection() {
955 var rows
= getSelectedArticleIds2();
957 if (rows
.length
== 0) {
958 alert(__("No articles are selected."));
962 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
965 if (getActiveFeedId() != 0) {
966 str
= __("Delete %d selected articles in %s?");
968 str
= __("Delete %d selected articles?");
971 str
= str
.replace("%d", rows
.length
);
972 str
= str
.replace("%s", fn
);
974 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
978 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
982 new Ajax
.Request("backend.php", {
984 onComplete: function(transport
) {
985 handle_rpc_json(transport
);
990 exception_error("deleteSelection", e
);
994 function archiveSelection() {
998 var rows
= getSelectedArticleIds2();
1000 if (rows
.length
== 0) {
1001 alert(__("No articles are selected."));
1005 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1009 if (getActiveFeedId() != 0) {
1010 str
= __("Archive %d selected articles in %s?");
1013 str
= __("Move %d archived articles back?");
1017 str
= str
.replace("%d", rows
.length
);
1018 str
= str
.replace("%s", fn
);
1020 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1024 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1028 for (var i
= 0; i
< rows
.length
; i
++) {
1029 cache_delete("article:" + rows
[i
]);
1032 new Ajax
.Request("backend.php", {
1034 onComplete: function(transport
) {
1035 handle_rpc_json(transport
);
1040 exception_error("archiveSelection", e
);
1044 function catchupSelection() {
1048 var rows
= getSelectedArticleIds2();
1050 if (rows
.length
== 0) {
1051 alert(__("No articles are selected."));
1055 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1057 var str
= __("Mark %d selected articles in %s as read?");
1059 str
= str
.replace("%d", rows
.length
);
1060 str
= str
.replace("%s", fn
);
1062 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1066 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1069 exception_error("catchupSelection", e
);
1073 function editArticleTags(id
) {
1074 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1076 if (dijit
.byId("editTagsDlg"))
1077 dijit
.byId("editTagsDlg").destroyRecursive();
1079 dialog
= new dijit
.Dialog({
1081 title
: __("Edit article Tags"),
1082 style
: "width: 600px",
1083 execute: function() {
1084 if (this.validate()) {
1085 var query
= dojo
.objectToQuery(this.attr('value'));
1087 notify_progress("Saving article tags...", true);
1089 new Ajax
.Request("backend.php", {
1091 onComplete: function(transport
) {
1095 var data
= JSON
.parse(transport
.responseText
);
1098 var tags_str
= article
.tags
;
1099 var id
= tags_str
.id
;
1101 var tags
= $("ATSTR-" + id
);
1102 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1104 if (tags
) tags
.innerHTML
= tags_str
.content
;
1105 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1107 cache_delete("article:" + id
);
1116 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1117 dojo
.disconnect(tmph
);
1119 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1120 "backend.php?op=rpc&method=completeTags",
1121 { tokens
: ',', paramName
: "search" });
1128 function cdmScrollToArticleId(id
) {
1130 var ctr
= $("headlines-frame");
1131 var e
= $("RROW-" + id
);
1133 if (!e
|| !ctr
) return;
1135 ctr
.scrollTop
= e
.offsetTop
;
1138 exception_error("cdmScrollToArticleId", e
);
1142 function getActiveArticleId() {
1143 return active_post_id
;
1146 function postMouseIn(id
) {
1147 post_under_pointer
= id
;
1150 function postMouseOut(id
) {
1151 post_under_pointer
= false;
1154 function headlines_scroll_handler(e
) {
1156 var hsp
= $("headlines-spacer");
1158 if (!_infscroll_disable
) {
1159 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1160 (e
.scrollHeight
!= 0 &&
1161 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1164 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1165 __("Loading, please wait...");
1167 loadMoreHeadlines();
1172 if (hsp
) hsp
.innerHTML
= "";
1175 if (getInitParam("cdm_auto_catchup") == 1) {
1177 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1179 if ($("headlines-frame").scrollTop
>
1180 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1182 var id
= child
.id
.replace("RROW-", "");
1184 if (catchup_id_batch
.indexOf(id
) == -1)
1185 catchup_id_batch
.push(id
);
1187 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1191 if (catchup_id_batch
.length
> 0) {
1192 window
.clearTimeout(catchup_timeout_id
);
1194 if (!_infscroll_request_sent
) {
1195 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1202 console
.warn("headlines_scroll_handler: " + e
);
1206 function catchupBatchedArticles() {
1208 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1210 // make a copy of the array
1211 var batch
= catchup_id_batch
.slice();
1212 var query
= "?op=rpc&method=catchupSelected" +
1213 "&cmode=0&ids=" + param_escape(batch
.toString());
1217 new Ajax
.Request("backend.php", {
1219 onComplete: function(transport
) {
1220 handle_rpc_json(transport
);
1222 batch
.each(function(id
) {
1223 var elem
= $("RROW-" + id
);
1224 if (elem
) elem
.removeClassName("Unread");
1225 catchup_id_batch
.remove(id
);
1232 exception_error("catchupBatchedArticles", e
);
1236 function catchupRelativeToArticle(below
, id
) {
1240 if (!id
) id
= getActiveArticleId();
1243 alert(__("No article is selected."));
1247 var visible_ids
= getVisibleArticleIds();
1249 var ids_to_mark
= new Array();
1252 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1253 if (visible_ids
[i
] != id
) {
1254 var e
= $("RROW-" + visible_ids
[i
]);
1256 if (e
&& e
.hasClassName("Unread")) {
1257 ids_to_mark
.push(visible_ids
[i
]);
1264 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1265 if (visible_ids
[i
] != id
) {
1266 var e
= $("RROW-" + visible_ids
[i
]);
1268 if (e
&& e
.hasClassName("Unread")) {
1269 ids_to_mark
.push(visible_ids
[i
]);
1277 if (ids_to_mark
.length
== 0) {
1278 alert(__("No articles found to mark"));
1280 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1282 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1284 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1285 var e
= $("RROW-" + ids_to_mark
[i
]);
1286 e
.removeClassName("Unread");
1289 var query
= "?op=rpc&method=catchupSelected" +
1290 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1292 new Ajax
.Request("backend.php", {
1294 onComplete: function(transport
) {
1295 handle_rpc_json(transport
);
1302 exception_error("catchupRelativeToArticle", e
);
1306 function cdmExpandArticle(id
) {
1311 var elem
= $("CICD-" + active_post_id
);
1313 if (id
== active_post_id
&& Element
.visible(elem
))
1316 selectArticles("none");
1318 var old_offset
= $("RROW-" + id
).offsetTop
;
1320 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1322 Element
.show("CEXC-" + active_post_id
);
1325 active_post_id
= id
;
1327 elem
= $("CICD-" + id
);
1329 if (!Element
.visible(elem
)) {
1331 Element
.hide("CEXC-" + id
);
1334 var new_offset
= $("RROW-" + id
).offsetTop
;
1336 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1338 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1339 $("headlines-frame").scrollTop
= new_offset
;
1341 toggleUnread(id
, 0, true);
1345 exception_error("cdmExpandArticle", e
);
1351 function fixHeadlinesOrder(ids
) {
1353 for (var i
= 0; i
< ids
.length
; i
++) {
1354 var e
= $("RROW-" + ids
[i
]);
1358 e
.removeClassName("even");
1359 e
.addClassName("odd");
1361 e
.removeClassName("odd");
1362 e
.addClassName("even");
1367 exception_error("fixHeadlinesOrder", e
);
1371 function getArticleUnderPointer() {
1372 return post_under_pointer
;
1375 function scrollArticle(offset
) {
1378 var ci
= $("content-insert");
1380 ci
.scrollTop
+= offset
;
1383 var hi
= $("headlines-frame");
1385 hi
.scrollTop
+= offset
;
1390 exception_error("scrollArticle", e
);
1394 function show_labels_in_headlines(transport
) {
1396 var data
= JSON
.parse(transport
.responseText
);
1399 data
['info-for-headlines'].each(function(elem
) {
1400 var ctr
= $("HLLCTR-" + elem
.id
);
1402 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1405 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1409 exception_error("show_labels_in_headlines", e
);
1413 function dismissArticle(id
) {
1415 var elem
= $("RROW-" + id
);
1417 toggleUnread(id
, 0, true);
1419 new Effect
.Fade(elem
, {duration
: 0.5});
1421 active_post_id
= false;
1424 exception_error("dismissArticle", e
);
1428 function dismissSelectedArticles() {
1431 var ids
= getVisibleArticleIds();
1435 for (var i
= 0; i
< ids
.length
; i
++) {
1436 var elem
= $("RROW-" + ids
[i
]);
1438 if (elem
.className
&& elem
.hasClassName("Selected") &&
1439 ids
[i
] != active_post_id
) {
1440 new Effect
.Fade(elem
, {duration
: 0.5});
1448 selectionToggleUnread(false);
1450 fixHeadlinesOrder(tmp
);
1453 exception_error("dismissSelectedArticles", e
);
1457 function dismissReadArticles() {
1460 var ids
= getVisibleArticleIds();
1463 for (var i
= 0; i
< ids
.length
; i
++) {
1464 var elem
= $("RROW-" + ids
[i
]);
1466 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1467 !elem
.hasClassName("Selected")) {
1469 new Effect
.Fade(elem
, {duration
: 0.5});
1475 fixHeadlinesOrder(tmp
);
1478 exception_error("dismissSelectedArticles", e
);
1482 function getVisibleArticleIds() {
1487 getLoadedArticleIds().each(function(id
) {
1488 var elem
= $("RROW-" + id
);
1489 if (elem
&& Element
.visible(elem
))
1494 exception_error("getVisibleArticleIds", e
);
1500 function cdmClicked(event
, id
) {
1502 //var shift_key = event.shiftKey;
1506 if (!event
.ctrlKey
) {
1508 if (!getInitParam("cdm_expanded")) {
1509 return cdmExpandArticle(id
);
1512 selectArticles("none");
1515 var elem
= $("RROW-" + id
);
1516 var article_is_unread
= elem
.hasClassName("Unread");
1519 elem
.removeClassName("Unread");
1521 active_post_id
= id
;
1523 if (article_is_unread
) {
1524 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1527 var query
= "?op=rpc&method=catchupSelected" +
1528 "&cmode=0&ids=" + param_escape(id
);
1530 new Ajax
.Request("backend.php", {
1532 onComplete: function(transport
) {
1533 handle_rpc_json(transport
);
1540 toggleSelected(id
, true);
1542 var elem
= $("RROW-" + id
);
1543 var article_is_unread
= elem
.hasClassName("Unread");
1545 if (article_is_unread
) {
1546 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1549 toggleUnread(id
, 0, false);
1551 openArticleInNewWindow(id
);
1554 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1555 request_counters(unread_in_buffer
== 0);
1558 exception_error("cdmClicked");
1564 function hlClicked(event
, id
) {
1566 if (event
.which
== 2) {
1569 } else if (event
.ctrlKey
) {
1570 toggleSelected(id
, true);
1571 toggleUnread(id
, 0, false);
1572 openArticleInNewWindow(id
);
1580 exception_error("hlClicked");
1584 function getFirstVisibleHeadlineId() {
1585 var rows
= getVisibleArticleIds();
1590 function getLastVisibleHeadlineId() {
1591 var rows
= getVisibleArticleIds();
1592 return rows
[rows
.length
-1];
1595 function openArticleInNewWindow(id
) {
1596 toggleUnread(id
, 0, false);
1597 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1600 function isCdmMode() {
1601 return getInitParam("combined_display_mode");
1604 function markHeadline(id
) {
1605 var row
= $("RROW-" + id
);
1607 var check
= dijit
.byId("RCHK-" + id
);
1610 check
.attr("checked", true);
1613 row
.addClassName("Selected");
1617 function getRelativePostIds(id
, limit
) {
1623 if (!limit
) limit
= 6; //3
1625 var ids
= getVisibleArticleIds();
1627 for (var i
= 0; i
< ids
.length
; i
++) {
1629 for (var k
= 1; k
<= limit
; k
++) {
1630 //if (i > k-1) tmp.push(ids[i-k]);
1631 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1638 exception_error("getRelativePostIds", e
);
1644 function correctHeadlinesOffset(id
) {
1648 var container
= $("headlines-frame");
1649 var row
= $("RROW-" + id
);
1651 if (!container
|| !row
) return;
1653 var viewport
= container
.offsetHeight
;
1655 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1656 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1658 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1659 //console.log("Vport: " + viewport);
1661 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1662 container
.scrollTop
= row
.offsetTop
;
1663 } else if (rel_offset_bottom
> viewport
) {
1665 /* doesn't properly work with Opera in some cases because
1666 Opera fucks up element scrolling */
1668 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1672 exception_error("correctHeadlinesOffset", e
);
1677 function headlineActionsChange(elem
) {
1680 elem
.attr('value', 'false');
1682 exception_error("headlineActionsChange", e
);
1686 function closeArticlePanel() {
1688 if (dijit
.byId("content-insert"))
1689 dijit
.byId("headlines-wrap-inner").removeChild(
1690 dijit
.byId("content-insert"));
1693 function initHeadlinesMenu() {
1695 if (dijit
.byId("headlinesMenu"))
1696 dijit
.byId("headlinesMenu").destroyRecursive();
1701 nodes
= $$("#headlines-frame > div[id*=RROW]");
1703 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1706 nodes
.each(function(node
) {
1710 var menu
= new dijit
.Menu({
1711 id
: "headlinesMenu",
1715 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1716 var callerNode
= event
.target
, match
= null, tries
= 0;
1718 while (match
== null && callerNode
&& tries
<= 3) {
1719 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1720 callerNode
= callerNode
.parentNode
;
1724 if (match
) this.callerRowId
= parseInt(match
[1]);
1728 /* if (!isCdmMode())
1729 menu.addChild(new dijit.MenuItem({
1730 label: __("View article"),
1731 onClick: function(event) {
1732 view(this.getParent().callerRowId);
1735 menu
.addChild(new dijit
.MenuItem({
1736 label
: __("Open original article"),
1737 onClick: function(event
) {
1738 openArticleInNewWindow(this.getParent().callerRowId
);
1741 menu
.addChild(new dijit
.MenuSeparator());
1743 menu
.addChild(new dijit
.MenuItem({
1744 label
: __("Mark above as read"),
1745 onClick: function(event
) {
1746 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1749 menu
.addChild(new dijit
.MenuItem({
1750 label
: __("Mark below as read"),
1751 onClick: function(event
) {
1752 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1756 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1760 menu
.addChild(new dijit
.MenuSeparator());
1762 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1763 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1765 labels
.each(function(label
) {
1766 var id
= label
.id
[0];
1767 var bare_id
= id
.substr(id
.indexOf(":")+1);
1768 var name
= label
.name
[0];
1770 bare_id
= -11-bare_id
;
1772 labelAddMenu
.addChild(new dijit
.MenuItem({
1775 onClick: function(event
) {
1776 var ids
= getSelectedArticleIds2();
1778 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1780 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1782 selectionAssignLabel(this.labelId
, ids
);
1785 labelDelMenu
.addChild(new dijit
.MenuItem({
1788 onClick: function(event
) {
1789 var ids
= getSelectedArticleIds2();
1791 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1793 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1795 selectionRemoveLabel(this.labelId
, ids
);
1800 menu
.addChild(new dijit
.PopupMenuItem({
1801 label
: __("Assign label"),
1802 popup
: labelAddMenu
,
1805 menu
.addChild(new dijit
.PopupMenuItem({
1806 label
: __("Remove label"),
1807 popup
: labelDelMenu
,
1815 exception_error("initHeadlinesMenu", e
);
1820 function player(elem
) {
1821 var aid
= elem
.getAttribute("audio-id");
1822 var status
= elem
.getAttribute("status");
1830 elem
.innerHTML
= __("Playing...");
1831 elem
.title
= __("Click to pause");
1832 elem
.addClassName("playing");
1836 elem
.innerHTML
= __("Play");
1837 elem
.title
= __("Click to play");
1838 elem
.removeClassName("playing");
1841 elem
.setAttribute("status", status
);
1843 alert("Your browser doesn't seem to support HTML5 audio.");
1847 function cache_set(id
, obj
) {
1848 //console.log("cache_set: " + id);
1851 sessionStorage
[id
] = obj
;
1853 sessionStorage
.clear();
1857 function cache_get(id
) {
1859 return sessionStorage
[id
];
1862 function cache_clear() {
1864 sessionStorage
.clear();
1867 function cache_delete(id
) {
1869 sessionStorage
.removeItem(id
);
1872 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
1873 if (toolbar_obj
&& content_obj
) {
1874 cache_set("feed:" + feed
+ ":" + is_cat
,
1875 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
1878 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
1881 obj
= JSON
.parse(obj
);
1883 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
1884 if (content_obj
) obj
.content
= content_obj
;
1886 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
1890 console
.warn("cache_headlines failed: " + e
);
1895 function render_local_headlines(feed
, is_cat
, obj
) {
1898 dijit
.byId("headlines-toolbar").attr('content',
1901 dijit
.byId("headlines-frame").attr('content',
1904 dojo
.parser
.parse('headlines-toolbar');
1906 $("headlines-frame").scrollTop
= 0;
1907 selectArticles('none');
1908 setActiveFeedId(feed
, is_cat
);
1909 initHeadlinesMenu();
1911 dijit
.getEnclosingWidget(
1912 document
.forms
["main_toolbar_form"].update
).attr('disabled',
1913 is_cat
|| feed
<= 0);
1915 precache_headlines();
1918 exception_error("render_local_headlines", e
);
1922 function precache_headlines_idle() {
1924 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id
) {
1925 if (get_timestamp() - _viewfeed_last
> 120) {
1927 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
1930 feeds
.each(function(item
) {
1931 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
1932 uncached
.push(item
);
1935 if (uncached
.length
> 0) {
1936 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
1937 viewfeed(rf
[0], '', rf
[1], 0, true);
1941 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
1944 exception_error("precache_headlines_idle", e
);
1948 function precache_headlines() {
1950 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id
) {
1952 feed_precache_timeout_id
= window
.setTimeout(function() {
1953 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
1954 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
1956 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
1957 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
1959 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
1960 viewfeed(nf
[0], '', nf
[1], 0, true);
1962 window
.setTimeout(function() {
1963 feed_precache_timeout_id
= false;
1969 exception_error("precache_headlines", e
);
1973 function cancelSearch() {
1978 exception_error("cancelSearch", e
);
1982 function setSelectionScore() {
1984 var ids
= getSelectedArticleIds2();
1986 if (ids
.length
> 0) {
1989 var score
= prompt(__("Please enter new score for selected articles:"), score
);
1991 if (score
!= undefined) {
1992 var query
= "op=rpc&method=setScore&id=" + param_escape(ids
.toString()) +
1993 "&score=" + param_escape(score
);
1995 new Ajax
.Request("backend.php", {
1997 onComplete: function(transport
) {
1998 var reply
= JSON
.parse(transport
.responseText
);
2002 ids
.each(function(id
) {
2003 var row
= $("RROW-" + id
);
2006 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2009 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2010 reply
["score_pic"]);
2011 pic
.setAttribute("score", score
);
2020 alert(__("No articles are selected."));
2023 exception_error("setSelectionScore", e
);
2027 function changeScore(id
, pic
) {
2029 var score
= pic
.getAttribute("score");
2031 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2033 if (new_score
!= undefined) {
2035 var query
= "op=rpc&method=setScore&id=" + param_escape(id
) +
2036 "&score=" + param_escape(new_score
);
2038 new Ajax
.Request("backend.php", {
2040 onComplete: function(transport
) {
2041 var reply
= JSON
.parse(transport
.responseText
);
2044 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2045 pic
.setAttribute("score", new_score
);
2050 exception_error("changeScore", e
);