]>
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
= [];
15 var _last_headlines_update
= 0;
17 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
19 function headlines_callback2(transport
, offset
, background
, infscroll_req
) {
21 handle_rpc_json(transport
);
23 loading_set_progress(25);
25 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
+ " I:" + infscroll_req
);
33 reply
= JSON
.parse(transport
.responseText
);
40 is_cat
= reply
['headlines']['is_cat'];
41 feed_id
= reply
['headlines']['id'];
44 var content
= reply
['headlines']['content'];
46 if (getInitParam("cdm_auto_catchup") == 1) {
47 content
= content
+ "<div id='headlines-spacer'></div>";
52 setActiveFeedId(feed_id
, is_cat
);
54 /* dijit.getEnclosingWidget(
55 document.forms["main_toolbar_form"].update).attr('disabled',
56 is_cat || feed_id <= 0); */
59 if (infscroll_req
== false) {
60 $("headlines-frame").scrollTop
= 0;
64 var headlines_count
= reply
['headlines-info']['count'];
66 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
68 if (parseInt(headlines_count
) < 30) {
69 _infscroll_disable
= 1;
71 _infscroll_disable
= 0;
74 var counters
= reply
['counters'];
75 var articles
= reply
['articles'];
76 //var runtime_info = reply['runtime-info'];
78 if (infscroll_req
== false) {
79 loaded_article_ids
= [];
81 dijit
.byId("headlines-frame").attr('content',
82 reply
['headlines']['content']);
84 dijit
.byId("headlines-toolbar").attr('content',
85 reply
['headlines']['toolbar']);
87 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
88 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
89 row
.parentNode
.removeChild(row
);
91 loaded_article_ids
.push(row
.id
);
95 if (getInitParam("cdm_auto_catchup") == 1) {
96 var hsp
= $("headlines-spacer");
97 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
98 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
104 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
105 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
111 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
112 console
.log("adding some more headlines: " + headlines_count
);
114 var c
= dijit
.byId("headlines-frame");
115 var ids
= getSelectedArticleIds2();
118 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
120 var hsp
= $("headlines-spacer");
123 c
.domNode
.removeChild(hsp
);
125 $$("#headlines-tmp > div").each(function(row
) {
126 if (row
.className
== 'cdmFeedTitle') {
127 row
.style
.display
= 'none';
128 c
.domNode
.appendChild(row
);
130 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
131 row
.style
.display
= 'none';
132 c
.domNode
.appendChild(row
);
134 loaded_article_ids
.push(row
.id
);
136 row
.parentNode
.removeChild(row
);
140 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
142 fixHeadlinesOrder(getLoadedArticleIds());
144 if (getInitParam("cdm_auto_catchup") == 1) {
145 c
.domNode
.appendChild(hsp
);
148 console
.log("added " + new_elems
.size() + " headlines");
150 if (new_elems
.size() == 0)
151 _infscroll_disable
= true;
153 console
.log("restore selected ids: " + ids
);
155 for (var i
= 0; i
< ids
.length
; i
++) {
156 markHeadline(ids
[i
]);
161 new_elems
.each(function(child
) {
162 var cb
= dijit
.byId(child
.id
.replace("RROW-", "RCHK-"));
165 dojo
.parser
.parse(child
);
167 if (!Element
.visible(child
))
168 new Effect
.Appear(child
, { duration
: 0.5 });
170 c
.domNode
.removeChild(child
);
175 console
.log("no new headlines received");
177 var hsp
= $("headlines-spacer");
179 if (hsp
) hsp
.innerHTML
= "";
184 for (var i
= 0; i
< articles
.length
; i
++) {
185 var a_id
= articles
[i
]['id'];
186 cache_set("article:" + a_id
, articles
[i
]['content']);
189 console
.log("no cached articles received");
193 parse_counters(counters
);
195 request_counters(true);
197 } else if (transport
.responseText
) {
198 console
.error("Invalid object received: " + transport
.responseText
);
199 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
200 __('Could not update headlines (invalid object received - see error console for details)') +
203 //notify_error("Error communicating with server.");
204 Element
.show(dijit
.byId("net-alert").domNode
);
207 _infscroll_request_sent
= 0;
208 _last_headlines_update
= new Date().getTime();
210 unpackVisibleHeadlines();
215 exception_error("headlines_callback2", e
, transport
);
219 function render_article(article
) {
221 dijit
.byId("headlines-wrap-inner").addChild(
222 dijit
.byId("content-insert"));
224 var c
= dijit
.byId("content-insert");
227 c
.domNode
.scrollTop
= 0;
230 c
.attr('content', article
);
232 correctHeadlinesOffset(getActiveArticleId());
239 exception_error("render_article", e
);
243 function showArticleInHeadlines(id
) {
246 selectArticles("none");
248 var crow
= $("RROW-" + id
);
252 var article_is_unread
= crow
.hasClassName("Unread");
254 crow
.removeClassName("Unread");
255 crow
.addClassName("active");
257 selectArticles('none');
259 var view_mode
= false;
262 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
263 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
270 if (article_is_unread
)
271 _force_scheduled_update
= true;
274 exception_error("showArticleInHeadlines", e
);
278 function article_callback2(transport
, id
) {
280 console
.log("article_callback2 " + id
);
282 handle_rpc_json(transport
);
287 reply
= JSON
.parse(transport
.responseText
);
294 reply
.each(function(article
) {
295 if (getActiveArticleId() == article
['id']) {
296 render_article(article
['content']);
298 cids_requested
.remove(article
['id']);
300 cache_set("article:" + article
['id'], article
['content']);
303 // if (id != last_requested_article) {
304 // console.log("requested article id is out of sequence, aborting");
308 } else if (transport
.responseText
) {
309 console
.error("Invalid object received: " + transport
.responseText
);
311 render_article("<div class='whiteBox'>" +
312 __('Could not display article (invalid object received - see error console for details)') + "</div>");
314 Element
.show(dijit
.byId("net-alert").domNode
);
317 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
318 request_counters(unread_in_buffer
== 0);
320 //headlines_scroll_handler($("headlines-frame"));
323 if (!_infscroll_disable &&
324 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
334 exception_error("article_callback2", e
, transport
);
340 var oldrow
= $("RROW-" + getActiveArticleId());
341 if (oldrow
) oldrow
.removeClassName("active");
343 var crow
= $("RROW-" + id
);
347 console
.log("loading article: " + id
);
349 var cached_article
= cache_get("article:" + id
);
351 console
.log("cache check result: " + (cached_article
!= false));
353 var query
= "?op=article&method=view&id=" + param_escape(id
);
355 var neighbor_ids
= getRelativePostIds(id
);
357 /* only request uncached articles */
359 var cids_to_request
= [];
361 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
362 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
363 if (!cache_get("article:" + neighbor_ids
[i
])) {
364 cids_to_request
.push(neighbor_ids
[i
]);
365 cids_requested
.push(neighbor_ids
[i
]);
369 console
.log("additional ids: " + cids_to_request
.toString());
371 query
= query
+ "&cids=" + cids_to_request
.toString();
373 var article_is_unread
= crow
.hasClassName("Unread");
375 setActiveArticleId(id
);
376 showArticleInHeadlines(id
);
378 if (cached_article
&& article_is_unread
) {
380 query
= query
+ "&mode=prefetch";
382 render_article(cached_article
);
384 } else if (cached_article
) {
386 query
= query
+ "&mode=prefetch_old";
387 render_article(cached_article
);
389 // if we don't need to request any relative ids, we might as well skip
390 // the server roundtrip altogether
391 if (cids_to_request
.length
== 0) {
394 if (!_infscroll_disable &&
395 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
403 //headlines_scroll_handler($("headlines-frame"));
409 last_requested_article
= id
;
413 if (article_is_unread
) {
414 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
417 new Ajax
.Request("backend.php", {
419 onComplete: function(transport
) {
420 article_callback2(transport
, id
);
426 exception_error("view", e
);
430 function toggleMark(id
, client_only
) {
432 var query
= "?op=rpc&id=" + id
+ "&method=mark";
434 var img
= $("FMPIC-" + id
);
438 if (img
.src
.match("mark_unset")) {
439 img
.src
= img
.src
.replace("mark_unset", "mark_set");
440 img
.alt
= __("Unstar article");
441 query
= query
+ "&mark=1";
444 img
.src
= img
.src
.replace("mark_set", "mark_unset");
445 img
.alt
= __("Star article");
446 query
= query
+ "&mark=0";
450 new Ajax
.Request("backend.php", {
452 onComplete: function(transport
) {
453 handle_rpc_json(transport
);
458 exception_error("toggleMark", e
);
462 function togglePub(id
, client_only
, no_effects
, note
) {
464 var query
= "?op=rpc&id=" + id
+ "&method=publ";
466 if (note
!= undefined) {
467 query
= query
+ "¬e=" + param_escape(note
);
469 query
= query
+ "¬e=undefined";
472 var img
= $("FPPIC-" + id
);
476 if (img
.src
.match("pub_unset") || note
!= undefined) {
477 img
.src
= img
.src
.replace("pub_unset", "pub_set");
478 img
.alt
= __("Unpublish article");
479 query
= query
+ "&pub=1";
482 img
.src
= img
.src
.replace("pub_set", "pub_unset");
483 img
.alt
= __("Publish article");
485 query
= query
+ "&pub=0";
489 new Ajax
.Request("backend.php", {
491 onComplete: function(transport
) {
492 handle_rpc_json(transport
);
497 exception_error("togglePub", e
);
501 function moveToPost(mode
, noscroll
) {
505 var rows
= getVisibleArticleIds();
510 if (!$('RROW-' + getActiveArticleId())) {
511 setActiveArticleId(0);
514 if (!getActiveArticleId()) {
516 prev_id
= rows
[rows
.length
-1]
518 for (var i
= 0; i
< rows
.length
; i
++) {
519 if (rows
[i
] == getActiveArticleId()) {
521 // Account for adjacent identical article ids.
522 if (i
> 0) prev_id
= rows
[i
-1];
524 for (var j
= i
+1; j
< rows
.length
; j
++) {
525 if (rows
[j
] != getActiveArticleId()) {
535 if (mode
== "next") {
536 if (next_id
|| getActiveArticleId()) {
539 var article
= $("RROW-" + getActiveArticleId());
540 var ctr
= $("headlines-frame");
542 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
543 ctr
.scrollTop
+ ctr
.offsetHeight
) {
545 scrollArticle(ctr
.offsetHeight
/4);
547 } else if (next_id
) {
548 cdmExpandArticle(next_id
);
549 cdmScrollToArticleId(next_id
, true);
552 } else if (next_id
) {
553 correctHeadlinesOffset(next_id
);
554 view(next_id
, getActiveFeedId());
559 if (mode
== "prev") {
560 if (prev_id
|| getActiveArticleId()) {
563 var article
= $("RROW-" + getActiveArticleId());
564 var prev_article
= $("RROW-" + prev_id
);
565 var ctr
= $("headlines-frame");
567 if (!getInitParam("cdm_expanded")) {
569 if (!noscroll
&& article
.offsetTop
< ctr
.scrollTop
) {
570 scrollArticle(-ctr
.offsetHeight
/4);
572 cdmExpandArticle(prev_id
);
573 cdmScrollToArticleId(prev_id
, true);
577 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
578 scrollArticle(-ctr
.offsetHeight
/3);
579 } else if (!noscroll
&& prev_article
&&
580 prev_article
.offsetTop
< ctr
.scrollTop
) {
581 cdmExpandArticle(prev_id
);
582 scrollArticle(-ctr
.offsetHeight
/4);
583 } else if (prev_id
) {
584 cdmExpandArticle(prev_id
);
585 cdmScrollToArticleId(prev_id
, noscroll
);
589 } else if (prev_id
) {
590 correctHeadlinesOffset(prev_id
);
591 view(prev_id
, getActiveFeedId());
597 exception_error("moveToPost", e
);
601 function toggleSelected(id
, force_on
) {
604 var cb
= dijit
.byId("RCHK-" + id
);
605 var row
= $("RROW-" + id
);
608 if (row
.hasClassName('Selected') && !force_on
) {
609 row
.removeClassName('Selected');
610 if (cb
) cb
.attr("checked", false);
612 row
.addClassName('Selected');
613 if (cb
) cb
.attr("checked", true);
617 exception_error("toggleSelected", e
);
621 function toggleUnread_afh(effect
) {
624 var elem
= effect
.element
;
625 elem
.style
.backgroundColor
= "";
628 exception_error("toggleUnread_afh", e
);
632 function toggleUnread(id
, cmode
, effect
) {
635 var row
= $("RROW-" + id
);
637 if (cmode
== undefined || cmode
== 2) {
638 if (row
.hasClassName("Unread")) {
639 row
.removeClassName("Unread");
642 row
.addClassName("Unread");
645 } else if (cmode
== 0) {
647 row
.removeClassName("Unread");
649 } else if (cmode
== 1) {
650 row
.addClassName("Unread");
653 if (cmode
== undefined) cmode
= 2;
655 var query
= "?op=rpc&method=catchupSelected" +
656 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
658 // notify_progress("Loading, please wait...");
660 new Ajax
.Request("backend.php", {
662 onComplete: function(transport
) {
663 handle_rpc_json(transport
);
669 exception_error("toggleUnread", e
);
673 function selectionRemoveLabel(id
, ids
) {
676 if (!ids
) ids
= getSelectedArticleIds2();
678 if (ids
.length
== 0) {
679 alert(__("No articles are selected."));
683 var query
= "?op=article&method=removeFromLabel&ids=" +
684 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
688 new Ajax
.Request("backend.php", {
690 onComplete: function(transport
) {
691 handle_rpc_json(transport
);
692 show_labels_in_headlines(transport
);
696 exception_error("selectionAssignLabel", e
);
701 function selectionAssignLabel(id
, ids
) {
704 if (!ids
) ids
= getSelectedArticleIds2();
706 if (ids
.length
== 0) {
707 alert(__("No articles are selected."));
711 var query
= "?op=article&method=assignToLabel&ids=" +
712 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
716 new Ajax
.Request("backend.php", {
718 onComplete: function(transport
) {
719 handle_rpc_json(transport
);
720 show_labels_in_headlines(transport
);
724 exception_error("selectionAssignLabel", e
);
729 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
731 var rows
= ids
? ids
: getSelectedArticleIds2();
733 if (rows
.length
== 0 && !no_error
) {
734 alert(__("No articles are selected."));
738 for (var i
= 0; i
< rows
.length
; i
++) {
739 var row
= $("RROW-" + rows
[i
]);
741 if (set_state
== undefined) {
742 if (row
.hasClassName("Unread")) {
743 row
.removeClassName("Unread");
745 row
.addClassName("Unread");
749 if (set_state
== false) {
750 row
.removeClassName("Unread");
753 if (set_state
== true) {
754 row
.addClassName("Unread");
759 if (rows
.length
> 0) {
763 if (set_state
== undefined) {
765 } else if (set_state
== true) {
767 } else if (set_state
== false) {
771 var query
= "?op=rpc&method=catchupSelected" +
772 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
774 notify_progress("Loading, please wait...");
776 new Ajax
.Request("backend.php", {
778 onComplete: function(transport
) {
779 handle_rpc_json(transport
);
780 if (callback
) callback(transport
);
786 exception_error("selectionToggleUnread", e
);
791 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
794 var rows
= ids
? ids
: getSelectedArticleIds2();
796 if (rows
.length
== 0 && !no_error
) {
797 alert(__("No articles are selected."));
801 for (var i
= 0; i
< rows
.length
; i
++) {
802 toggleMark(rows
[i
], true, true);
805 if (rows
.length
> 0) {
807 var query
= "?op=rpc&method=markSelected&ids=" +
808 param_escape(rows
.toString()) + "&cmode=2";
810 new Ajax
.Request("backend.php", {
812 onComplete: function(transport
) {
813 handle_rpc_json(transport
);
814 if (callback
) callback(transport
);
820 exception_error("selectionToggleMarked", e
);
825 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
828 var rows
= ids
? ids
: getSelectedArticleIds2();
830 if (rows
.length
== 0 && !no_error
) {
831 alert(__("No articles are selected."));
835 for (var i
= 0; i
< rows
.length
; i
++) {
836 togglePub(rows
[i
], true, true);
839 if (rows
.length
> 0) {
841 var query
= "?op=rpc&method=publishSelected&ids=" +
842 param_escape(rows
.toString()) + "&cmode=2";
844 new Ajax
.Request("backend.php", {
846 onComplete: function(transport
) {
847 handle_rpc_json(transport
);
853 exception_error("selectionToggleMarked", e
);
857 function getSelectedArticleIds2() {
861 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
863 rv
.push(child
.id
.replace("RROW-", ""));
869 function getLoadedArticleIds() {
872 var children
= $$("#headlines-frame > div[id*=RROW-]");
874 children
.each(function(child
) {
875 rv
.push(child
.id
.replace("RROW-", ""));
882 // mode = all,none,unread,invert,marked,published
883 function selectArticles(mode
) {
886 var children
= $$("#headlines-frame > div[id*=RROW]");
888 children
.each(function(child
) {
889 var id
= child
.id
.replace("RROW-", "");
890 var cb
= dijit
.byId("RCHK-" + id
);
893 child
.addClassName("Selected");
894 if (cb
) cb
.attr("checked", true);
895 } else if (mode
== "unread") {
896 if (child
.hasClassName("Unread")) {
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
== "marked") {
904 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
906 if (img
&& img
.src
.match("mark_set")) {
907 child
.addClassName("Selected");
908 if (cb
) cb
.attr("checked", true);
910 child
.removeClassName("Selected");
911 if (cb
) cb
.attr("checked", false);
913 } else if (mode
== "published") {
914 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
916 if (img
&& img
.src
.match("pub_set")) {
917 child
.addClassName("Selected");
918 if (cb
) cb
.attr("checked", true);
920 child
.removeClassName("Selected");
921 if (cb
) cb
.attr("checked", false);
924 } else if (mode
== "invert") {
925 if (child
.hasClassName("Selected")) {
926 child
.removeClassName("Selected");
927 if (cb
) cb
.attr("checked", false);
929 child
.addClassName("Selected");
930 if (cb
) cb
.attr("checked", true);
934 child
.removeClassName("Selected");
935 if (cb
) cb
.attr("checked", false);
940 exception_error("selectArticles", e
);
944 function deleteSelection() {
948 var rows
= getSelectedArticleIds2();
950 if (rows
.length
== 0) {
951 alert(__("No articles are selected."));
955 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
958 if (getActiveFeedId() != 0) {
959 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
961 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
964 str
= str
.replace("%d", rows
.length
);
965 str
= str
.replace("%s", fn
);
967 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
971 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
975 new Ajax
.Request("backend.php", {
977 onComplete: function(transport
) {
978 handle_rpc_json(transport
);
983 exception_error("deleteSelection", e
);
987 function archiveSelection() {
991 var rows
= getSelectedArticleIds2();
993 if (rows
.length
== 0) {
994 alert(__("No articles are selected."));
998 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1002 if (getActiveFeedId() != 0) {
1003 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1006 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1008 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1013 str
= str
.replace("%d", rows
.length
);
1014 str
= str
.replace("%s", fn
);
1016 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1020 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1024 for (var i
= 0; i
< rows
.length
; i
++) {
1025 cache_delete("article:" + rows
[i
]);
1028 new Ajax
.Request("backend.php", {
1030 onComplete: function(transport
) {
1031 handle_rpc_json(transport
);
1036 exception_error("archiveSelection", e
);
1040 function catchupSelection() {
1044 var rows
= getSelectedArticleIds2();
1046 if (rows
.length
== 0) {
1047 alert(__("No articles are selected."));
1051 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1053 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1055 str
= str
.replace("%d", rows
.length
);
1056 str
= str
.replace("%s", fn
);
1058 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1062 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1065 exception_error("catchupSelection", e
);
1069 function editArticleTags(id
) {
1070 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1072 if (dijit
.byId("editTagsDlg"))
1073 dijit
.byId("editTagsDlg").destroyRecursive();
1075 dialog
= new dijit
.Dialog({
1077 title
: __("Edit article Tags"),
1078 style
: "width: 600px",
1079 execute: function() {
1080 if (this.validate()) {
1081 var query
= dojo
.objectToQuery(this.attr('value'));
1083 notify_progress("Saving article tags...", true);
1085 new Ajax
.Request("backend.php", {
1087 onComplete: function(transport
) {
1092 var data
= JSON
.parse(transport
.responseText
);
1099 var tags
= $("ATSTR-" + id
);
1100 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1102 if (tags
) tags
.innerHTML
= data
.content
;
1103 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1106 exception_error("editArticleTags/inner", e
);
1115 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1116 dojo
.disconnect(tmph
);
1118 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1119 "backend.php?op=article&method=completeTags",
1120 { tokens
: ',', paramName
: "search" });
1127 function cdmScrollToArticleId(id
, force
) {
1129 var ctr
= $("headlines-frame");
1130 var e
= $("RROW-" + id
);
1132 if (!e
|| !ctr
) return;
1134 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1135 e
.offsetTop
< ctr
.scrollTop
) {
1137 // expanded cdm has a 4px margin now
1138 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1142 exception_error("cdmScrollToArticleId", e
);
1146 function setActiveArticleId(id
) {
1147 _active_article_id
= id
;
1150 function getActiveArticleId() {
1151 return _active_article_id
;
1154 function postMouseIn(e
, id
) {
1155 post_under_pointer
= id
;
1158 function postMouseOut(id
) {
1159 post_under_pointer
= false;
1162 function unpackVisibleHeadlines() {
1164 if (!isCdmMode()) return;
1166 $$("#headlines-frame > div[id*=RROW]").each(
1168 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1169 $("headlines-frame").offsetHeight
) {
1171 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1174 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1175 cencw
.setAttribute('id', '');
1176 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 // let's get DOM some time to settle down
1213 var ts
= new Date().getTime();
1214 if (ts
- _last_headlines_update
< 100) return;
1216 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1218 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1219 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1221 var id
= child
.id
.replace("RROW-", "");
1223 if (catchup_id_batch
.indexOf(id
) == -1)
1224 catchup_id_batch
.push(id
);
1226 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1230 if (catchup_id_batch
.length
> 0) {
1231 window
.clearTimeout(catchup_timeout_id
);
1233 if (!_infscroll_request_sent
) {
1234 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1241 console
.warn("headlines_scroll_handler: " + e
);
1245 function catchupBatchedArticles() {
1247 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1249 // make a copy of the array
1250 var batch
= catchup_id_batch
.slice();
1251 var query
= "?op=rpc&method=catchupSelected" +
1252 "&cmode=0&ids=" + param_escape(batch
.toString());
1256 new Ajax
.Request("backend.php", {
1258 onComplete: function(transport
) {
1259 handle_rpc_json(transport
);
1261 reply
= JSON
.parse(transport
.responseText
);
1262 var batch
= reply
.ids
;
1264 batch
.each(function(id
) {
1266 var elem
= $("RROW-" + id
);
1267 if (elem
) elem
.removeClassName("Unread");
1268 catchup_id_batch
.remove(id
);
1275 exception_error("catchupBatchedArticles", e
);
1279 function catchupRelativeToArticle(below
, id
) {
1283 if (!id
) id
= getActiveArticleId();
1286 alert(__("No article is selected."));
1290 var visible_ids
= getVisibleArticleIds();
1292 var ids_to_mark
= new Array();
1295 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1296 if (visible_ids
[i
] != id
) {
1297 var e
= $("RROW-" + visible_ids
[i
]);
1299 if (e
&& e
.hasClassName("Unread")) {
1300 ids_to_mark
.push(visible_ids
[i
]);
1307 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1308 if (visible_ids
[i
] != id
) {
1309 var e
= $("RROW-" + visible_ids
[i
]);
1311 if (e
&& e
.hasClassName("Unread")) {
1312 ids_to_mark
.push(visible_ids
[i
]);
1320 if (ids_to_mark
.length
== 0) {
1321 alert(__("No articles found to mark"));
1323 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1325 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1327 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1328 var e
= $("RROW-" + ids_to_mark
[i
]);
1329 e
.removeClassName("Unread");
1332 var query
= "?op=rpc&method=catchupSelected" +
1333 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1335 new Ajax
.Request("backend.php", {
1337 onComplete: function(transport
) {
1338 handle_rpc_json(transport
);
1345 exception_error("catchupRelativeToArticle", e
);
1349 function cdmCollapseArticle(event
, id
) {
1351 var row
= $("RROW-" + id
);
1352 var elem
= $("CICD-" + id
);
1355 var collapse
= $$("div#RROW-" + id
+
1356 " span[class='collapseBtn']")[0];
1359 Element
.show("CEXC-" + id
);
1360 Element
.hide(collapse
);
1361 row
.removeClassName("active");
1363 markHeadline(id
, false);
1365 if (id
== getActiveArticleId()) {
1366 setActiveArticleId(0);
1369 if (event
) Event
.stop(event
);
1373 exception_error("cdmCollapseArticle", e
);
1377 function cdmExpandArticle(id
) {
1379 console
.log("cdmExpandArticle " + id
);
1381 if (!$("RROW-" + id
)) return false;
1383 var oldrow
= $("RROW-" + getActiveArticleId());
1385 var elem
= $("CICD-" + getActiveArticleId());
1387 if (id
== getActiveArticleId() && Element
.visible(elem
))
1390 selectArticles("none");
1392 var old_offset
= $("RROW-" + id
).offsetTop
;
1394 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1395 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1396 " span[class='collapseBtn']")[0];
1399 Element
.show("CEXC-" + getActiveArticleId());
1400 Element
.hide(collapse
);
1403 if (oldrow
) oldrow
.removeClassName("active");
1405 setActiveArticleId(id
);
1407 elem
= $("CICD-" + id
);
1409 var collapse
= $$("div#RROW-" + id
+
1410 " span[class='collapseBtn']")[0];
1412 var cencw
= $("CENCW-" + id
);
1414 if (!Element
.visible(elem
)) {
1416 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1417 cencw
.setAttribute('id', '');
1418 Element
.show(cencw
);
1422 Element
.hide("CEXC-" + id
);
1423 Element
.show(collapse
);
1426 var new_offset
= $("RROW-" + id
).offsetTop
;
1428 if (old_offset
> new_offset
)
1429 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1431 toggleUnread(id
, 0, true);
1433 $("RROW-" + id
).addClassName("active");
1436 exception_error("cdmExpandArticle", e
);
1442 function fixHeadlinesOrder(ids
) {
1444 for (var i
= 0; i
< ids
.length
; i
++) {
1445 var e
= $("RROW-" + ids
[i
]);
1449 e
.removeClassName("even");
1450 e
.addClassName("odd");
1452 e
.removeClassName("odd");
1453 e
.addClassName("even");
1458 exception_error("fixHeadlinesOrder", e
);
1462 function getArticleUnderPointer() {
1463 return post_under_pointer
;
1466 function scrollArticle(offset
) {
1469 var ci
= $("content-insert");
1471 ci
.scrollTop
+= offset
;
1474 var hi
= $("headlines-frame");
1476 hi
.scrollTop
+= offset
;
1481 exception_error("scrollArticle", e
);
1485 function show_labels_in_headlines(transport
) {
1487 var data
= JSON
.parse(transport
.responseText
);
1490 data
['info-for-headlines'].each(function(elem
) {
1491 var ctr
= $("HLLCTR-" + elem
.id
);
1493 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1497 exception_error("show_labels_in_headlines", e
);
1501 function dismissArticle(id
) {
1503 var elem
= $("RROW-" + id
);
1507 toggleUnread(id
, 0, true);
1509 new Effect
.Fade(elem
, {duration
: 0.5});
1511 if (id
== getActiveArticleId()) {
1512 setActiveArticleId(0);
1516 exception_error("dismissArticle", e
);
1520 function dismissSelectedArticles() {
1523 var ids
= getVisibleArticleIds();
1527 for (var i
= 0; i
< ids
.length
; i
++) {
1528 var elem
= $("RROW-" + ids
[i
]);
1530 if (elem
.className
&& elem
.hasClassName("Selected") &&
1531 ids
[i
] != getActiveArticleId()) {
1532 new Effect
.Fade(elem
, {duration
: 0.5});
1540 selectionToggleUnread(false);
1542 fixHeadlinesOrder(tmp
);
1545 exception_error("dismissSelectedArticles", e
);
1549 function dismissReadArticles() {
1552 var ids
= getVisibleArticleIds();
1555 for (var i
= 0; i
< ids
.length
; i
++) {
1556 var elem
= $("RROW-" + ids
[i
]);
1558 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1559 !elem
.hasClassName("Selected")) {
1561 new Effect
.Fade(elem
, {duration
: 0.5});
1567 fixHeadlinesOrder(tmp
);
1570 exception_error("dismissSelectedArticles", e
);
1574 function getVisibleArticleIds() {
1579 getLoadedArticleIds().each(function(id
) {
1580 var elem
= $("RROW-" + id
);
1581 if (elem
&& Element
.visible(elem
))
1586 exception_error("getVisibleArticleIds", e
);
1592 function cdmClicked(event
, id
) {
1594 //var shift_key = event.shiftKey;
1596 if (!event
.ctrlKey
) {
1598 if (!getInitParam("cdm_expanded")) {
1599 return cdmExpandArticle(id
);
1602 var elem
= $("RROW-" + getActiveArticleId());
1604 if (elem
) elem
.removeClassName("active");
1606 selectArticles("none");
1609 var elem
= $("RROW-" + id
);
1610 var article_is_unread
= elem
.hasClassName("Unread");
1612 elem
.removeClassName("Unread");
1613 elem
.addClassName("active");
1615 setActiveArticleId(id
);
1617 if (article_is_unread
) {
1618 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1621 var query
= "?op=rpc&method=catchupSelected" +
1622 "&cmode=0&ids=" + param_escape(id
);
1624 new Ajax
.Request("backend.php", {
1626 onComplete: function(transport
) {
1627 handle_rpc_json(transport
);
1630 return !event
.shiftKey
;
1634 toggleSelected(id
, true);
1636 var elem
= $("RROW-" + id
);
1637 var article_is_unread
= elem
.hasClassName("Unread");
1639 if (article_is_unread
) {
1640 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1643 toggleUnread(id
, 0, false);
1645 openArticleInNewWindow(id
);
1648 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1649 request_counters(unread_in_buffer
== 0);
1652 exception_error("cdmClicked");
1658 function hlClicked(event
, id
) {
1660 if (event
.which
== 2) {
1663 } else if (event
.ctrlKey
) {
1664 toggleSelected(id
, true);
1665 toggleUnread(id
, 0, false);
1666 openArticleInNewWindow(id
);
1674 exception_error("hlClicked");
1678 function getFirstVisibleHeadlineId() {
1679 var rows
= getVisibleArticleIds();
1684 function getLastVisibleHeadlineId() {
1685 var rows
= getVisibleArticleIds();
1686 return rows
[rows
.length
-1];
1689 function openArticleInNewWindow(id
) {
1690 toggleUnread(id
, 0, false);
1691 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1694 function isCdmMode() {
1695 return getInitParam("combined_display_mode");
1698 function markHeadline(id
, marked
) {
1699 if (marked
== undefined) marked
= true;
1701 var row
= $("RROW-" + id
);
1703 var check
= dijit
.byId("RCHK-" + id
);
1706 check
.attr("checked", marked
);
1710 row
.addClassName("Selected");
1712 row
.removeClassName("Selected");
1716 function getRelativePostIds(id
, limit
) {
1722 if (!limit
) limit
= 6; //3
1724 var ids
= getVisibleArticleIds();
1726 for (var i
= 0; i
< ids
.length
; i
++) {
1728 for (var k
= 1; k
<= limit
; k
++) {
1729 //if (i > k-1) tmp.push(ids[i-k]);
1730 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1737 exception_error("getRelativePostIds", e
);
1743 function correctHeadlinesOffset(id
) {
1747 var container
= $("headlines-frame");
1748 var row
= $("RROW-" + id
);
1750 if (!container
|| !row
) return;
1752 var viewport
= container
.offsetHeight
;
1754 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1755 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1757 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1758 //console.log("Vport: " + viewport);
1760 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1761 container
.scrollTop
= row
.offsetTop
;
1762 } else if (rel_offset_bottom
> viewport
) {
1764 /* doesn't properly work with Opera in some cases because
1765 Opera fucks up element scrolling */
1767 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1771 exception_error("correctHeadlinesOffset", e
);
1776 function headlineActionsChange(elem
) {
1779 elem
.attr('value', 'false');
1781 exception_error("headlineActionsChange", e
);
1785 function closeArticlePanel() {
1787 if (dijit
.byId("content-insert"))
1788 dijit
.byId("headlines-wrap-inner").removeChild(
1789 dijit
.byId("content-insert"));
1792 function initHeadlinesMenu() {
1794 if (dijit
.byId("headlinesMenu"))
1795 dijit
.byId("headlinesMenu").destroyRecursive();
1800 nodes
= $$("#headlines-frame > div[id*=RROW]");
1802 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1805 nodes
.each(function(node
) {
1809 var menu
= new dijit
.Menu({
1810 id
: "headlinesMenu",
1814 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1815 var callerNode
= event
.target
, match
= null, tries
= 0;
1817 while (match
== null && callerNode
&& tries
<= 3) {
1818 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1819 callerNode
= callerNode
.parentNode
;
1823 if (match
) this.callerRowId
= parseInt(match
[1]);
1827 /* if (!isCdmMode())
1828 menu.addChild(new dijit.MenuItem({
1829 label: __("View article"),
1830 onClick: function(event) {
1831 view(this.getParent().callerRowId);
1834 menu
.addChild(new dijit
.MenuItem({
1835 label
: __("Open original article"),
1836 onClick: function(event
) {
1837 openArticleInNewWindow(this.getParent().callerRowId
);
1840 menu
.addChild(new dijit
.MenuItem({
1841 label
: __("Display article URL"),
1842 onClick: function(event
) {
1843 displayArticleUrl(this.getParent().callerRowId
);
1846 menu
.addChild(new dijit
.MenuSeparator());
1848 menu
.addChild(new dijit
.MenuItem({
1849 label
: __("Toggle unread"),
1850 onClick: function(event
) {
1851 var ids
= getSelectedArticleIds2();
1853 var id
= this.getParent().callerRowId
+ "";
1854 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1856 selectionToggleUnread(undefined, false, true, ids
);
1859 menu
.addChild(new dijit
.MenuItem({
1860 label
: __("Toggle marked"),
1861 onClick: function(event
) {
1862 var ids
= getSelectedArticleIds2();
1864 var id
= this.getParent().callerRowId
+ "";
1865 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1867 selectionToggleMarked(undefined, false, true, ids
);
1870 menu
.addChild(new dijit
.MenuItem({
1871 label
: __("Toggle published"),
1872 onClick: function(event
) {
1873 var ids
= getSelectedArticleIds2();
1875 var id
= this.getParent().callerRowId
+ "";
1876 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1878 selectionTogglePublished(undefined, false, true, ids
);
1881 menu
.addChild(new dijit
.MenuSeparator());
1883 menu
.addChild(new dijit
.MenuItem({
1884 label
: __("Mark above as read"),
1885 onClick: function(event
) {
1886 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1889 menu
.addChild(new dijit
.MenuItem({
1890 label
: __("Mark below as read"),
1891 onClick: function(event
) {
1892 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1896 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1900 menu
.addChild(new dijit
.MenuSeparator());
1902 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1903 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1905 labels
.each(function(label
) {
1906 var id
= label
.id
[0];
1907 var bare_id
= id
.substr(id
.indexOf(":")+1);
1908 var name
= label
.name
[0];
1910 bare_id
= feed_to_label_id(bare_id
);
1912 labelAddMenu
.addChild(new dijit
.MenuItem({
1915 onClick: function(event
) {
1916 var ids
= getSelectedArticleIds2();
1918 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1920 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1922 selectionAssignLabel(this.labelId
, ids
);
1925 labelDelMenu
.addChild(new dijit
.MenuItem({
1928 onClick: function(event
) {
1929 var ids
= getSelectedArticleIds2();
1931 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1933 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1935 selectionRemoveLabel(this.labelId
, ids
);
1940 menu
.addChild(new dijit
.PopupMenuItem({
1941 label
: __("Assign label"),
1942 popup
: labelAddMenu
,
1945 menu
.addChild(new dijit
.PopupMenuItem({
1946 label
: __("Remove label"),
1947 popup
: labelDelMenu
,
1955 exception_error("initHeadlinesMenu", e
);
1960 function player(elem
) {
1961 var aid
= elem
.getAttribute("audio-id");
1962 var status
= elem
.getAttribute("status");
1970 elem
.innerHTML
= __("Playing...");
1971 elem
.title
= __("Click to pause");
1972 elem
.addClassName("playing");
1976 elem
.innerHTML
= __("Play");
1977 elem
.title
= __("Click to play");
1978 elem
.removeClassName("playing");
1981 elem
.setAttribute("status", status
);
1983 alert("Your browser doesn't seem to support HTML5 audio.");
1987 function cache_set(id
, obj
) {
1988 //console.log("cache_set: " + id);
1991 sessionStorage
[id
] = obj
;
1993 sessionStorage
.clear();
1997 function cache_get(id
) {
1999 return sessionStorage
[id
];
2002 function cache_clear() {
2004 sessionStorage
.clear();
2007 function cache_delete(id
) {
2009 sessionStorage
.removeItem(id
);
2012 function cancelSearch() {
2017 exception_error("cancelSearch", e
);
2021 function setSelectionScore() {
2023 var ids
= getSelectedArticleIds2();
2025 if (ids
.length
> 0) {
2028 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2030 if (score
!= undefined) {
2031 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2032 "&score=" + param_escape(score
);
2034 new Ajax
.Request("backend.php", {
2036 onComplete: function(transport
) {
2037 var reply
= JSON
.parse(transport
.responseText
);
2041 ids
.each(function(id
) {
2042 var row
= $("RROW-" + id
);
2045 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2048 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2049 reply
["score_pic"]);
2050 pic
.setAttribute("score", score
);
2059 alert(__("No articles are selected."));
2062 exception_error("setSelectionScore", e
);
2066 function changeScore(id
, pic
) {
2068 var score
= pic
.getAttribute("score");
2070 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2072 if (new_score
!= undefined) {
2074 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2075 "&score=" + param_escape(new_score
);
2077 new Ajax
.Request("backend.php", {
2079 onComplete: function(transport
) {
2080 var reply
= JSON
.parse(transport
.responseText
);
2083 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2084 pic
.setAttribute("score", new_score
);
2089 exception_error("changeScore", e
);
2093 function displayArticleUrl(id
) {
2095 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2097 new Ajax
.Request("backend.php", {
2099 onComplete: function(transport
) {
2100 var reply
= JSON
.parse(transport
.responseText
);
2102 if (reply
&& reply
.link
) {
2103 prompt(__("Article URL:"), reply
.link
);
2107 exception_error("changeScore", e
);
2111 function openSelectedAttachment(elem
) {
2113 var url
= elem
[elem
.selectedIndex
].value
;
2117 elem
.selectedIndex
= 0;
2121 exception_error("openSelectedAttachment", e
);