]>
git.wh0rd.org - tt-rss.git/blob - js/viewfeed.js
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;
13 var cids_requested
= [];
14 var loaded_article_ids
= [];
16 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
18 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
20 handle_rpc_json(transport
);
22 loading_set_progress(25);
24 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
32 reply
= JSON
.parse(transport
.responseText
);
39 is_cat
= reply
['headlines']['is_cat'];
40 feed_id
= reply
['headlines']['id'];
43 var content
= reply
['headlines']['content'];
45 if (getInitParam("cdm_auto_catchup") == 1) {
46 content
= content
+ "<div id='headlines-spacer'></div>";
51 setActiveFeedId(feed_id
, is_cat
);
53 /* dijit.getEnclosingWidget(
54 document.forms["main_toolbar_form"].update).attr('disabled',
55 is_cat || feed_id <= 0); */
58 if (infscroll_req
== false) {
59 $("headlines-frame").scrollTop
= 0;
63 var headlines_count
= reply
['headlines-info']['count'];
65 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
67 if (parseInt(headlines_count
) < 30) {
68 _infscroll_disable
= 1;
70 _infscroll_disable
= 0;
73 var counters
= reply
['counters'];
74 var articles
= reply
['articles'];
75 //var runtime_info = reply['runtime-info'];
77 if (infscroll_req
== false) {
78 loaded_article_ids
= [];
80 dijit
.byId("headlines-frame").attr('content',
81 reply
['headlines']['content']);
83 dijit
.byId("headlines-toolbar").attr('content',
84 reply
['headlines']['toolbar']);
86 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
87 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
88 row
.parentNode
.removeChild(row
);
90 loaded_article_ids
.push(row
.id
);
94 if (getInitParam("cdm_auto_catchup") == 1) {
95 var hsp
= $("headlines-spacer");
96 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
97 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
103 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
104 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
110 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
111 console
.log("adding some more headlines: " + headlines_count
);
113 var c
= dijit
.byId("headlines-frame");
114 var ids
= getSelectedArticleIds2();
117 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
119 var hsp
= $("headlines-spacer");
122 c
.domNode
.removeChild(hsp
);
124 $$("#headlines-tmp > div").each(function(row
) {
125 if (row
.className
== 'cdmFeedTitle') {
126 row
.style
.display
= 'none';
127 c
.domNode
.appendChild(row
);
129 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
130 row
.style
.display
= 'none';
131 c
.domNode
.appendChild(row
);
133 loaded_article_ids
.push(row
.id
);
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 " + new_elems
.size() + " headlines");
149 if (new_elems
.size() == 0)
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 new_elems
.each(function(child
) {
161 var cb
= dijit
.byId(child
.id
.replace("RROW-", "RCHK-"));
164 dojo
.parser
.parse(child
);
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
= "";
183 for (var i
= 0; i
< articles
.length
; i
++) {
184 var a_id
= articles
[i
]['id'];
185 cache_set("article:" + a_id
, articles
[i
]['content']);
188 console
.log("no cached articles received");
192 parse_counters(counters
);
194 request_counters(true);
196 } else if (transport
.responseText
) {
197 console
.error("Invalid object received: " + transport
.responseText
);
198 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
199 __('Could not update headlines (invalid object received - see error console for details)') +
202 //notify_error("Error communicating with server.");
203 Element
.show(dijit
.byId("net-alert").domNode
);
206 _infscroll_request_sent
= 0;
208 unpackVisibleHeadlines();
213 exception_error("headlines_callback2", e
, transport
);
217 function render_article(article
) {
219 dijit
.byId("headlines-wrap-inner").addChild(
220 dijit
.byId("content-insert"));
222 var c
= dijit
.byId("content-insert");
225 c
.domNode
.scrollTop
= 0;
228 c
.attr('content', article
);
230 correctHeadlinesOffset(getActiveArticleId());
237 exception_error("render_article", e
);
241 function showArticleInHeadlines(id
) {
244 selectArticles("none");
246 var crow
= $("RROW-" + id
);
250 var article_is_unread
= crow
.hasClassName("Unread");
252 crow
.removeClassName("Unread");
253 crow
.addClassName("active");
255 selectArticles('none');
257 var view_mode
= false;
260 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
261 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
268 if (article_is_unread
)
269 _force_scheduled_update
= true;
272 exception_error("showArticleInHeadlines", e
);
276 function article_callback2(transport
, id
) {
278 console
.log("article_callback2 " + id
);
280 handle_rpc_json(transport
);
285 reply
= JSON
.parse(transport
.responseText
);
292 reply
.each(function(article
) {
293 if (getActiveArticleId() == article
['id']) {
294 render_article(article
['content']);
296 cids_requested
.remove(article
['id']);
298 cache_set("article:" + article
['id'], article
['content']);
301 // if (id != last_requested_article) {
302 // console.log("requested article id is out of sequence, aborting");
306 } else if (transport
.responseText
) {
307 console
.error("Invalid object received: " + transport
.responseText
);
309 render_article("<div class='whiteBox'>" +
310 __('Could not display article (invalid object received - see error console for details)') + "</div>");
312 Element
.show(dijit
.byId("net-alert").domNode
);
315 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
316 request_counters(unread_in_buffer
== 0);
318 //headlines_scroll_handler($("headlines-frame"));
321 if (!_infscroll_disable &&
322 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
332 exception_error("article_callback2", e
, transport
);
338 var oldrow
= $("RROW-" + getActiveArticleId());
339 if (oldrow
) oldrow
.removeClassName("active");
341 var crow
= $("RROW-" + id
);
345 console
.log("loading article: " + id
);
347 var cached_article
= cache_get("article:" + id
);
349 console
.log("cache check result: " + (cached_article
!= false));
351 var query
= "?op=article&method=view&id=" + param_escape(id
);
353 var neighbor_ids
= getRelativePostIds(id
);
355 /* only request uncached articles */
357 var cids_to_request
= [];
359 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
360 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
361 if (!cache_get("article:" + neighbor_ids
[i
])) {
362 cids_to_request
.push(neighbor_ids
[i
]);
363 cids_requested
.push(neighbor_ids
[i
]);
367 console
.log("additional ids: " + cids_to_request
.toString());
369 query
= query
+ "&cids=" + cids_to_request
.toString();
371 var article_is_unread
= crow
.hasClassName("Unread");
373 setActiveArticleId(id
);
374 showArticleInHeadlines(id
);
376 if (cached_article
&& article_is_unread
) {
378 query
= query
+ "&mode=prefetch";
380 render_article(cached_article
);
382 } else if (cached_article
) {
384 query
= query
+ "&mode=prefetch_old";
385 render_article(cached_article
);
387 // if we don't need to request any relative ids, we might as well skip
388 // the server roundtrip altogether
389 if (cids_to_request
.length
== 0) {
392 if (!_infscroll_disable &&
393 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
401 //headlines_scroll_handler($("headlines-frame"));
407 last_requested_article
= id
;
411 if (article_is_unread
) {
412 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
415 new Ajax
.Request("backend.php", {
417 onComplete: function(transport
) {
418 article_callback2(transport
, id
);
424 exception_error("view", e
);
428 function toggleMark(id
, client_only
) {
430 var query
= "?op=rpc&id=" + id
+ "&method=mark";
432 var img
= $("FMPIC-" + id
);
436 if (img
.src
.match("mark_unset")) {
437 img
.src
= img
.src
.replace("mark_unset", "mark_set");
438 img
.alt
= __("Unstar article");
439 query
= query
+ "&mark=1";
442 img
.src
= img
.src
.replace("mark_set", "mark_unset");
443 img
.alt
= __("Star article");
444 query
= query
+ "&mark=0";
448 new Ajax
.Request("backend.php", {
450 onComplete: function(transport
) {
451 handle_rpc_json(transport
);
456 exception_error("toggleMark", e
);
460 function togglePub(id
, client_only
, no_effects
, note
) {
462 var query
= "?op=rpc&id=" + id
+ "&method=publ";
464 if (note
!= undefined) {
465 query
= query
+ "¬e=" + param_escape(note
);
467 query
= query
+ "¬e=undefined";
470 var img
= $("FPPIC-" + id
);
474 if (img
.src
.match("pub_unset") || note
!= undefined) {
475 img
.src
= img
.src
.replace("pub_unset", "pub_set");
476 img
.alt
= __("Unpublish article");
477 query
= query
+ "&pub=1";
480 img
.src
= img
.src
.replace("pub_set", "pub_unset");
481 img
.alt
= __("Publish article");
483 query
= query
+ "&pub=0";
487 new Ajax
.Request("backend.php", {
489 onComplete: function(transport
) {
490 handle_rpc_json(transport
);
495 exception_error("togglePub", e
);
499 function moveToPost(mode
, noscroll
) {
503 var rows
= getVisibleArticleIds();
508 if (!$('RROW-' + getActiveArticleId())) {
509 setActiveArticleId(0);
512 if (!getActiveArticleId()) {
514 prev_id
= rows
[rows
.length
-1]
516 for (var i
= 0; i
< rows
.length
; i
++) {
517 if (rows
[i
] == getActiveArticleId()) {
519 // Account for adjacent identical article ids.
520 if (i
> 0) prev_id
= rows
[i
-1];
522 for (var j
= i
+1; j
< rows
.length
; j
++) {
523 if (rows
[j
] != getActiveArticleId()) {
533 if (mode
== "next") {
534 if (next_id
|| getActiveArticleId()) {
537 var article
= $("RROW-" + getActiveArticleId());
538 var ctr
= $("headlines-frame");
540 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
541 ctr
.scrollTop
+ ctr
.offsetHeight
) {
543 scrollArticle(ctr
.offsetHeight
/4);
545 } else if (next_id
) {
546 cdmExpandArticle(next_id
);
547 cdmScrollToArticleId(next_id
, true);
550 } else if (next_id
) {
551 correctHeadlinesOffset(next_id
);
552 view(next_id
, getActiveFeedId());
557 if (mode
== "prev") {
558 if (prev_id
|| getActiveArticleId()) {
561 var article
= $("RROW-" + getActiveArticleId());
562 var prev_article
= $("RROW-" + prev_id
);
563 var ctr
= $("headlines-frame");
565 if (!getInitParam("cdm_expanded")) {
567 if (!noscroll
&& article
.offsetTop
< ctr
.scrollTop
) {
568 scrollArticle(-ctr
.offsetHeight
/4);
570 cdmExpandArticle(prev_id
);
571 cdmScrollToArticleId(prev_id
, true);
575 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
576 scrollArticle(-ctr
.offsetHeight
/3);
577 } else if (!noscroll
&& prev_article
&&
578 prev_article
.offsetTop
< ctr
.scrollTop
) {
579 cdmExpandArticle(prev_id
);
580 scrollArticle(-ctr
.offsetHeight
/4);
581 } else if (prev_id
) {
582 cdmExpandArticle(prev_id
);
583 cdmScrollToArticleId(prev_id
, noscroll
);
587 } else if (prev_id
) {
588 correctHeadlinesOffset(prev_id
);
589 view(prev_id
, getActiveFeedId());
595 exception_error("moveToPost", e
);
599 function toggleSelected(id
, force_on
) {
602 var cb
= dijit
.byId("RCHK-" + id
);
603 var row
= $("RROW-" + id
);
606 if (row
.hasClassName('Selected') && !force_on
) {
607 row
.removeClassName('Selected');
608 if (cb
) cb
.attr("checked", false);
610 row
.addClassName('Selected');
611 if (cb
) cb
.attr("checked", true);
615 exception_error("toggleSelected", e
);
619 function toggleUnread_afh(effect
) {
622 var elem
= effect
.element
;
623 elem
.style
.backgroundColor
= "";
626 exception_error("toggleUnread_afh", e
);
630 function toggleUnread(id
, cmode
, effect
) {
633 var row
= $("RROW-" + id
);
635 if (cmode
== undefined || cmode
== 2) {
636 if (row
.hasClassName("Unread")) {
637 row
.removeClassName("Unread");
640 row
.addClassName("Unread");
643 } else if (cmode
== 0) {
645 row
.removeClassName("Unread");
647 } else if (cmode
== 1) {
648 row
.addClassName("Unread");
651 if (cmode
== undefined) cmode
= 2;
653 var query
= "?op=rpc&method=catchupSelected" +
654 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
656 // notify_progress("Loading, please wait...");
658 new Ajax
.Request("backend.php", {
660 onComplete: function(transport
) {
661 handle_rpc_json(transport
);
667 exception_error("toggleUnread", e
);
671 function selectionRemoveLabel(id
, ids
) {
674 if (!ids
) ids
= getSelectedArticleIds2();
676 if (ids
.length
== 0) {
677 alert(__("No articles are selected."));
681 var query
= "?op=article&method=removeFromLabel&ids=" +
682 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
686 new Ajax
.Request("backend.php", {
688 onComplete: function(transport
) {
689 handle_rpc_json(transport
);
690 show_labels_in_headlines(transport
);
694 exception_error("selectionAssignLabel", e
);
699 function selectionAssignLabel(id
, ids
) {
702 if (!ids
) ids
= getSelectedArticleIds2();
704 if (ids
.length
== 0) {
705 alert(__("No articles are selected."));
709 var query
= "?op=article&method=assignToLabel&ids=" +
710 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
714 new Ajax
.Request("backend.php", {
716 onComplete: function(transport
) {
717 handle_rpc_json(transport
);
718 show_labels_in_headlines(transport
);
722 exception_error("selectionAssignLabel", e
);
727 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
729 var rows
= ids
? ids
: getSelectedArticleIds2();
731 if (rows
.length
== 0 && !no_error
) {
732 alert(__("No articles are selected."));
736 for (var i
= 0; i
< rows
.length
; i
++) {
737 var row
= $("RROW-" + rows
[i
]);
739 if (set_state
== undefined) {
740 if (row
.hasClassName("Unread")) {
741 row
.removeClassName("Unread");
743 row
.addClassName("Unread");
747 if (set_state
== false) {
748 row
.removeClassName("Unread");
751 if (set_state
== true) {
752 row
.addClassName("Unread");
757 if (rows
.length
> 0) {
761 if (set_state
== undefined) {
763 } else if (set_state
== true) {
765 } else if (set_state
== false) {
769 var query
= "?op=rpc&method=catchupSelected" +
770 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
772 notify_progress("Loading, please wait...");
774 new Ajax
.Request("backend.php", {
776 onComplete: function(transport
) {
777 handle_rpc_json(transport
);
778 if (callback
) callback(transport
);
784 exception_error("selectionToggleUnread", e
);
789 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
792 var rows
= ids
? ids
: getSelectedArticleIds2();
794 if (rows
.length
== 0 && !no_error
) {
795 alert(__("No articles are selected."));
799 for (var i
= 0; i
< rows
.length
; i
++) {
800 toggleMark(rows
[i
], true, true);
803 if (rows
.length
> 0) {
805 var query
= "?op=rpc&method=markSelected&ids=" +
806 param_escape(rows
.toString()) + "&cmode=2";
808 new Ajax
.Request("backend.php", {
810 onComplete: function(transport
) {
811 handle_rpc_json(transport
);
812 if (callback
) callback(transport
);
818 exception_error("selectionToggleMarked", e
);
823 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
826 var rows
= ids
? ids
: getSelectedArticleIds2();
828 if (rows
.length
== 0 && !no_error
) {
829 alert(__("No articles are selected."));
833 for (var i
= 0; i
< rows
.length
; i
++) {
834 togglePub(rows
[i
], true, true);
837 if (rows
.length
> 0) {
839 var query
= "?op=rpc&method=publishSelected&ids=" +
840 param_escape(rows
.toString()) + "&cmode=2";
842 new Ajax
.Request("backend.php", {
844 onComplete: function(transport
) {
845 handle_rpc_json(transport
);
851 exception_error("selectionToggleMarked", e
);
855 function getSelectedArticleIds2() {
859 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
861 rv
.push(child
.id
.replace("RROW-", ""));
867 function getLoadedArticleIds() {
870 var children
= $$("#headlines-frame > div[id*=RROW-]");
872 children
.each(function(child
) {
873 rv
.push(child
.id
.replace("RROW-", ""));
880 // mode = all,none,unread,invert,marked,published
881 function selectArticles(mode
) {
884 var children
= $$("#headlines-frame > div[id*=RROW]");
886 children
.each(function(child
) {
887 var id
= child
.id
.replace("RROW-", "");
888 var cb
= dijit
.byId("RCHK-" + id
);
891 child
.addClassName("Selected");
892 if (cb
) cb
.attr("checked", true);
893 } else if (mode
== "unread") {
894 if (child
.hasClassName("Unread")) {
895 child
.addClassName("Selected");
896 if (cb
) cb
.attr("checked", true);
898 child
.removeClassName("Selected");
899 if (cb
) cb
.attr("checked", false);
901 } else if (mode
== "marked") {
902 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
904 if (img
&& img
.src
.match("mark_set")) {
905 child
.addClassName("Selected");
906 if (cb
) cb
.attr("checked", true);
908 child
.removeClassName("Selected");
909 if (cb
) cb
.attr("checked", false);
911 } else if (mode
== "published") {
912 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
914 if (img
&& img
.src
.match("pub_set")) {
915 child
.addClassName("Selected");
916 if (cb
) cb
.attr("checked", true);
918 child
.removeClassName("Selected");
919 if (cb
) cb
.attr("checked", false);
922 } else if (mode
== "invert") {
923 if (child
.hasClassName("Selected")) {
924 child
.removeClassName("Selected");
925 if (cb
) cb
.attr("checked", false);
927 child
.addClassName("Selected");
928 if (cb
) cb
.attr("checked", true);
932 child
.removeClassName("Selected");
933 if (cb
) cb
.attr("checked", false);
938 exception_error("selectArticles", e
);
942 function deleteSelection() {
946 var rows
= getSelectedArticleIds2();
948 if (rows
.length
== 0) {
949 alert(__("No articles are selected."));
953 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
956 if (getActiveFeedId() != 0) {
957 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
959 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
962 str
= str
.replace("%d", rows
.length
);
963 str
= str
.replace("%s", fn
);
965 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
969 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
973 new Ajax
.Request("backend.php", {
975 onComplete: function(transport
) {
976 handle_rpc_json(transport
);
981 exception_error("deleteSelection", e
);
985 function archiveSelection() {
989 var rows
= getSelectedArticleIds2();
991 if (rows
.length
== 0) {
992 alert(__("No articles are selected."));
996 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1000 if (getActiveFeedId() != 0) {
1001 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1004 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1006 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1011 str
= str
.replace("%d", rows
.length
);
1012 str
= str
.replace("%s", fn
);
1014 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1018 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1022 for (var i
= 0; i
< rows
.length
; i
++) {
1023 cache_delete("article:" + rows
[i
]);
1026 new Ajax
.Request("backend.php", {
1028 onComplete: function(transport
) {
1029 handle_rpc_json(transport
);
1034 exception_error("archiveSelection", e
);
1038 function catchupSelection() {
1042 var rows
= getSelectedArticleIds2();
1044 if (rows
.length
== 0) {
1045 alert(__("No articles are selected."));
1049 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1051 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1053 str
= str
.replace("%d", rows
.length
);
1054 str
= str
.replace("%s", fn
);
1056 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1060 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1063 exception_error("catchupSelection", e
);
1067 function editArticleTags(id
) {
1068 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1070 if (dijit
.byId("editTagsDlg"))
1071 dijit
.byId("editTagsDlg").destroyRecursive();
1073 dialog
= new dijit
.Dialog({
1075 title
: __("Edit article Tags"),
1076 style
: "width: 600px",
1077 execute: function() {
1078 if (this.validate()) {
1079 var query
= dojo
.objectToQuery(this.attr('value'));
1081 notify_progress("Saving article tags...", true);
1083 new Ajax
.Request("backend.php", {
1085 onComplete: function(transport
) {
1090 var data
= JSON
.parse(transport
.responseText
);
1097 var tags
= $("ATSTR-" + id
);
1098 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1100 if (tags
) tags
.innerHTML
= data
.content
;
1101 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1104 exception_error("editArticleTags/inner", e
);
1113 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1114 dojo
.disconnect(tmph
);
1116 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1117 "backend.php?op=article&method=completeTags",
1118 { tokens
: ',', paramName
: "search" });
1125 function cdmScrollToArticleId(id
, force
) {
1127 var ctr
= $("headlines-frame");
1128 var e
= $("RROW-" + id
);
1130 if (!e
|| !ctr
) return;
1132 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1133 e
.offsetTop
< ctr
.scrollTop
) {
1135 // expanded cdm has a 4px margin now
1136 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1140 exception_error("cdmScrollToArticleId", e
);
1144 function setActiveArticleId(id
) {
1145 _active_article_id
= id
;
1148 function getActiveArticleId() {
1149 return _active_article_id
;
1152 function postMouseIn(e
, id
) {
1153 post_under_pointer
= id
;
1156 function postMouseOut(id
) {
1157 post_under_pointer
= false;
1160 function unpackVisibleHeadlines() {
1163 if (!isCdmMode()) return;
1165 $$("#headlines-frame > div[id*=RROW]").each(
1167 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1168 $("headlines-frame").offsetHeight
) {
1170 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1173 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1174 cencw
.setAttribute('id', '');
1175 Element
.show(cencw
);
1183 exception_error("unpackVisibleHeadlines", e
);
1187 function headlines_scroll_handler(e
) {
1189 var hsp
= $("headlines-spacer");
1191 unpackVisibleHeadlines();
1193 if (!_infscroll_disable
) {
1194 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1195 (e
.scrollHeight
!= 0 &&
1196 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1199 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1200 __("Loading, please wait...");
1202 loadMoreHeadlines();
1207 if (hsp
) hsp
.innerHTML
= "";
1210 if (getInitParam("cdm_auto_catchup") == 1) {
1212 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1214 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1215 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1217 var id
= child
.id
.replace("RROW-", "");
1219 if (catchup_id_batch
.indexOf(id
) == -1)
1220 catchup_id_batch
.push(id
);
1222 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1226 if (catchup_id_batch
.length
> 0) {
1227 window
.clearTimeout(catchup_timeout_id
);
1229 if (!_infscroll_request_sent
) {
1230 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1237 console
.warn("headlines_scroll_handler: " + e
);
1241 function catchupBatchedArticles() {
1243 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1245 // make a copy of the array
1246 var batch
= catchup_id_batch
.slice();
1247 var query
= "?op=rpc&method=catchupSelected" +
1248 "&cmode=0&ids=" + param_escape(batch
.toString());
1252 new Ajax
.Request("backend.php", {
1254 onComplete: function(transport
) {
1255 handle_rpc_json(transport
);
1257 batch
.each(function(id
) {
1258 var elem
= $("RROW-" + id
);
1259 if (elem
) elem
.removeClassName("Unread");
1260 catchup_id_batch
.remove(id
);
1267 exception_error("catchupBatchedArticles", e
);
1271 function catchupRelativeToArticle(below
, id
) {
1275 if (!id
) id
= getActiveArticleId();
1278 alert(__("No article is selected."));
1282 var visible_ids
= getVisibleArticleIds();
1284 var ids_to_mark
= new Array();
1287 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1288 if (visible_ids
[i
] != id
) {
1289 var e
= $("RROW-" + visible_ids
[i
]);
1291 if (e
&& e
.hasClassName("Unread")) {
1292 ids_to_mark
.push(visible_ids
[i
]);
1299 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1300 if (visible_ids
[i
] != id
) {
1301 var e
= $("RROW-" + visible_ids
[i
]);
1303 if (e
&& e
.hasClassName("Unread")) {
1304 ids_to_mark
.push(visible_ids
[i
]);
1312 if (ids_to_mark
.length
== 0) {
1313 alert(__("No articles found to mark"));
1315 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1317 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1319 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1320 var e
= $("RROW-" + ids_to_mark
[i
]);
1321 e
.removeClassName("Unread");
1324 var query
= "?op=rpc&method=catchupSelected" +
1325 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1327 new Ajax
.Request("backend.php", {
1329 onComplete: function(transport
) {
1330 handle_rpc_json(transport
);
1337 exception_error("catchupRelativeToArticle", e
);
1341 function cdmCollapseArticle(event
, id
) {
1343 var row
= $("RROW-" + id
);
1344 var elem
= $("CICD-" + id
);
1347 var collapse
= $$("div#RROW-" + id
+
1348 " span[class='collapseBtn']")[0];
1351 Element
.show("CEXC-" + id
);
1352 Element
.hide(collapse
);
1353 row
.removeClassName("active");
1355 markHeadline(id
, false);
1357 if (id
== getActiveArticleId()) {
1358 setActiveArticleId(0);
1361 if (event
) Event
.stop(event
);
1365 exception_error("cdmCollapseArticle", e
);
1369 function cdmExpandArticle(id
) {
1371 console
.log("cdmExpandArticle " + id
);
1373 if (!$("RROW-" + id
)) return false;
1375 var oldrow
= $("RROW-" + getActiveArticleId());
1377 var elem
= $("CICD-" + getActiveArticleId());
1379 if (id
== getActiveArticleId() && Element
.visible(elem
))
1382 selectArticles("none");
1384 var old_offset
= $("RROW-" + id
).offsetTop
;
1386 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1387 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1388 " span[class='collapseBtn']")[0];
1391 Element
.show("CEXC-" + getActiveArticleId());
1392 Element
.hide(collapse
);
1395 if (oldrow
) oldrow
.removeClassName("active");
1397 setActiveArticleId(id
);
1399 elem
= $("CICD-" + id
);
1401 var collapse
= $$("div#RROW-" + id
+
1402 " span[class='collapseBtn']")[0];
1404 var cencw
= $("CENCW-" + id
);
1406 if (!Element
.visible(elem
)) {
1408 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1409 cencw
.setAttribute('id', '');
1410 Element
.show(cencw
);
1414 Element
.hide("CEXC-" + id
);
1415 Element
.show(collapse
);
1418 var new_offset
= $("RROW-" + id
).offsetTop
;
1420 if (old_offset
> new_offset
)
1421 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1423 toggleUnread(id
, 0, true);
1425 $("RROW-" + id
).addClassName("active");
1428 exception_error("cdmExpandArticle", e
);
1434 function fixHeadlinesOrder(ids
) {
1436 for (var i
= 0; i
< ids
.length
; i
++) {
1437 var e
= $("RROW-" + ids
[i
]);
1441 e
.removeClassName("even");
1442 e
.addClassName("odd");
1444 e
.removeClassName("odd");
1445 e
.addClassName("even");
1450 exception_error("fixHeadlinesOrder", e
);
1454 function getArticleUnderPointer() {
1455 return post_under_pointer
;
1458 function scrollArticle(offset
) {
1461 var ci
= $("content-insert");
1463 ci
.scrollTop
+= offset
;
1466 var hi
= $("headlines-frame");
1468 hi
.scrollTop
+= offset
;
1473 exception_error("scrollArticle", e
);
1477 function show_labels_in_headlines(transport
) {
1479 var data
= JSON
.parse(transport
.responseText
);
1482 data
['info-for-headlines'].each(function(elem
) {
1483 var ctr
= $("HLLCTR-" + elem
.id
);
1485 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1489 exception_error("show_labels_in_headlines", e
);
1493 function dismissArticle(id
) {
1495 var elem
= $("RROW-" + id
);
1499 toggleUnread(id
, 0, true);
1501 new Effect
.Fade(elem
, {duration
: 0.5});
1503 if (id
== getActiveArticleId()) {
1504 setActiveArticleId(0);
1508 exception_error("dismissArticle", e
);
1512 function dismissSelectedArticles() {
1515 var ids
= getVisibleArticleIds();
1519 for (var i
= 0; i
< ids
.length
; i
++) {
1520 var elem
= $("RROW-" + ids
[i
]);
1522 if (elem
.className
&& elem
.hasClassName("Selected") &&
1523 ids
[i
] != getActiveArticleId()) {
1524 new Effect
.Fade(elem
, {duration
: 0.5});
1532 selectionToggleUnread(false);
1534 fixHeadlinesOrder(tmp
);
1537 exception_error("dismissSelectedArticles", e
);
1541 function dismissReadArticles() {
1544 var ids
= getVisibleArticleIds();
1547 for (var i
= 0; i
< ids
.length
; i
++) {
1548 var elem
= $("RROW-" + ids
[i
]);
1550 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1551 !elem
.hasClassName("Selected")) {
1553 new Effect
.Fade(elem
, {duration
: 0.5});
1559 fixHeadlinesOrder(tmp
);
1562 exception_error("dismissSelectedArticles", e
);
1566 function getVisibleArticleIds() {
1571 getLoadedArticleIds().each(function(id
) {
1572 var elem
= $("RROW-" + id
);
1573 if (elem
&& Element
.visible(elem
))
1578 exception_error("getVisibleArticleIds", e
);
1584 function cdmClicked(event
, id
) {
1586 //var shift_key = event.shiftKey;
1588 if (!event
.ctrlKey
) {
1590 if (!getInitParam("cdm_expanded")) {
1591 return cdmExpandArticle(id
);
1594 var elem
= $("RROW-" + getActiveArticleId());
1596 if (elem
) elem
.removeClassName("active");
1598 selectArticles("none");
1601 var elem
= $("RROW-" + id
);
1602 var article_is_unread
= elem
.hasClassName("Unread");
1604 elem
.removeClassName("Unread");
1605 elem
.addClassName("active");
1607 setActiveArticleId(id
);
1609 if (article_is_unread
) {
1610 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1613 var query
= "?op=rpc&method=catchupSelected" +
1614 "&cmode=0&ids=" + param_escape(id
);
1616 new Ajax
.Request("backend.php", {
1618 onComplete: function(transport
) {
1619 handle_rpc_json(transport
);
1622 return !event
.shiftKey
;
1626 toggleSelected(id
, true);
1628 var elem
= $("RROW-" + id
);
1629 var article_is_unread
= elem
.hasClassName("Unread");
1631 if (article_is_unread
) {
1632 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1635 toggleUnread(id
, 0, false);
1637 openArticleInNewWindow(id
);
1640 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1641 request_counters(unread_in_buffer
== 0);
1644 exception_error("cdmClicked");
1650 function hlClicked(event
, id
) {
1652 if (event
.which
== 2) {
1655 } else if (event
.ctrlKey
) {
1656 toggleSelected(id
, true);
1657 toggleUnread(id
, 0, false);
1658 openArticleInNewWindow(id
);
1666 exception_error("hlClicked");
1670 function getFirstVisibleHeadlineId() {
1671 var rows
= getVisibleArticleIds();
1676 function getLastVisibleHeadlineId() {
1677 var rows
= getVisibleArticleIds();
1678 return rows
[rows
.length
-1];
1681 function openArticleInNewWindow(id
) {
1682 toggleUnread(id
, 0, false);
1683 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1686 function isCdmMode() {
1687 return getInitParam("combined_display_mode");
1690 function markHeadline(id
, marked
) {
1691 if (marked
== undefined) marked
= true;
1693 var row
= $("RROW-" + id
);
1695 var check
= dijit
.byId("RCHK-" + id
);
1698 check
.attr("checked", marked
);
1702 row
.addClassName("Selected");
1704 row
.removeClassName("Selected");
1708 function getRelativePostIds(id
, limit
) {
1714 if (!limit
) limit
= 6; //3
1716 var ids
= getVisibleArticleIds();
1718 for (var i
= 0; i
< ids
.length
; i
++) {
1720 for (var k
= 1; k
<= limit
; k
++) {
1721 //if (i > k-1) tmp.push(ids[i-k]);
1722 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1729 exception_error("getRelativePostIds", e
);
1735 function correctHeadlinesOffset(id
) {
1739 var container
= $("headlines-frame");
1740 var row
= $("RROW-" + id
);
1742 if (!container
|| !row
) return;
1744 var viewport
= container
.offsetHeight
;
1746 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1747 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1749 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1750 //console.log("Vport: " + viewport);
1752 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1753 container
.scrollTop
= row
.offsetTop
;
1754 } else if (rel_offset_bottom
> viewport
) {
1756 /* doesn't properly work with Opera in some cases because
1757 Opera fucks up element scrolling */
1759 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1763 exception_error("correctHeadlinesOffset", e
);
1768 function headlineActionsChange(elem
) {
1771 elem
.attr('value', 'false');
1773 exception_error("headlineActionsChange", e
);
1777 function closeArticlePanel() {
1779 if (dijit
.byId("content-insert"))
1780 dijit
.byId("headlines-wrap-inner").removeChild(
1781 dijit
.byId("content-insert"));
1784 function initHeadlinesMenu() {
1786 if (dijit
.byId("headlinesMenu"))
1787 dijit
.byId("headlinesMenu").destroyRecursive();
1792 nodes
= $$("#headlines-frame > div[id*=RROW]");
1794 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1797 nodes
.each(function(node
) {
1801 var menu
= new dijit
.Menu({
1802 id
: "headlinesMenu",
1806 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1807 var callerNode
= event
.target
, match
= null, tries
= 0;
1809 while (match
== null && callerNode
&& tries
<= 3) {
1810 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1811 callerNode
= callerNode
.parentNode
;
1815 if (match
) this.callerRowId
= parseInt(match
[1]);
1819 /* if (!isCdmMode())
1820 menu.addChild(new dijit.MenuItem({
1821 label: __("View article"),
1822 onClick: function(event) {
1823 view(this.getParent().callerRowId);
1826 menu
.addChild(new dijit
.MenuItem({
1827 label
: __("Open original article"),
1828 onClick: function(event
) {
1829 openArticleInNewWindow(this.getParent().callerRowId
);
1832 menu
.addChild(new dijit
.MenuItem({
1833 label
: __("Display article URL"),
1834 onClick: function(event
) {
1835 displayArticleUrl(this.getParent().callerRowId
);
1838 menu
.addChild(new dijit
.MenuSeparator());
1840 menu
.addChild(new dijit
.MenuItem({
1841 label
: __("Toggle unread"),
1842 onClick: function(event
) {
1843 var ids
= getSelectedArticleIds2();
1845 var id
= this.getParent().callerRowId
+ "";
1846 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1848 selectionToggleUnread(undefined, false, true, ids
);
1851 menu
.addChild(new dijit
.MenuItem({
1852 label
: __("Toggle marked"),
1853 onClick: function(event
) {
1854 var ids
= getSelectedArticleIds2();
1856 var id
= this.getParent().callerRowId
+ "";
1857 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1859 selectionToggleMarked(undefined, false, true, ids
);
1862 menu
.addChild(new dijit
.MenuItem({
1863 label
: __("Toggle published"),
1864 onClick: function(event
) {
1865 var ids
= getSelectedArticleIds2();
1867 var id
= this.getParent().callerRowId
+ "";
1868 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1870 selectionTogglePublished(undefined, false, true, ids
);
1873 menu
.addChild(new dijit
.MenuSeparator());
1875 menu
.addChild(new dijit
.MenuItem({
1876 label
: __("Mark above as read"),
1877 onClick: function(event
) {
1878 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1881 menu
.addChild(new dijit
.MenuItem({
1882 label
: __("Mark below as read"),
1883 onClick: function(event
) {
1884 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1888 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1892 menu
.addChild(new dijit
.MenuSeparator());
1894 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1895 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1897 labels
.each(function(label
) {
1898 var id
= label
.id
[0];
1899 var bare_id
= id
.substr(id
.indexOf(":")+1);
1900 var name
= label
.name
[0];
1902 bare_id
= feed_to_label_id(bare_id
);
1904 labelAddMenu
.addChild(new dijit
.MenuItem({
1907 onClick: function(event
) {
1908 var ids
= getSelectedArticleIds2();
1910 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1912 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1914 selectionAssignLabel(this.labelId
, ids
);
1917 labelDelMenu
.addChild(new dijit
.MenuItem({
1920 onClick: function(event
) {
1921 var ids
= getSelectedArticleIds2();
1923 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1925 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1927 selectionRemoveLabel(this.labelId
, ids
);
1932 menu
.addChild(new dijit
.PopupMenuItem({
1933 label
: __("Assign label"),
1934 popup
: labelAddMenu
,
1937 menu
.addChild(new dijit
.PopupMenuItem({
1938 label
: __("Remove label"),
1939 popup
: labelDelMenu
,
1947 exception_error("initHeadlinesMenu", e
);
1952 function player(elem
) {
1953 var aid
= elem
.getAttribute("audio-id");
1954 var status
= elem
.getAttribute("status");
1962 elem
.innerHTML
= __("Playing...");
1963 elem
.title
= __("Click to pause");
1964 elem
.addClassName("playing");
1968 elem
.innerHTML
= __("Play");
1969 elem
.title
= __("Click to play");
1970 elem
.removeClassName("playing");
1973 elem
.setAttribute("status", status
);
1975 alert("Your browser doesn't seem to support HTML5 audio.");
1979 function cache_set(id
, obj
) {
1980 //console.log("cache_set: " + id);
1983 sessionStorage
[id
] = obj
;
1985 sessionStorage
.clear();
1989 function cache_get(id
) {
1991 return sessionStorage
[id
];
1994 function cache_clear() {
1996 sessionStorage
.clear();
1999 function cache_delete(id
) {
2001 sessionStorage
.removeItem(id
);
2004 function cancelSearch() {
2009 exception_error("cancelSearch", e
);
2013 function setSelectionScore() {
2015 var ids
= getSelectedArticleIds2();
2017 if (ids
.length
> 0) {
2020 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2022 if (score
!= undefined) {
2023 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2024 "&score=" + param_escape(score
);
2026 new Ajax
.Request("backend.php", {
2028 onComplete: function(transport
) {
2029 var reply
= JSON
.parse(transport
.responseText
);
2033 ids
.each(function(id
) {
2034 var row
= $("RROW-" + id
);
2037 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2040 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2041 reply
["score_pic"]);
2042 pic
.setAttribute("score", score
);
2051 alert(__("No articles are selected."));
2054 exception_error("setSelectionScore", e
);
2058 function changeScore(id
, pic
) {
2060 var score
= pic
.getAttribute("score");
2062 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2064 if (new_score
!= undefined) {
2066 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2067 "&score=" + param_escape(new_score
);
2069 new Ajax
.Request("backend.php", {
2071 onComplete: function(transport
) {
2072 var reply
= JSON
.parse(transport
.responseText
);
2075 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2076 pic
.setAttribute("score", new_score
);
2081 exception_error("changeScore", e
);
2085 function displayArticleUrl(id
) {
2087 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2089 new Ajax
.Request("backend.php", {
2091 onComplete: function(transport
) {
2092 var reply
= JSON
.parse(transport
.responseText
);
2094 if (reply
&& reply
.link
) {
2095 prompt(__("Article URL:"), reply
.link
);
2099 exception_error("changeScore", e
);
2103 function openSelectedAttachment(elem
) {
2105 var url
= elem
[elem
.selectedIndex
].value
;
2109 elem
.selectedIndex
= 0;
2113 exception_error("openSelectedAttachment", e
);