]>
git.wh0rd.org - tt-rss.git/blob - js/viewfeed.js
a907a05d6be89460f389ca472bb1f7bfde4ede7e
1 var article_cache
= new Array();
3 var _active_article_id
= 0;
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 (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 (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 if (!$("RCHK-" + child
.id
.replace("RROW-", "RCHK-"))) {
166 if (!Element
.visible(child
))
167 new Effect
.Appear(child
, { duration
: 0.5 });
169 c
.domNode
.removeChild(child
);
174 console
.log("no new headlines received");
176 var hsp
= $("headlines-spacer");
178 if (hsp
) hsp
.innerHTML
= "";
182 if (headlines_count
> 0)
183 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
186 for (var i
= 0; i
< articles
.length
; i
++) {
187 var a_id
= articles
[i
]['id'];
188 cache_set("article:" + a_id
, articles
[i
]['content']);
191 console
.log("no cached articles received");
194 // do not precache stuff after fresh feed
196 precache_headlines();
199 parse_counters(counters
);
201 request_counters(true);
203 } else if (transport
.responseText
) {
204 console
.error("Invalid object received: " + transport
.responseText
);
205 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
206 __('Could not update headlines (invalid object received - see error console for details)') +
209 //notify_error("Error communicating with server.");
210 Element
.show(dijit
.byId("net-alert").domNode
);
213 _infscroll_request_sent
= 0;
219 exception_error("headlines_callback2", e
, transport
);
223 function render_article(article
) {
225 dijit
.byId("headlines-wrap-inner").addChild(
226 dijit
.byId("content-insert"));
228 var c
= dijit
.byId("content-insert");
231 c
.domNode
.scrollTop
= 0;
234 c
.attr('content', article
);
236 correctHeadlinesOffset(getActiveArticleId());
243 exception_error("render_article", e
);
247 function showArticleInHeadlines(id
) {
251 selectArticles("none");
253 var crow
= $("RROW-" + id
);
257 var article_is_unread
= crow
.hasClassName("Unread");
259 crow
.removeClassName("Unread");
261 selectArticles('none');
263 var view_mode
= false;
266 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
267 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
272 if (article_is_unread
&& view_mode
== "all_articles") {
273 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
278 if (article_is_unread
)
279 _force_scheduled_update
= true;
282 exception_error("showArticleInHeadlines", e
);
286 function article_callback2(transport
, id
) {
288 console
.log("article_callback2 " + id
);
290 handle_rpc_json(transport
);
295 reply
= JSON
.parse(transport
.responseText
);
302 reply
.each(function(article
) {
303 if (getActiveArticleId() == article
['id']) {
304 render_article(article
['content']);
306 cids_requested
.remove(article
['id']);
308 cache_set("article:" + article
['id'], article
['content']);
311 // if (id != last_requested_article) {
312 // console.log("requested article id is out of sequence, aborting");
316 } else if (transport
.responseText
) {
317 console
.error("Invalid object received: " + transport
.responseText
);
319 render_article("<div class='whiteBox'>" +
320 __('Could not display article (invalid object received - see error console for details)') + "</div>");
322 Element
.show(dijit
.byId("net-alert").domNode
);
325 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
326 request_counters(unread_in_buffer
== 0);
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 var crow
= $("RROW-" + id
);
352 console
.log("loading article: " + id
);
354 var cached_article
= cache_get("article:" + id
);
356 console
.log("cache check result: " + (cached_article
!= false));
360 var query
= "?op=article&method=view&id=" + param_escape(id
);
362 var neighbor_ids
= getRelativePostIds(id
);
364 /* only request uncached articles */
366 var cids_to_request
= [];
368 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
369 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
370 if (!cache_get("article:" + neighbor_ids
[i
])) {
371 cids_to_request
.push(neighbor_ids
[i
]);
372 cids_requested
.push(neighbor_ids
[i
]);
376 console
.log("additional ids: " + cids_to_request
.toString());
378 query
= query
+ "&cids=" + cids_to_request
.toString();
380 var article_is_unread
= crow
.hasClassName("Unread");
382 setActiveArticleId(id
);
383 showArticleInHeadlines(id
);
385 precache_headlines();
387 if (cached_article
&& article_is_unread
) {
389 query
= query
+ "&mode=prefetch";
391 render_article(cached_article
);
393 } else if (cached_article
) {
395 query
= query
+ "&mode=prefetch_old";
396 render_article(cached_article
);
398 // if we don't need to request any relative ids, we might as well skip
399 // the server roundtrip altogether
400 if (cids_to_request
.length
== 0) {
403 if (!_infscroll_disable &&
404 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
412 headlines_scroll_handler($("headlines-frame"));
418 last_requested_article
= id
;
422 if (article_is_unread
) {
423 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
426 new Ajax
.Request("backend.php", {
428 onComplete: function(transport
) {
429 article_callback2(transport
, id
);
435 exception_error("view", e
);
439 function toggleMark(id
, client_only
) {
441 var query
= "?op=rpc&id=" + id
+ "&method=mark";
443 var img
= $("FMPIC-" + id
);
447 if (img
.src
.match("mark_unset")) {
448 img
.src
= img
.src
.replace("mark_unset", "mark_set");
449 img
.alt
= __("Unstar article");
450 query
= query
+ "&mark=1";
453 img
.src
= img
.src
.replace("mark_set", "mark_unset");
454 img
.alt
= __("Star article");
455 query
= query
+ "&mark=0";
458 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
461 new Ajax
.Request("backend.php", {
463 onComplete: function(transport
) {
464 handle_rpc_json(transport
);
469 exception_error("toggleMark", e
);
473 function togglePub(id
, client_only
, no_effects
, note
) {
475 var query
= "?op=rpc&id=" + id
+ "&method=publ";
477 if (note
!= undefined) {
478 query
= query
+ "¬e=" + param_escape(note
);
480 query
= query
+ "¬e=undefined";
483 var img
= $("FPPIC-" + id
);
487 if (img
.src
.match("pub_unset") || note
!= undefined) {
488 img
.src
= img
.src
.replace("pub_unset", "pub_set");
489 img
.alt
= __("Unpublish article");
490 query
= query
+ "&pub=1";
493 img
.src
= img
.src
.replace("pub_set", "pub_unset");
494 img
.alt
= __("Publish article");
496 query
= query
+ "&pub=0";
499 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
502 new Ajax
.Request("backend.php", {
504 onComplete: function(transport
) {
505 handle_rpc_json(transport
);
510 exception_error("togglePub", e
);
514 function moveToPost(mode
, noscroll
) {
518 var rows
= getVisibleArticleIds();
523 if (!$('RROW-' + getActiveArticleId())) {
524 setActiveArticleId(0);
527 if (!getActiveArticleId()) {
529 prev_id
= rows
[rows
.length
-1]
531 for (var i
= 0; i
< rows
.length
; i
++) {
532 if (rows
[i
] == getActiveArticleId()) {
534 // Account for adjacent identical article ids.
535 if (i
> 0) prev_id
= rows
[i
-1];
537 for (var j
= i
+1; j
< rows
.length
; j
++) {
538 if (rows
[j
] != getActiveArticleId()) {
548 if (mode
== "next") {
549 if (next_id
|| getActiveArticleId()) {
552 var article
= $("RROW-" + getActiveArticleId());
553 var ctr
= $("headlines-frame");
555 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
556 ctr
.scrollTop
+ ctr
.offsetHeight
) {
558 scrollArticle(ctr
.offsetHeight
/2);
560 } else if (next_id
) {
561 cdmExpandArticle(next_id
);
562 cdmScrollToArticleId(next_id
, noscroll
);
565 } else if (next_id
) {
566 correctHeadlinesOffset(next_id
);
567 view(next_id
, getActiveFeedId());
572 if (mode
== "prev") {
573 if (prev_id
|| getActiveArticleId()) {
576 var article
= $("RROW-" + getActiveArticleId());
577 var prev_article
= $("RROW-" + prev_id
);
578 var ctr
= $("headlines-frame");
580 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
581 scrollArticle(-ctr
.offsetHeight
/2);
582 } else if (!noscroll
&& prev_article
&&
583 prev_article
.offsetTop
< ctr
.scrollTop
) {
584 cdmExpandArticle(prev_id
);
585 scrollArticle(-ctr
.offsetHeight
/2);
586 } else if (prev_id
) {
587 cdmExpandArticle(prev_id
);
588 cdmScrollToArticleId(prev_id
, noscroll
);
590 } else if (prev_id
) {
591 correctHeadlinesOffset(prev_id
);
592 view(prev_id
, getActiveFeedId());
598 exception_error("moveToPost", e
);
602 function toggleSelected(id
, force_on
) {
605 var cb
= $("RCHK-" + id
);
606 var row
= $("RROW-" + id
);
609 if (row
.hasClassName('Selected') && !force_on
) {
610 row
.removeClassName('Selected');
611 if (cb
) cb
.checked
= false;
613 row
.addClassName('Selected');
614 if (cb
) cb
.checked
= true;
618 exception_error("toggleSelected", e
);
622 function toggleUnread_afh(effect
) {
625 var elem
= effect
.element
;
626 elem
.style
.backgroundColor
= "";
629 exception_error("toggleUnread_afh", e
);
633 function toggleUnread(id
, cmode
, effect
) {
636 var row
= $("RROW-" + id
);
638 if (cmode
== undefined || cmode
== 2) {
639 if (row
.hasClassName("Unread")) {
640 row
.removeClassName("Unread");
643 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
644 afterFinish
: toggleUnread_afh
,
645 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
649 row
.addClassName("Unread");
652 } else if (cmode
== 0) {
654 row
.removeClassName("Unread");
657 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
658 afterFinish
: toggleUnread_afh
,
659 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
662 } else if (cmode
== 1) {
663 row
.addClassName("Unread");
666 if (cmode
== undefined) cmode
= 2;
668 var query
= "?op=rpc&method=catchupSelected" +
669 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
671 // notify_progress("Loading, please wait...");
673 new Ajax
.Request("backend.php", {
675 onComplete: function(transport
) {
676 handle_rpc_json(transport
);
682 exception_error("toggleUnread", e
);
686 function selectionRemoveLabel(id
, ids
) {
689 if (!ids
) ids
= getSelectedArticleIds2();
691 if (ids
.length
== 0) {
692 alert(__("No articles are selected."));
696 var query
= "?op=rpc&method=removeFromLabel&ids=" +
697 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
701 new Ajax
.Request("backend.php", {
703 onComplete: function(transport
) {
704 handle_rpc_json(transport
);
705 show_labels_in_headlines(transport
);
709 exception_error("selectionAssignLabel", e
);
714 function selectionAssignLabel(id
, ids
) {
717 if (!ids
) ids
= getSelectedArticleIds2();
719 if (ids
.length
== 0) {
720 alert(__("No articles are selected."));
724 var query
= "?op=rpc&method=assignToLabel&ids=" +
725 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
729 new Ajax
.Request("backend.php", {
731 onComplete: function(transport
) {
732 handle_rpc_json(transport
);
733 show_labels_in_headlines(transport
);
737 exception_error("selectionAssignLabel", e
);
742 function selectionToggleUnread(set_state
, callback
, no_error
) {
744 var rows
= getSelectedArticleIds2();
746 if (rows
.length
== 0 && !no_error
) {
747 alert(__("No articles are selected."));
751 for (var i
= 0; i
< rows
.length
; i
++) {
752 var row
= $("RROW-" + rows
[i
]);
754 if (set_state
== undefined) {
755 if (row
.hasClassName("Unread")) {
756 row
.removeClassName("Unread");
758 row
.addClassName("Unread");
762 if (set_state
== false) {
763 row
.removeClassName("Unread");
766 if (set_state
== true) {
767 row
.addClassName("Unread");
772 if (rows
.length
> 0) {
776 if (set_state
== undefined) {
778 } else if (set_state
== true) {
780 } else if (set_state
== false) {
784 var query
= "?op=rpc&method=catchupSelected" +
785 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
787 notify_progress("Loading, please wait...");
789 new Ajax
.Request("backend.php", {
791 onComplete: function(transport
) {
792 handle_rpc_json(transport
);
793 if (callback
) callback(transport
);
799 exception_error("selectionToggleUnread", e
);
803 function selectionToggleMarked() {
806 var rows
= getSelectedArticleIds2();
808 if (rows
.length
== 0) {
809 alert(__("No articles are selected."));
813 for (var i
= 0; i
< rows
.length
; i
++) {
814 toggleMark(rows
[i
], true, true);
817 if (rows
.length
> 0) {
819 var query
= "?op=rpc&method=markSelected&ids=" +
820 param_escape(rows
.toString()) + "&cmode=2";
822 new Ajax
.Request("backend.php", {
824 onComplete: function(transport
) {
825 handle_rpc_json(transport
);
831 exception_error("selectionToggleMarked", e
);
835 function selectionTogglePublished() {
838 var rows
= getSelectedArticleIds2();
840 if (rows
.length
== 0) {
841 alert(__("No articles are selected."));
845 for (var i
= 0; i
< rows
.length
; i
++) {
846 togglePub(rows
[i
], true, true);
849 if (rows
.length
> 0) {
851 var query
= "?op=rpc&method=publishSelected&ids=" +
852 param_escape(rows
.toString()) + "&cmode=2";
854 new Ajax
.Request("backend.php", {
856 onComplete: function(transport
) {
857 handle_rpc_json(transport
);
863 exception_error("selectionToggleMarked", e
);
867 function getSelectedArticleIds2() {
871 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
873 rv
.push(child
.id
.replace("RROW-", ""));
879 function getLoadedArticleIds() {
882 var children
= $$("#headlines-frame > div[id*=RROW-]");
884 children
.each(function(child
) {
885 rv
.push(child
.id
.replace("RROW-", ""));
892 // mode = all,none,unread,invert,marked,published
893 function selectArticles(mode
) {
896 var children
= $$("#headlines-frame > div[id*=RROW]");
898 children
.each(function(child
) {
899 var id
= child
.id
.replace("RROW-", "");
900 var cb
= $("RCHK-" + id
);
903 child
.addClassName("Selected");
904 if (cb
) cb
.checked
= true;
905 } else if (mode
== "unread") {
906 if (child
.hasClassName("Unread")) {
907 child
.addClassName("Selected");
908 if (cb
) cb
.checked
= true;
910 child
.removeClassName("Selected");
911 if (cb
) cb
.checked
= false;
913 } else if (mode
== "marked") {
914 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
916 if (img
&& img
.src
.match("mark_set")) {
917 child
.addClassName("Selected");
918 if (cb
) cb
.checked
= true;
920 child
.removeClassName("Selected");
921 if (cb
) cb
.checked
= false;
923 } else if (mode
== "published") {
924 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
926 if (img
&& img
.src
.match("pub_set")) {
927 child
.addClassName("Selected");
928 if (cb
) cb
.checked
= true;
930 child
.removeClassName("Selected");
931 if (cb
) cb
.checked
= false;
934 } else if (mode
== "invert") {
935 if (child
.hasClassName("Selected")) {
936 child
.removeClassName("Selected");
937 if (cb
) cb
.checked
= false;
939 child
.addClassName("Selected");
940 if (cb
) cb
.checked
= true;
944 child
.removeClassName("Selected");
945 if (cb
) cb
.checked
= false;
950 exception_error("selectArticles", e
);
954 function catchupPage() {
956 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
958 var str
= __("Mark all visible articles in %s as read?");
960 str
= str
.replace("%s", fn
);
962 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
966 selectArticles('all');
967 selectionToggleUnread(false, 'viewCurrentFeed()', true);
968 selectArticles('none');
971 function deleteSelection() {
975 var rows
= getSelectedArticleIds2();
977 if (rows
.length
== 0) {
978 alert(__("No articles are selected."));
982 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
985 if (getActiveFeedId() != 0) {
986 str
= __("Delete %d selected articles in %s?");
988 str
= __("Delete %d selected articles?");
991 str
= str
.replace("%d", rows
.length
);
992 str
= str
.replace("%s", fn
);
994 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
998 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
1002 new Ajax
.Request("backend.php", {
1004 onComplete: function(transport
) {
1005 handle_rpc_json(transport
);
1010 exception_error("deleteSelection", e
);
1014 function archiveSelection() {
1018 var rows
= getSelectedArticleIds2();
1020 if (rows
.length
== 0) {
1021 alert(__("No articles are selected."));
1025 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1029 if (getActiveFeedId() != 0) {
1030 str
= __("Archive %d selected articles in %s?");
1033 str
= __("Move %d archived articles back?");
1037 str
= str
.replace("%d", rows
.length
);
1038 str
= str
.replace("%s", fn
);
1040 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1044 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1048 for (var i
= 0; i
< rows
.length
; i
++) {
1049 cache_delete("article:" + rows
[i
]);
1052 new Ajax
.Request("backend.php", {
1054 onComplete: function(transport
) {
1055 handle_rpc_json(transport
);
1060 exception_error("archiveSelection", e
);
1064 function catchupSelection() {
1068 var rows
= getSelectedArticleIds2();
1070 if (rows
.length
== 0) {
1071 alert(__("No articles are selected."));
1075 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1077 var str
= __("Mark %d selected articles in %s as read?");
1079 str
= str
.replace("%d", rows
.length
);
1080 str
= str
.replace("%s", fn
);
1082 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1086 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1089 exception_error("catchupSelection", e
);
1093 function editArticleTags(id
) {
1094 var query
= "backend.php?op=dlg&method=editArticleTags¶m=" + param_escape(id
);
1096 if (dijit
.byId("editTagsDlg"))
1097 dijit
.byId("editTagsDlg").destroyRecursive();
1099 dialog
= new dijit
.Dialog({
1101 title
: __("Edit article Tags"),
1102 style
: "width: 600px",
1103 execute: function() {
1104 if (this.validate()) {
1105 var query
= dojo
.objectToQuery(this.attr('value'));
1107 notify_progress("Saving article tags...", true);
1109 new Ajax
.Request("backend.php", {
1111 onComplete: function(transport
) {
1115 var data
= JSON
.parse(transport
.responseText
);
1118 var tags_str
= article
.tags
;
1119 var id
= tags_str
.id
;
1121 var tags
= $("ATSTR-" + id
);
1122 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1124 if (tags
) tags
.innerHTML
= tags_str
.content
;
1125 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1127 cache_delete("article:" + id
);
1136 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1137 dojo
.disconnect(tmph
);
1139 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1140 "backend.php?op=rpc&method=completeTags",
1141 { tokens
: ',', paramName
: "search" });
1148 function cdmScrollToArticleId(id
, force
) {
1150 var ctr
= $("headlines-frame");
1151 var e
= $("RROW-" + id
);
1153 if (!e
|| !ctr
) return;
1155 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1156 e
.offsetTop
< ctr
.scrollTop
) {
1157 ctr
.scrollTop
= e
.offsetTop
;
1161 exception_error("cdmScrollToArticleId", e
);
1165 function setActiveArticleId(id
) {
1166 _active_article_id
= id
;
1169 function getActiveArticleId() {
1170 return _active_article_id
;
1173 function postMouseIn(id
) {
1174 post_under_pointer
= id
;
1177 function postMouseOut(id
) {
1178 post_under_pointer
= false;
1181 function headlines_scroll_handler(e
) {
1183 var hsp
= $("headlines-spacer");
1185 if (!_infscroll_disable
) {
1186 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1187 (e
.scrollHeight
!= 0 &&
1188 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1191 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1192 __("Loading, please wait...");
1194 loadMoreHeadlines();
1199 if (hsp
) hsp
.innerHTML
= "";
1202 if (getInitParam("cdm_auto_catchup") == 1) {
1204 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1206 if ($("headlines-frame").scrollTop
>
1207 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1209 var id
= child
.id
.replace("RROW-", "");
1211 if (catchup_id_batch
.indexOf(id
) == -1)
1212 catchup_id_batch
.push(id
);
1214 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1218 if (catchup_id_batch
.length
> 0) {
1219 window
.clearTimeout(catchup_timeout_id
);
1221 if (!_infscroll_request_sent
) {
1222 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1229 console
.warn("headlines_scroll_handler: " + e
);
1233 function catchupBatchedArticles() {
1235 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1237 // make a copy of the array
1238 var batch
= catchup_id_batch
.slice();
1239 var query
= "?op=rpc&method=catchupSelected" +
1240 "&cmode=0&ids=" + param_escape(batch
.toString());
1244 new Ajax
.Request("backend.php", {
1246 onComplete: function(transport
) {
1247 handle_rpc_json(transport
);
1249 batch
.each(function(id
) {
1250 var elem
= $("RROW-" + id
);
1251 if (elem
) elem
.removeClassName("Unread");
1252 catchup_id_batch
.remove(id
);
1259 exception_error("catchupBatchedArticles", e
);
1263 function catchupRelativeToArticle(below
, id
) {
1267 if (!id
) id
= getActiveArticleId();
1270 alert(__("No article is selected."));
1274 var visible_ids
= getVisibleArticleIds();
1276 var ids_to_mark
= new Array();
1279 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1280 if (visible_ids
[i
] != id
) {
1281 var e
= $("RROW-" + visible_ids
[i
]);
1283 if (e
&& e
.hasClassName("Unread")) {
1284 ids_to_mark
.push(visible_ids
[i
]);
1291 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1292 if (visible_ids
[i
] != id
) {
1293 var e
= $("RROW-" + visible_ids
[i
]);
1295 if (e
&& e
.hasClassName("Unread")) {
1296 ids_to_mark
.push(visible_ids
[i
]);
1304 if (ids_to_mark
.length
== 0) {
1305 alert(__("No articles found to mark"));
1307 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1309 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1311 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1312 var e
= $("RROW-" + ids_to_mark
[i
]);
1313 e
.removeClassName("Unread");
1316 var query
= "?op=rpc&method=catchupSelected" +
1317 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1319 new Ajax
.Request("backend.php", {
1321 onComplete: function(transport
) {
1322 handle_rpc_json(transport
);
1329 exception_error("catchupRelativeToArticle", e
);
1333 function cdmExpandArticle(id
) {
1338 var elem
= $("CICD-" + getActiveArticleId());
1340 if (id
== getActiveArticleId() && Element
.visible(elem
))
1343 selectArticles("none");
1345 var old_offset
= $("RROW-" + id
).offsetTop
;
1347 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1349 Element
.show("CEXC-" + getActiveArticleId());
1352 setActiveArticleId(id
);
1354 elem
= $("CICD-" + id
);
1356 if (!Element
.visible(elem
)) {
1358 Element
.hide("CEXC-" + id
);
1361 /* var new_offset = $("RROW-" + id).offsetTop;
1363 $("headlines-frame").scrollTop += (new_offset-old_offset);
1365 if ($("RROW-" + id).offsetTop != old_offset)
1366 $("headlines-frame").scrollTop = new_offset; */
1368 toggleUnread(id
, 0, true);
1372 exception_error("cdmExpandArticle", e
);
1378 function fixHeadlinesOrder(ids
) {
1380 for (var i
= 0; i
< ids
.length
; i
++) {
1381 var e
= $("RROW-" + ids
[i
]);
1385 e
.removeClassName("even");
1386 e
.addClassName("odd");
1388 e
.removeClassName("odd");
1389 e
.addClassName("even");
1394 exception_error("fixHeadlinesOrder", e
);
1398 function getArticleUnderPointer() {
1399 return post_under_pointer
;
1402 function scrollArticle(offset
) {
1405 var ci
= $("content-insert");
1407 ci
.scrollTop
+= offset
;
1410 var hi
= $("headlines-frame");
1412 hi
.scrollTop
+= offset
;
1417 exception_error("scrollArticle", e
);
1421 function show_labels_in_headlines(transport
) {
1423 var data
= JSON
.parse(transport
.responseText
);
1426 data
['info-for-headlines'].each(function(elem
) {
1427 var ctr
= $("HLLCTR-" + elem
.id
);
1429 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1432 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1436 exception_error("show_labels_in_headlines", e
);
1440 function dismissArticle(id
) {
1442 var elem
= $("RROW-" + id
);
1444 toggleUnread(id
, 0, true);
1446 new Effect
.Fade(elem
, {duration
: 0.5});
1448 if (id
== getActiveArticleId()) {
1449 setActiveArticleId(0);
1453 exception_error("dismissArticle", e
);
1457 function dismissSelectedArticles() {
1460 var ids
= getVisibleArticleIds();
1464 for (var i
= 0; i
< ids
.length
; i
++) {
1465 var elem
= $("RROW-" + ids
[i
]);
1467 if (elem
.className
&& elem
.hasClassName("Selected") &&
1468 ids
[i
] != getActiveArticleId()) {
1469 new Effect
.Fade(elem
, {duration
: 0.5});
1477 selectionToggleUnread(false);
1479 fixHeadlinesOrder(tmp
);
1482 exception_error("dismissSelectedArticles", e
);
1486 function dismissReadArticles() {
1489 var ids
= getVisibleArticleIds();
1492 for (var i
= 0; i
< ids
.length
; i
++) {
1493 var elem
= $("RROW-" + ids
[i
]);
1495 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1496 !elem
.hasClassName("Selected")) {
1498 new Effect
.Fade(elem
, {duration
: 0.5});
1504 fixHeadlinesOrder(tmp
);
1507 exception_error("dismissSelectedArticles", e
);
1511 function getVisibleArticleIds() {
1516 getLoadedArticleIds().each(function(id
) {
1517 var elem
= $("RROW-" + id
);
1518 if (elem
&& Element
.visible(elem
))
1523 exception_error("getVisibleArticleIds", e
);
1529 function cdmClicked(event
, id
) {
1531 //var shift_key = event.shiftKey;
1535 if (!event
.ctrlKey
) {
1537 if (!getInitParam("cdm_expanded")) {
1538 return cdmExpandArticle(id
);
1541 selectArticles("none");
1544 var elem
= $("RROW-" + id
);
1545 var article_is_unread
= elem
.hasClassName("Unread");
1548 elem
.removeClassName("Unread");
1550 setActiveArticleId(id
);
1552 if (article_is_unread
) {
1553 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1556 var query
= "?op=rpc&method=catchupSelected" +
1557 "&cmode=0&ids=" + param_escape(id
);
1559 new Ajax
.Request("backend.php", {
1561 onComplete: function(transport
) {
1562 handle_rpc_json(transport
);
1569 toggleSelected(id
, true);
1571 var elem
= $("RROW-" + id
);
1572 var article_is_unread
= elem
.hasClassName("Unread");
1574 if (article_is_unread
) {
1575 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1578 toggleUnread(id
, 0, false);
1580 openArticleInNewWindow(id
);
1583 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1584 request_counters(unread_in_buffer
== 0);
1587 exception_error("cdmClicked");
1593 function hlClicked(event
, id
) {
1595 if (event
.which
== 2) {
1598 } else if (event
.ctrlKey
) {
1599 toggleSelected(id
, true);
1600 toggleUnread(id
, 0, false);
1601 openArticleInNewWindow(id
);
1609 exception_error("hlClicked");
1613 function getFirstVisibleHeadlineId() {
1614 var rows
= getVisibleArticleIds();
1619 function getLastVisibleHeadlineId() {
1620 var rows
= getVisibleArticleIds();
1621 return rows
[rows
.length
-1];
1624 function openArticleInNewWindow(id
) {
1625 toggleUnread(id
, 0, false);
1626 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1629 function isCdmMode() {
1630 return getInitParam("combined_display_mode");
1633 function markHeadline(id
) {
1634 var row
= $("RROW-" + id
);
1636 var check
= $("RCHK-" + id
);
1639 check
.checked
= true;
1642 row
.addClassName("Selected");
1646 function getRelativePostIds(id
, limit
) {
1652 if (!limit
) limit
= 6; //3
1654 var ids
= getVisibleArticleIds();
1656 for (var i
= 0; i
< ids
.length
; i
++) {
1658 for (var k
= 1; k
<= limit
; k
++) {
1659 //if (i > k-1) tmp.push(ids[i-k]);
1660 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1667 exception_error("getRelativePostIds", e
);
1673 function correctHeadlinesOffset(id
) {
1677 var container
= $("headlines-frame");
1678 var row
= $("RROW-" + id
);
1680 if (!container
|| !row
) return;
1682 var viewport
= container
.offsetHeight
;
1684 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1685 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1687 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1688 //console.log("Vport: " + viewport);
1690 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1691 container
.scrollTop
= row
.offsetTop
;
1692 } else if (rel_offset_bottom
> viewport
) {
1694 /* doesn't properly work with Opera in some cases because
1695 Opera fucks up element scrolling */
1697 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1701 exception_error("correctHeadlinesOffset", e
);
1706 function headlineActionsChange(elem
) {
1709 elem
.attr('value', 'false');
1711 exception_error("headlineActionsChange", e
);
1715 function closeArticlePanel() {
1717 if (dijit
.byId("content-insert"))
1718 dijit
.byId("headlines-wrap-inner").removeChild(
1719 dijit
.byId("content-insert"));
1722 function initHeadlinesMenu() {
1724 if (dijit
.byId("headlinesMenu"))
1725 dijit
.byId("headlinesMenu").destroyRecursive();
1730 nodes
= $$("#headlines-frame > div[id*=RROW]");
1732 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1735 nodes
.each(function(node
) {
1739 var menu
= new dijit
.Menu({
1740 id
: "headlinesMenu",
1744 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1745 var callerNode
= event
.target
, match
= null, tries
= 0;
1747 while (match
== null && callerNode
&& tries
<= 3) {
1748 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1749 callerNode
= callerNode
.parentNode
;
1753 if (match
) this.callerRowId
= parseInt(match
[1]);
1757 /* if (!isCdmMode())
1758 menu.addChild(new dijit.MenuItem({
1759 label: __("View article"),
1760 onClick: function(event) {
1761 view(this.getParent().callerRowId);
1764 menu
.addChild(new dijit
.MenuItem({
1765 label
: __("Open original article"),
1766 onClick: function(event
) {
1767 openArticleInNewWindow(this.getParent().callerRowId
);
1770 menu
.addChild(new dijit
.MenuSeparator());
1772 menu
.addChild(new dijit
.MenuItem({
1773 label
: __("Mark above as read"),
1774 onClick: function(event
) {
1775 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1778 menu
.addChild(new dijit
.MenuItem({
1779 label
: __("Mark below as read"),
1780 onClick: function(event
) {
1781 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1785 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1789 menu
.addChild(new dijit
.MenuSeparator());
1791 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1792 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1794 labels
.each(function(label
) {
1795 var id
= label
.id
[0];
1796 var bare_id
= id
.substr(id
.indexOf(":")+1);
1797 var name
= label
.name
[0];
1799 bare_id
= -11-bare_id
;
1801 labelAddMenu
.addChild(new dijit
.MenuItem({
1804 onClick: function(event
) {
1805 var ids
= getSelectedArticleIds2();
1807 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1809 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1811 selectionAssignLabel(this.labelId
, ids
);
1814 labelDelMenu
.addChild(new dijit
.MenuItem({
1817 onClick: function(event
) {
1818 var ids
= getSelectedArticleIds2();
1820 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1822 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1824 selectionRemoveLabel(this.labelId
, ids
);
1829 menu
.addChild(new dijit
.PopupMenuItem({
1830 label
: __("Assign label"),
1831 popup
: labelAddMenu
,
1834 menu
.addChild(new dijit
.PopupMenuItem({
1835 label
: __("Remove label"),
1836 popup
: labelDelMenu
,
1844 exception_error("initHeadlinesMenu", e
);
1849 function player(elem
) {
1850 var aid
= elem
.getAttribute("audio-id");
1851 var status
= elem
.getAttribute("status");
1859 elem
.innerHTML
= __("Playing...");
1860 elem
.title
= __("Click to pause");
1861 elem
.addClassName("playing");
1865 elem
.innerHTML
= __("Play");
1866 elem
.title
= __("Click to play");
1867 elem
.removeClassName("playing");
1870 elem
.setAttribute("status", status
);
1872 alert("Your browser doesn't seem to support HTML5 audio.");
1876 function cache_set(id
, obj
) {
1877 //console.log("cache_set: " + id);
1880 sessionStorage
[id
] = obj
;
1882 sessionStorage
.clear();
1886 function cache_get(id
) {
1888 return sessionStorage
[id
];
1891 function cache_clear() {
1893 sessionStorage
.clear();
1896 function cache_delete(id
) {
1898 sessionStorage
.removeItem(id
);
1901 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
1902 if (toolbar_obj
&& content_obj
) {
1903 cache_set("feed:" + feed
+ ":" + is_cat
,
1904 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
1907 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
1910 obj
= JSON
.parse(obj
);
1912 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
1913 if (content_obj
) obj
.content
= content_obj
;
1915 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
1919 console
.warn("cache_headlines failed: " + e
);
1924 function render_local_headlines(feed
, is_cat
, obj
) {
1927 dijit
.byId("headlines-toolbar").attr('content',
1930 dijit
.byId("headlines-frame").attr('content',
1933 dojo
.parser
.parse('headlines-toolbar');
1935 $("headlines-frame").scrollTop
= 0;
1936 selectArticles('none');
1937 setActiveFeedId(feed
, is_cat
);
1938 initHeadlinesMenu();
1940 dijit
.getEnclosingWidget(
1941 document
.forms
["main_toolbar_form"].update
).attr('disabled',
1942 is_cat
|| feed
<= 0);
1944 precache_headlines();
1947 exception_error("render_local_headlines", e
);
1951 function precache_headlines_idle() {
1953 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id
) {
1954 if (get_timestamp() - _viewfeed_last
> 120) {
1956 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
1959 feeds
.each(function(item
) {
1960 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
1961 uncached
.push(item
);
1964 if (uncached
.length
> 0) {
1965 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
1966 viewfeed(rf
[0], '', rf
[1], 0, true);
1970 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 1000*30);
1973 exception_error("precache_headlines_idle", e
);
1977 function precache_headlines() {
1979 if (getInitParam("bw_limit") != "1" && !feed_precache_timeout_id
) {
1981 feed_precache_timeout_id
= window
.setTimeout(function() {
1982 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
1983 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
1985 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
1986 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
1988 if (nf
&& nf
[0] != nuf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
1989 viewfeed(nf
[0], '', nf
[1], 0, true);
1991 window
.setTimeout(function() {
1992 feed_precache_timeout_id
= false;
1998 exception_error("precache_headlines", e
);
2002 function cancelSearch() {
2007 exception_error("cancelSearch", e
);
2011 function setSelectionScore() {
2013 var ids
= getSelectedArticleIds2();
2015 if (ids
.length
> 0) {
2018 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2020 if (score
!= undefined) {
2021 var query
= "op=rpc&method=setScore&id=" + param_escape(ids
.toString()) +
2022 "&score=" + param_escape(score
);
2024 new Ajax
.Request("backend.php", {
2026 onComplete: function(transport
) {
2027 var reply
= JSON
.parse(transport
.responseText
);
2031 ids
.each(function(id
) {
2032 var row
= $("RROW-" + id
);
2035 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2038 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2039 reply
["score_pic"]);
2040 pic
.setAttribute("score", score
);
2049 alert(__("No articles are selected."));
2052 exception_error("setSelectionScore", e
);
2056 function changeScore(id
, pic
) {
2058 var score
= pic
.getAttribute("score");
2060 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2062 if (new_score
!= undefined) {
2064 var query
= "op=rpc&method=setScore&id=" + param_escape(id
) +
2065 "&score=" + param_escape(new_score
);
2067 new Ajax
.Request("backend.php", {
2069 onComplete: function(transport
) {
2070 var reply
= JSON
.parse(transport
.responseText
);
2073 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2074 pic
.setAttribute("score", new_score
);
2079 exception_error("changeScore", e
);