]>
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() / 1000;
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() / 1000;
1215 if (ts
- _last_headlines_update
< 3) return;
1217 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1219 if (child
.hasClassName("Unread") && $("headlines-frame").scrollTop
>
1220 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1222 var id
= child
.id
.replace("RROW-", "");
1224 if (catchup_id_batch
.indexOf(id
) == -1)
1225 catchup_id_batch
.push(id
);
1227 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1231 if (catchup_id_batch
.length
> 0) {
1232 window
.clearTimeout(catchup_timeout_id
);
1234 if (!_infscroll_request_sent
) {
1235 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1242 console
.warn("headlines_scroll_handler: " + e
);
1246 function catchupBatchedArticles() {
1248 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1250 // make a copy of the array
1251 var batch
= catchup_id_batch
.slice();
1252 var query
= "?op=rpc&method=catchupSelected" +
1253 "&cmode=0&ids=" + param_escape(batch
.toString());
1257 new Ajax
.Request("backend.php", {
1259 onComplete: function(transport
) {
1260 handle_rpc_json(transport
);
1262 batch
.each(function(id
) {
1263 var elem
= $("RROW-" + id
);
1264 if (elem
) elem
.removeClassName("Unread");
1265 catchup_id_batch
.remove(id
);
1272 exception_error("catchupBatchedArticles", e
);
1276 function catchupRelativeToArticle(below
, id
) {
1280 if (!id
) id
= getActiveArticleId();
1283 alert(__("No article is selected."));
1287 var visible_ids
= getVisibleArticleIds();
1289 var ids_to_mark
= new Array();
1292 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1293 if (visible_ids
[i
] != id
) {
1294 var e
= $("RROW-" + visible_ids
[i
]);
1296 if (e
&& e
.hasClassName("Unread")) {
1297 ids_to_mark
.push(visible_ids
[i
]);
1304 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1305 if (visible_ids
[i
] != id
) {
1306 var e
= $("RROW-" + visible_ids
[i
]);
1308 if (e
&& e
.hasClassName("Unread")) {
1309 ids_to_mark
.push(visible_ids
[i
]);
1317 if (ids_to_mark
.length
== 0) {
1318 alert(__("No articles found to mark"));
1320 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1322 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1324 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1325 var e
= $("RROW-" + ids_to_mark
[i
]);
1326 e
.removeClassName("Unread");
1329 var query
= "?op=rpc&method=catchupSelected" +
1330 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1332 new Ajax
.Request("backend.php", {
1334 onComplete: function(transport
) {
1335 handle_rpc_json(transport
);
1342 exception_error("catchupRelativeToArticle", e
);
1346 function cdmCollapseArticle(event
, id
) {
1348 var row
= $("RROW-" + id
);
1349 var elem
= $("CICD-" + id
);
1352 var collapse
= $$("div#RROW-" + id
+
1353 " span[class='collapseBtn']")[0];
1356 Element
.show("CEXC-" + id
);
1357 Element
.hide(collapse
);
1358 row
.removeClassName("active");
1360 markHeadline(id
, false);
1362 if (id
== getActiveArticleId()) {
1363 setActiveArticleId(0);
1366 if (event
) Event
.stop(event
);
1370 exception_error("cdmCollapseArticle", e
);
1374 function cdmExpandArticle(id
) {
1376 console
.log("cdmExpandArticle " + id
);
1378 if (!$("RROW-" + id
)) return false;
1380 var oldrow
= $("RROW-" + getActiveArticleId());
1382 var elem
= $("CICD-" + getActiveArticleId());
1384 if (id
== getActiveArticleId() && Element
.visible(elem
))
1387 selectArticles("none");
1389 var old_offset
= $("RROW-" + id
).offsetTop
;
1391 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1392 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1393 " span[class='collapseBtn']")[0];
1396 Element
.show("CEXC-" + getActiveArticleId());
1397 Element
.hide(collapse
);
1400 if (oldrow
) oldrow
.removeClassName("active");
1402 setActiveArticleId(id
);
1404 elem
= $("CICD-" + id
);
1406 var collapse
= $$("div#RROW-" + id
+
1407 " span[class='collapseBtn']")[0];
1409 var cencw
= $("CENCW-" + id
);
1411 if (!Element
.visible(elem
)) {
1413 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1414 cencw
.setAttribute('id', '');
1415 Element
.show(cencw
);
1419 Element
.hide("CEXC-" + id
);
1420 Element
.show(collapse
);
1423 var new_offset
= $("RROW-" + id
).offsetTop
;
1425 if (old_offset
> new_offset
)
1426 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1428 toggleUnread(id
, 0, true);
1430 $("RROW-" + id
).addClassName("active");
1433 exception_error("cdmExpandArticle", e
);
1439 function fixHeadlinesOrder(ids
) {
1441 for (var i
= 0; i
< ids
.length
; i
++) {
1442 var e
= $("RROW-" + ids
[i
]);
1446 e
.removeClassName("even");
1447 e
.addClassName("odd");
1449 e
.removeClassName("odd");
1450 e
.addClassName("even");
1455 exception_error("fixHeadlinesOrder", e
);
1459 function getArticleUnderPointer() {
1460 return post_under_pointer
;
1463 function scrollArticle(offset
) {
1466 var ci
= $("content-insert");
1468 ci
.scrollTop
+= offset
;
1471 var hi
= $("headlines-frame");
1473 hi
.scrollTop
+= offset
;
1478 exception_error("scrollArticle", e
);
1482 function show_labels_in_headlines(transport
) {
1484 var data
= JSON
.parse(transport
.responseText
);
1487 data
['info-for-headlines'].each(function(elem
) {
1488 var ctr
= $("HLLCTR-" + elem
.id
);
1490 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1494 exception_error("show_labels_in_headlines", e
);
1498 function dismissArticle(id
) {
1500 var elem
= $("RROW-" + id
);
1504 toggleUnread(id
, 0, true);
1506 new Effect
.Fade(elem
, {duration
: 0.5});
1508 if (id
== getActiveArticleId()) {
1509 setActiveArticleId(0);
1513 exception_error("dismissArticle", e
);
1517 function dismissSelectedArticles() {
1520 var ids
= getVisibleArticleIds();
1524 for (var i
= 0; i
< ids
.length
; i
++) {
1525 var elem
= $("RROW-" + ids
[i
]);
1527 if (elem
.className
&& elem
.hasClassName("Selected") &&
1528 ids
[i
] != getActiveArticleId()) {
1529 new Effect
.Fade(elem
, {duration
: 0.5});
1537 selectionToggleUnread(false);
1539 fixHeadlinesOrder(tmp
);
1542 exception_error("dismissSelectedArticles", e
);
1546 function dismissReadArticles() {
1549 var ids
= getVisibleArticleIds();
1552 for (var i
= 0; i
< ids
.length
; i
++) {
1553 var elem
= $("RROW-" + ids
[i
]);
1555 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1556 !elem
.hasClassName("Selected")) {
1558 new Effect
.Fade(elem
, {duration
: 0.5});
1564 fixHeadlinesOrder(tmp
);
1567 exception_error("dismissSelectedArticles", e
);
1571 function getVisibleArticleIds() {
1576 getLoadedArticleIds().each(function(id
) {
1577 var elem
= $("RROW-" + id
);
1578 if (elem
&& Element
.visible(elem
))
1583 exception_error("getVisibleArticleIds", e
);
1589 function cdmClicked(event
, id
) {
1591 //var shift_key = event.shiftKey;
1593 if (!event
.ctrlKey
) {
1595 if (!getInitParam("cdm_expanded")) {
1596 return cdmExpandArticle(id
);
1599 var elem
= $("RROW-" + getActiveArticleId());
1601 if (elem
) elem
.removeClassName("active");
1603 selectArticles("none");
1606 var elem
= $("RROW-" + id
);
1607 var article_is_unread
= elem
.hasClassName("Unread");
1609 elem
.removeClassName("Unread");
1610 elem
.addClassName("active");
1612 setActiveArticleId(id
);
1614 if (article_is_unread
) {
1615 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1618 var query
= "?op=rpc&method=catchupSelected" +
1619 "&cmode=0&ids=" + param_escape(id
);
1621 new Ajax
.Request("backend.php", {
1623 onComplete: function(transport
) {
1624 handle_rpc_json(transport
);
1627 return !event
.shiftKey
;
1631 toggleSelected(id
, true);
1633 var elem
= $("RROW-" + id
);
1634 var article_is_unread
= elem
.hasClassName("Unread");
1636 if (article_is_unread
) {
1637 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1640 toggleUnread(id
, 0, false);
1642 openArticleInNewWindow(id
);
1645 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1646 request_counters(unread_in_buffer
== 0);
1649 exception_error("cdmClicked");
1655 function hlClicked(event
, id
) {
1657 if (event
.which
== 2) {
1660 } else if (event
.ctrlKey
) {
1661 toggleSelected(id
, true);
1662 toggleUnread(id
, 0, false);
1663 openArticleInNewWindow(id
);
1671 exception_error("hlClicked");
1675 function getFirstVisibleHeadlineId() {
1676 var rows
= getVisibleArticleIds();
1681 function getLastVisibleHeadlineId() {
1682 var rows
= getVisibleArticleIds();
1683 return rows
[rows
.length
-1];
1686 function openArticleInNewWindow(id
) {
1687 toggleUnread(id
, 0, false);
1688 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1691 function isCdmMode() {
1692 return getInitParam("combined_display_mode");
1695 function markHeadline(id
, marked
) {
1696 if (marked
== undefined) marked
= true;
1698 var row
= $("RROW-" + id
);
1700 var check
= dijit
.byId("RCHK-" + id
);
1703 check
.attr("checked", marked
);
1707 row
.addClassName("Selected");
1709 row
.removeClassName("Selected");
1713 function getRelativePostIds(id
, limit
) {
1719 if (!limit
) limit
= 6; //3
1721 var ids
= getVisibleArticleIds();
1723 for (var i
= 0; i
< ids
.length
; i
++) {
1725 for (var k
= 1; k
<= limit
; k
++) {
1726 //if (i > k-1) tmp.push(ids[i-k]);
1727 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1734 exception_error("getRelativePostIds", e
);
1740 function correctHeadlinesOffset(id
) {
1744 var container
= $("headlines-frame");
1745 var row
= $("RROW-" + id
);
1747 if (!container
|| !row
) return;
1749 var viewport
= container
.offsetHeight
;
1751 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1752 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1754 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1755 //console.log("Vport: " + viewport);
1757 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1758 container
.scrollTop
= row
.offsetTop
;
1759 } else if (rel_offset_bottom
> viewport
) {
1761 /* doesn't properly work with Opera in some cases because
1762 Opera fucks up element scrolling */
1764 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1768 exception_error("correctHeadlinesOffset", e
);
1773 function headlineActionsChange(elem
) {
1776 elem
.attr('value', 'false');
1778 exception_error("headlineActionsChange", e
);
1782 function closeArticlePanel() {
1784 if (dijit
.byId("content-insert"))
1785 dijit
.byId("headlines-wrap-inner").removeChild(
1786 dijit
.byId("content-insert"));
1789 function initHeadlinesMenu() {
1791 if (dijit
.byId("headlinesMenu"))
1792 dijit
.byId("headlinesMenu").destroyRecursive();
1797 nodes
= $$("#headlines-frame > div[id*=RROW]");
1799 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1802 nodes
.each(function(node
) {
1806 var menu
= new dijit
.Menu({
1807 id
: "headlinesMenu",
1811 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1812 var callerNode
= event
.target
, match
= null, tries
= 0;
1814 while (match
== null && callerNode
&& tries
<= 3) {
1815 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1816 callerNode
= callerNode
.parentNode
;
1820 if (match
) this.callerRowId
= parseInt(match
[1]);
1824 /* if (!isCdmMode())
1825 menu.addChild(new dijit.MenuItem({
1826 label: __("View article"),
1827 onClick: function(event) {
1828 view(this.getParent().callerRowId);
1831 menu
.addChild(new dijit
.MenuItem({
1832 label
: __("Open original article"),
1833 onClick: function(event
) {
1834 openArticleInNewWindow(this.getParent().callerRowId
);
1837 menu
.addChild(new dijit
.MenuItem({
1838 label
: __("Display article URL"),
1839 onClick: function(event
) {
1840 displayArticleUrl(this.getParent().callerRowId
);
1843 menu
.addChild(new dijit
.MenuSeparator());
1845 menu
.addChild(new dijit
.MenuItem({
1846 label
: __("Toggle unread"),
1847 onClick: function(event
) {
1848 var ids
= getSelectedArticleIds2();
1850 var id
= this.getParent().callerRowId
+ "";
1851 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1853 selectionToggleUnread(undefined, false, true, ids
);
1856 menu
.addChild(new dijit
.MenuItem({
1857 label
: __("Toggle marked"),
1858 onClick: function(event
) {
1859 var ids
= getSelectedArticleIds2();
1861 var id
= this.getParent().callerRowId
+ "";
1862 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1864 selectionToggleMarked(undefined, false, true, ids
);
1867 menu
.addChild(new dijit
.MenuItem({
1868 label
: __("Toggle published"),
1869 onClick: function(event
) {
1870 var ids
= getSelectedArticleIds2();
1872 var id
= this.getParent().callerRowId
+ "";
1873 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1875 selectionTogglePublished(undefined, false, true, ids
);
1878 menu
.addChild(new dijit
.MenuSeparator());
1880 menu
.addChild(new dijit
.MenuItem({
1881 label
: __("Mark above as read"),
1882 onClick: function(event
) {
1883 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1886 menu
.addChild(new dijit
.MenuItem({
1887 label
: __("Mark below as read"),
1888 onClick: function(event
) {
1889 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1893 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1897 menu
.addChild(new dijit
.MenuSeparator());
1899 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1900 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1902 labels
.each(function(label
) {
1903 var id
= label
.id
[0];
1904 var bare_id
= id
.substr(id
.indexOf(":")+1);
1905 var name
= label
.name
[0];
1907 bare_id
= feed_to_label_id(bare_id
);
1909 labelAddMenu
.addChild(new dijit
.MenuItem({
1912 onClick: function(event
) {
1913 var ids
= getSelectedArticleIds2();
1915 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1917 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1919 selectionAssignLabel(this.labelId
, ids
);
1922 labelDelMenu
.addChild(new dijit
.MenuItem({
1925 onClick: function(event
) {
1926 var ids
= getSelectedArticleIds2();
1928 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1930 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1932 selectionRemoveLabel(this.labelId
, ids
);
1937 menu
.addChild(new dijit
.PopupMenuItem({
1938 label
: __("Assign label"),
1939 popup
: labelAddMenu
,
1942 menu
.addChild(new dijit
.PopupMenuItem({
1943 label
: __("Remove label"),
1944 popup
: labelDelMenu
,
1952 exception_error("initHeadlinesMenu", e
);
1957 function player(elem
) {
1958 var aid
= elem
.getAttribute("audio-id");
1959 var status
= elem
.getAttribute("status");
1967 elem
.innerHTML
= __("Playing...");
1968 elem
.title
= __("Click to pause");
1969 elem
.addClassName("playing");
1973 elem
.innerHTML
= __("Play");
1974 elem
.title
= __("Click to play");
1975 elem
.removeClassName("playing");
1978 elem
.setAttribute("status", status
);
1980 alert("Your browser doesn't seem to support HTML5 audio.");
1984 function cache_set(id
, obj
) {
1985 //console.log("cache_set: " + id);
1988 sessionStorage
[id
] = obj
;
1990 sessionStorage
.clear();
1994 function cache_get(id
) {
1996 return sessionStorage
[id
];
1999 function cache_clear() {
2001 sessionStorage
.clear();
2004 function cache_delete(id
) {
2006 sessionStorage
.removeItem(id
);
2009 function cancelSearch() {
2014 exception_error("cancelSearch", e
);
2018 function setSelectionScore() {
2020 var ids
= getSelectedArticleIds2();
2022 if (ids
.length
> 0) {
2025 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2027 if (score
!= undefined) {
2028 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2029 "&score=" + param_escape(score
);
2031 new Ajax
.Request("backend.php", {
2033 onComplete: function(transport
) {
2034 var reply
= JSON
.parse(transport
.responseText
);
2038 ids
.each(function(id
) {
2039 var row
= $("RROW-" + id
);
2042 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2045 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2046 reply
["score_pic"]);
2047 pic
.setAttribute("score", score
);
2056 alert(__("No articles are selected."));
2059 exception_error("setSelectionScore", e
);
2063 function changeScore(id
, pic
) {
2065 var score
= pic
.getAttribute("score");
2067 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2069 if (new_score
!= undefined) {
2071 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2072 "&score=" + param_escape(new_score
);
2074 new Ajax
.Request("backend.php", {
2076 onComplete: function(transport
) {
2077 var reply
= JSON
.parse(transport
.responseText
);
2080 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2081 pic
.setAttribute("score", new_score
);
2086 exception_error("changeScore", e
);
2090 function displayArticleUrl(id
) {
2092 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2094 new Ajax
.Request("backend.php", {
2096 onComplete: function(transport
) {
2097 var reply
= JSON
.parse(transport
.responseText
);
2099 if (reply
&& reply
.link
) {
2100 prompt(__("Article URL:"), reply
.link
);
2104 exception_error("changeScore", e
);
2108 function openSelectedAttachment(elem
) {
2110 var url
= elem
[elem
.selectedIndex
].value
;
2114 elem
.selectedIndex
= 0;
2118 exception_error("openSelectedAttachment", e
);