]>
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 if (feed_id
!= getActiveFeedId() || is_cat
!= activeFeedIsCat())
55 /* dijit.getEnclosingWidget(
56 document.forms["main_toolbar_form"].update).attr('disabled',
57 is_cat || feed_id <= 0); */
60 if (infscroll_req
== false) {
61 $("headlines-frame").scrollTop
= 0;
65 var headlines_count
= reply
['headlines-info']['count'];
67 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
69 if (parseInt(headlines_count
) < 30) {
70 _infscroll_disable
= 1;
72 _infscroll_disable
= 0;
75 var counters
= reply
['counters'];
76 var articles
= reply
['articles'];
77 //var runtime_info = reply['runtime-info'];
79 if (infscroll_req
== false) {
80 loaded_article_ids
= [];
82 dijit
.byId("headlines-frame").attr('content',
83 reply
['headlines']['content']);
85 dijit
.byId("headlines-toolbar").attr('content',
86 reply
['headlines']['toolbar']);
88 $$("#headlines-frame > div[id*=RROW]").each(function(row
) {
89 if (loaded_article_ids
.indexOf(row
.id
) != -1) {
90 row
.parentNode
.removeChild(row
);
92 loaded_article_ids
.push(row
.id
);
96 if (getInitParam("cdm_auto_catchup") == 1) {
97 var hsp
= $("headlines-spacer");
98 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
99 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
105 $("feed_title").innerHTML
+= "<span id='cancel_search'>" +
106 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
112 if (headlines_count
> 0 && feed_id
== getActiveFeedId() && is_cat
== activeFeedIsCat()) {
113 console
.log("adding some more headlines: " + headlines_count
);
115 var c
= dijit
.byId("headlines-frame");
116 var ids
= getSelectedArticleIds2();
119 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
121 var hsp
= $("headlines-spacer");
124 c
.domNode
.removeChild(hsp
);
126 $$("#headlines-tmp > div").each(function(row
) {
127 if (row
.className
== 'cdmFeedTitle') {
128 row
.style
.display
= 'none';
129 c
.domNode
.appendChild(row
);
131 } else if (loaded_article_ids
.indexOf(row
.id
) == -1) {
132 row
.style
.display
= 'none';
133 c
.domNode
.appendChild(row
);
135 loaded_article_ids
.push(row
.id
);
137 row
.parentNode
.removeChild(row
);
141 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
143 fixHeadlinesOrder(getLoadedArticleIds());
145 if (getInitParam("cdm_auto_catchup") == 1) {
146 c
.domNode
.appendChild(hsp
);
149 console
.log("added " + new_elems
.size() + " headlines");
151 if (new_elems
.size() == 0)
152 _infscroll_disable
= true;
154 console
.log("restore selected ids: " + ids
);
156 for (var i
= 0; i
< ids
.length
; i
++) {
157 markHeadline(ids
[i
]);
162 new_elems
.each(function(child
) {
163 var cb
= dijit
.byId(child
.id
.replace("RROW-", "RCHK-"));
166 dojo
.parser
.parse(child
);
168 if (!Element
.visible(child
))
169 new Effect
.Appear(child
, { duration
: 0.5 });
171 c
.domNode
.removeChild(child
);
176 console
.log("no new headlines received");
178 var hsp
= $("headlines-spacer");
180 if (hsp
) hsp
.innerHTML
= "";
185 for (var i
= 0; i
< articles
.length
; i
++) {
186 var a_id
= articles
[i
]['id'];
187 cache_set("article:" + a_id
, articles
[i
]['content']);
190 console
.log("no cached articles received");
194 parse_counters(counters
);
196 request_counters(true);
198 } else if (transport
.responseText
) {
199 console
.error("Invalid object received: " + transport
.responseText
);
200 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
201 __('Could not update headlines (invalid object received - see error console for details)') +
204 //notify_error("Error communicating with server.");
205 Element
.show(dijit
.byId("net-alert").domNode
);
208 _infscroll_request_sent
= 0;
209 _last_headlines_update
= new Date().getTime();
211 unpackVisibleHeadlines();
216 exception_error("headlines_callback2", e
, transport
);
220 function render_article(article
) {
222 dijit
.byId("headlines-wrap-inner").addChild(
223 dijit
.byId("content-insert"));
225 var c
= dijit
.byId("content-insert");
228 c
.domNode
.scrollTop
= 0;
231 c
.attr('content', article
);
233 correctHeadlinesOffset(getActiveArticleId());
240 exception_error("render_article", e
);
244 function showArticleInHeadlines(id
) {
247 selectArticles("none");
249 var crow
= $("RROW-" + id
);
253 var article_is_unread
= crow
.hasClassName("Unread");
255 crow
.removeClassName("Unread");
256 crow
.addClassName("active");
258 selectArticles('none');
260 var view_mode
= false;
263 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
264 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
271 if (article_is_unread
)
272 _force_scheduled_update
= true;
275 exception_error("showArticleInHeadlines", e
);
279 function article_callback2(transport
, id
) {
281 console
.log("article_callback2 " + id
);
283 handle_rpc_json(transport
);
288 reply
= JSON
.parse(transport
.responseText
);
295 reply
.each(function(article
) {
296 if (getActiveArticleId() == article
['id']) {
297 render_article(article
['content']);
299 cids_requested
.remove(article
['id']);
301 cache_set("article:" + article
['id'], article
['content']);
304 // if (id != last_requested_article) {
305 // console.log("requested article id is out of sequence, aborting");
309 } else if (transport
.responseText
) {
310 console
.error("Invalid object received: " + transport
.responseText
);
312 render_article("<div class='whiteBox'>" +
313 __('Could not display article (invalid object received - see error console for details)') + "</div>");
315 Element
.show(dijit
.byId("net-alert").domNode
);
318 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
319 request_counters(unread_in_buffer
== 0);
321 //headlines_scroll_handler($("headlines-frame"));
324 if (!_infscroll_disable &&
325 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
335 exception_error("article_callback2", e
, transport
);
341 var oldrow
= $("RROW-" + getActiveArticleId());
342 if (oldrow
) oldrow
.removeClassName("active");
344 var crow
= $("RROW-" + id
);
348 console
.log("loading article: " + id
);
350 var cached_article
= cache_get("article:" + id
);
352 console
.log("cache check result: " + (cached_article
!= false));
354 var query
= "?op=article&method=view&id=" + param_escape(id
);
356 var neighbor_ids
= getRelativePostIds(id
);
358 /* only request uncached articles */
360 var cids_to_request
= [];
362 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
363 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
364 if (!cache_get("article:" + neighbor_ids
[i
])) {
365 cids_to_request
.push(neighbor_ids
[i
]);
366 cids_requested
.push(neighbor_ids
[i
]);
370 console
.log("additional ids: " + cids_to_request
.toString());
372 query
= query
+ "&cids=" + cids_to_request
.toString();
374 var article_is_unread
= crow
.hasClassName("Unread");
376 setActiveArticleId(id
);
377 showArticleInHeadlines(id
);
379 if (cached_article
&& article_is_unread
) {
381 query
= query
+ "&mode=prefetch";
383 render_article(cached_article
);
385 } else if (cached_article
) {
387 query
= query
+ "&mode=prefetch_old";
388 render_article(cached_article
);
390 // if we don't need to request any relative ids, we might as well skip
391 // the server roundtrip altogether
392 if (cids_to_request
.length
== 0) {
395 if (!_infscroll_disable &&
396 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
404 //headlines_scroll_handler($("headlines-frame"));
410 last_requested_article
= id
;
414 if (article_is_unread
) {
415 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
418 new Ajax
.Request("backend.php", {
420 onComplete: function(transport
) {
421 article_callback2(transport
, id
);
427 exception_error("view", e
);
431 function toggleMark(id
, client_only
) {
433 var query
= "?op=rpc&id=" + id
+ "&method=mark";
435 var img
= $("FMPIC-" + id
);
439 if (img
.src
.match("mark_unset")) {
440 img
.src
= img
.src
.replace("mark_unset", "mark_set");
441 img
.alt
= __("Unstar article");
442 query
= query
+ "&mark=1";
445 img
.src
= img
.src
.replace("mark_set", "mark_unset");
446 img
.alt
= __("Star article");
447 query
= query
+ "&mark=0";
451 new Ajax
.Request("backend.php", {
453 onComplete: function(transport
) {
454 handle_rpc_json(transport
);
459 exception_error("toggleMark", e
);
463 function togglePub(id
, client_only
, no_effects
, note
) {
465 var query
= "?op=rpc&id=" + id
+ "&method=publ";
467 if (note
!= undefined) {
468 query
= query
+ "¬e=" + param_escape(note
);
470 query
= query
+ "¬e=undefined";
473 var img
= $("FPPIC-" + id
);
477 if (img
.src
.match("pub_unset") || note
!= undefined) {
478 img
.src
= img
.src
.replace("pub_unset", "pub_set");
479 img
.alt
= __("Unpublish article");
480 query
= query
+ "&pub=1";
483 img
.src
= img
.src
.replace("pub_set", "pub_unset");
484 img
.alt
= __("Publish article");
486 query
= query
+ "&pub=0";
490 new Ajax
.Request("backend.php", {
492 onComplete: function(transport
) {
493 handle_rpc_json(transport
);
498 exception_error("togglePub", e
);
502 function moveToPost(mode
, noscroll
) {
506 var rows
= getVisibleArticleIds();
511 if (!$('RROW-' + getActiveArticleId())) {
512 setActiveArticleId(0);
515 if (!getActiveArticleId()) {
517 prev_id
= rows
[rows
.length
-1]
519 for (var i
= 0; i
< rows
.length
; i
++) {
520 if (rows
[i
] == getActiveArticleId()) {
522 // Account for adjacent identical article ids.
523 if (i
> 0) prev_id
= rows
[i
-1];
525 for (var j
= i
+1; j
< rows
.length
; j
++) {
526 if (rows
[j
] != getActiveArticleId()) {
536 if (mode
== "next") {
537 if (next_id
|| getActiveArticleId()) {
540 var article
= $("RROW-" + getActiveArticleId());
541 var ctr
= $("headlines-frame");
543 if (!noscroll
&& article
&& article
.offsetTop
+ article
.offsetHeight
>
544 ctr
.scrollTop
+ ctr
.offsetHeight
) {
546 scrollArticle(ctr
.offsetHeight
/4);
548 } else if (next_id
) {
549 cdmExpandArticle(next_id
);
550 cdmScrollToArticleId(next_id
, true);
553 } else if (next_id
) {
554 correctHeadlinesOffset(next_id
);
555 view(next_id
, getActiveFeedId());
560 if (mode
== "prev") {
561 if (prev_id
|| getActiveArticleId()) {
564 var article
= $("RROW-" + getActiveArticleId());
565 var prev_article
= $("RROW-" + prev_id
);
566 var ctr
= $("headlines-frame");
568 if (!getInitParam("cdm_expanded")) {
570 if (!noscroll
&& article
.offsetTop
< ctr
.scrollTop
) {
571 scrollArticle(-ctr
.offsetHeight
/4);
573 cdmExpandArticle(prev_id
);
574 cdmScrollToArticleId(prev_id
, true);
578 if (!noscroll
&& article
&& article
.offsetTop
< ctr
.scrollTop
) {
579 scrollArticle(-ctr
.offsetHeight
/3);
580 } else if (!noscroll
&& prev_article
&&
581 prev_article
.offsetTop
< ctr
.scrollTop
) {
582 cdmExpandArticle(prev_id
);
583 scrollArticle(-ctr
.offsetHeight
/4);
584 } else if (prev_id
) {
585 cdmExpandArticle(prev_id
);
586 cdmScrollToArticleId(prev_id
, noscroll
);
590 } else if (prev_id
) {
591 correctHeadlinesOffset(prev_id
);
592 view(prev_id
, getActiveFeedId());
598 exception_error("moveToPost", e
);
602 function toggleSelected(id
, force_on
) {
605 var cb
= dijit
.byId("RCHK-" + id
);
606 var row
= $("RROW-" + id
);
609 if (row
.hasClassName('Selected') && !force_on
) {
610 row
.removeClassName('Selected');
611 if (cb
) cb
.attr("checked", false);
613 row
.addClassName('Selected');
614 if (cb
) cb
.attr("checked", true);
618 exception_error("toggleSelected", e
);
622 function toggleUnread_afh(effect
) {
625 var elem
= effect
.element
;
626 elem
.style
.backgroundColor
= "";
629 exception_error("toggleUnread_afh", e
);
633 function toggleUnread(id
, cmode
, effect
) {
636 var row
= $("RROW-" + id
);
638 if (cmode
== undefined || cmode
== 2) {
639 if (row
.hasClassName("Unread")) {
640 row
.removeClassName("Unread");
643 row
.addClassName("Unread");
646 } else if (cmode
== 0) {
648 row
.removeClassName("Unread");
650 } else if (cmode
== 1) {
651 row
.addClassName("Unread");
654 if (cmode
== undefined) cmode
= 2;
656 var query
= "?op=rpc&method=catchupSelected" +
657 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
659 // notify_progress("Loading, please wait...");
661 new Ajax
.Request("backend.php", {
663 onComplete: function(transport
) {
664 handle_rpc_json(transport
);
670 exception_error("toggleUnread", e
);
674 function selectionRemoveLabel(id
, ids
) {
677 if (!ids
) ids
= getSelectedArticleIds2();
679 if (ids
.length
== 0) {
680 alert(__("No articles are selected."));
684 var query
= "?op=article&method=removeFromLabel&ids=" +
685 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
689 new Ajax
.Request("backend.php", {
691 onComplete: function(transport
) {
692 handle_rpc_json(transport
);
693 show_labels_in_headlines(transport
);
697 exception_error("selectionAssignLabel", e
);
702 function selectionAssignLabel(id
, ids
) {
705 if (!ids
) ids
= getSelectedArticleIds2();
707 if (ids
.length
== 0) {
708 alert(__("No articles are selected."));
712 var query
= "?op=article&method=assignToLabel&ids=" +
713 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
717 new Ajax
.Request("backend.php", {
719 onComplete: function(transport
) {
720 handle_rpc_json(transport
);
721 show_labels_in_headlines(transport
);
725 exception_error("selectionAssignLabel", e
);
730 function selectionToggleUnread(set_state
, callback
, no_error
, ids
) {
732 var rows
= ids
? ids
: getSelectedArticleIds2();
734 if (rows
.length
== 0 && !no_error
) {
735 alert(__("No articles are selected."));
739 for (var i
= 0; i
< rows
.length
; i
++) {
740 var row
= $("RROW-" + rows
[i
]);
742 if (set_state
== undefined) {
743 if (row
.hasClassName("Unread")) {
744 row
.removeClassName("Unread");
746 row
.addClassName("Unread");
750 if (set_state
== false) {
751 row
.removeClassName("Unread");
754 if (set_state
== true) {
755 row
.addClassName("Unread");
760 if (rows
.length
> 0) {
764 if (set_state
== undefined) {
766 } else if (set_state
== true) {
768 } else if (set_state
== false) {
772 var query
= "?op=rpc&method=catchupSelected" +
773 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
775 notify_progress("Loading, please wait...");
777 new Ajax
.Request("backend.php", {
779 onComplete: function(transport
) {
780 handle_rpc_json(transport
);
781 if (callback
) callback(transport
);
787 exception_error("selectionToggleUnread", e
);
792 function selectionToggleMarked(sel_state
, callback
, no_error
, ids
) {
795 var rows
= ids
? ids
: getSelectedArticleIds2();
797 if (rows
.length
== 0 && !no_error
) {
798 alert(__("No articles are selected."));
802 for (var i
= 0; i
< rows
.length
; i
++) {
803 toggleMark(rows
[i
], true, true);
806 if (rows
.length
> 0) {
808 var query
= "?op=rpc&method=markSelected&ids=" +
809 param_escape(rows
.toString()) + "&cmode=2";
811 new Ajax
.Request("backend.php", {
813 onComplete: function(transport
) {
814 handle_rpc_json(transport
);
815 if (callback
) callback(transport
);
821 exception_error("selectionToggleMarked", e
);
826 function selectionTogglePublished(sel_state
, callback
, no_error
, ids
) {
829 var rows
= ids
? ids
: getSelectedArticleIds2();
831 if (rows
.length
== 0 && !no_error
) {
832 alert(__("No articles are selected."));
836 for (var i
= 0; i
< rows
.length
; i
++) {
837 togglePub(rows
[i
], true, true);
840 if (rows
.length
> 0) {
842 var query
= "?op=rpc&method=publishSelected&ids=" +
843 param_escape(rows
.toString()) + "&cmode=2";
845 new Ajax
.Request("backend.php", {
847 onComplete: function(transport
) {
848 handle_rpc_json(transport
);
854 exception_error("selectionToggleMarked", e
);
858 function getSelectedArticleIds2() {
862 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
864 rv
.push(child
.id
.replace("RROW-", ""));
870 function getLoadedArticleIds() {
873 var children
= $$("#headlines-frame > div[id*=RROW-]");
875 children
.each(function(child
) {
876 rv
.push(child
.id
.replace("RROW-", ""));
883 // mode = all,none,unread,invert,marked,published
884 function selectArticles(mode
) {
887 var children
= $$("#headlines-frame > div[id*=RROW]");
889 children
.each(function(child
) {
890 var id
= child
.id
.replace("RROW-", "");
891 var cb
= dijit
.byId("RCHK-" + id
);
894 child
.addClassName("Selected");
895 if (cb
) cb
.attr("checked", true);
896 } else if (mode
== "unread") {
897 if (child
.hasClassName("Unread")) {
898 child
.addClassName("Selected");
899 if (cb
) cb
.attr("checked", true);
901 child
.removeClassName("Selected");
902 if (cb
) cb
.attr("checked", false);
904 } else if (mode
== "marked") {
905 var img
= $("FMPIC-" + child
.id
.replace("RROW-", ""));
907 if (img
&& img
.src
.match("mark_set")) {
908 child
.addClassName("Selected");
909 if (cb
) cb
.attr("checked", true);
911 child
.removeClassName("Selected");
912 if (cb
) cb
.attr("checked", false);
914 } else if (mode
== "published") {
915 var img
= $("FPPIC-" + child
.id
.replace("RROW-", ""));
917 if (img
&& img
.src
.match("pub_set")) {
918 child
.addClassName("Selected");
919 if (cb
) cb
.attr("checked", true);
921 child
.removeClassName("Selected");
922 if (cb
) cb
.attr("checked", false);
925 } else if (mode
== "invert") {
926 if (child
.hasClassName("Selected")) {
927 child
.removeClassName("Selected");
928 if (cb
) cb
.attr("checked", false);
930 child
.addClassName("Selected");
931 if (cb
) cb
.attr("checked", true);
935 child
.removeClassName("Selected");
936 if (cb
) cb
.attr("checked", false);
941 exception_error("selectArticles", e
);
945 function deleteSelection() {
949 var rows
= getSelectedArticleIds2();
951 if (rows
.length
== 0) {
952 alert(__("No articles are selected."));
956 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
959 if (getActiveFeedId() != 0) {
960 str
= ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows
.length
);
962 str
= ngettext("Delete %d selected article?", "Delete %d selected articles?", rows
.length
);
965 str
= str
.replace("%d", rows
.length
);
966 str
= str
.replace("%s", fn
);
968 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
972 query
= "?op=rpc&method=delete&ids=" + param_escape(rows
);
976 new Ajax
.Request("backend.php", {
978 onComplete: function(transport
) {
979 handle_rpc_json(transport
);
984 exception_error("deleteSelection", e
);
988 function archiveSelection() {
992 var rows
= getSelectedArticleIds2();
994 if (rows
.length
== 0) {
995 alert(__("No articles are selected."));
999 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1003 if (getActiveFeedId() != 0) {
1004 str
= ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows
.length
);
1007 str
= ngettext("Move %d archived article back?", "Move %d archived articles back?", rows
.length
);
1009 str
+= " " + __("Please note that unstarred articles might get purged on next feed update.");
1014 str
= str
.replace("%d", rows
.length
);
1015 str
= str
.replace("%s", fn
);
1017 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1021 query
= "?op=rpc&method="+op
+"&ids=" + param_escape(rows
);
1025 for (var i
= 0; i
< rows
.length
; i
++) {
1026 cache_delete("article:" + rows
[i
]);
1029 new Ajax
.Request("backend.php", {
1031 onComplete: function(transport
) {
1032 handle_rpc_json(transport
);
1037 exception_error("archiveSelection", e
);
1041 function catchupSelection() {
1045 var rows
= getSelectedArticleIds2();
1047 if (rows
.length
== 0) {
1048 alert(__("No articles are selected."));
1052 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1054 var str
= ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows
.length
);
1056 str
= str
.replace("%d", rows
.length
);
1057 str
= str
.replace("%s", fn
);
1059 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1063 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1066 exception_error("catchupSelection", e
);
1070 function editArticleTags(id
) {
1071 var query
= "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id
);
1073 if (dijit
.byId("editTagsDlg"))
1074 dijit
.byId("editTagsDlg").destroyRecursive();
1076 dialog
= new dijit
.Dialog({
1078 title
: __("Edit article Tags"),
1079 style
: "width: 600px",
1080 execute: function() {
1081 if (this.validate()) {
1082 var query
= dojo
.objectToQuery(this.attr('value'));
1084 notify_progress("Saving article tags...", true);
1086 new Ajax
.Request("backend.php", {
1088 onComplete: function(transport
) {
1093 var data
= JSON
.parse(transport
.responseText
);
1100 var tags
= $("ATSTR-" + id
);
1101 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1103 if (tags
) tags
.innerHTML
= data
.content
;
1104 if (tooltip
) tooltip
.attr('label', data
.content_full
);
1107 exception_error("editArticleTags/inner", e
);
1116 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1117 dojo
.disconnect(tmph
);
1119 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1120 "backend.php?op=article&method=completeTags",
1121 { tokens
: ',', paramName
: "search" });
1128 function cdmScrollToArticleId(id
, force
) {
1130 var ctr
= $("headlines-frame");
1131 var e
= $("RROW-" + id
);
1133 if (!e
|| !ctr
) return;
1135 if (force
|| e
.offsetTop
+e
.offsetHeight
> (ctr
.scrollTop
+ctr
.offsetHeight
) ||
1136 e
.offsetTop
< ctr
.scrollTop
) {
1138 // expanded cdm has a 4px margin now
1139 ctr
.scrollTop
= parseInt(e
.offsetTop
) - 4;
1143 exception_error("cdmScrollToArticleId", e
);
1147 function setActiveArticleId(id
) {
1148 _active_article_id
= id
;
1151 function getActiveArticleId() {
1152 return _active_article_id
;
1155 function postMouseIn(e
, id
) {
1156 post_under_pointer
= id
;
1159 function postMouseOut(id
) {
1160 post_under_pointer
= false;
1163 function unpackVisibleHeadlines() {
1165 if (!isCdmMode()) return;
1167 $$("#headlines-frame > div[id*=RROW]").each(
1169 if (child
.offsetTop
<= $("headlines-frame").scrollTop
+
1170 $("headlines-frame").offsetHeight
) {
1172 var cencw
= $("CENCW-" + child
.id
.replace("RROW-", ""));
1175 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1176 cencw
.setAttribute('id', '');
1177 Element
.show(cencw
);
1184 exception_error("unpackVisibleHeadlines", e
);
1188 function headlines_scroll_handler(e
) {
1190 var hsp
= $("headlines-spacer");
1192 unpackVisibleHeadlines();
1194 if (!_infscroll_disable
) {
1195 if ((hsp
&& e
.scrollTop
+ e
.offsetHeight
>= hsp
.offsetTop
- hsp
.offsetHeight
) ||
1196 (e
.scrollHeight
!= 0 &&
1197 ((e
.scrollTop
+ e
.offsetHeight
) / e
.scrollHeight
>= 0.7))) {
1200 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1201 __("Loading, please wait...");
1203 loadMoreHeadlines();
1208 if (hsp
) hsp
.innerHTML
= "";
1211 if (getInitParam("cdm_auto_catchup") == 1) {
1213 // let's get DOM some time to settle down
1214 var ts
= new Date().getTime();
1215 if (ts
- _last_headlines_update
< 100) 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 reply
= JSON
.parse(transport
.responseText
);
1263 var batch
= reply
.ids
;
1265 batch
.each(function(id
) {
1267 var elem
= $("RROW-" + id
);
1268 if (elem
) elem
.removeClassName("Unread");
1269 catchup_id_batch
.remove(id
);
1276 exception_error("catchupBatchedArticles", e
);
1280 function catchupRelativeToArticle(below
, id
) {
1284 if (!id
) id
= getActiveArticleId();
1287 alert(__("No article is selected."));
1291 var visible_ids
= getVisibleArticleIds();
1293 var ids_to_mark
= new Array();
1296 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1297 if (visible_ids
[i
] != id
) {
1298 var e
= $("RROW-" + visible_ids
[i
]);
1300 if (e
&& e
.hasClassName("Unread")) {
1301 ids_to_mark
.push(visible_ids
[i
]);
1308 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1309 if (visible_ids
[i
] != id
) {
1310 var e
= $("RROW-" + visible_ids
[i
]);
1312 if (e
&& e
.hasClassName("Unread")) {
1313 ids_to_mark
.push(visible_ids
[i
]);
1321 if (ids_to_mark
.length
== 0) {
1322 alert(__("No articles found to mark"));
1324 var msg
= ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark
.length
).replace("%d", ids_to_mark
.length
);
1326 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1328 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1329 var e
= $("RROW-" + ids_to_mark
[i
]);
1330 e
.removeClassName("Unread");
1333 var query
= "?op=rpc&method=catchupSelected" +
1334 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1336 new Ajax
.Request("backend.php", {
1338 onComplete: function(transport
) {
1339 handle_rpc_json(transport
);
1346 exception_error("catchupRelativeToArticle", e
);
1350 function cdmCollapseArticle(event
, id
) {
1352 var row
= $("RROW-" + id
);
1353 var elem
= $("CICD-" + id
);
1356 var collapse
= $$("div#RROW-" + id
+
1357 " span[class='collapseBtn']")[0];
1360 Element
.show("CEXC-" + id
);
1361 Element
.hide(collapse
);
1362 row
.removeClassName("active");
1364 markHeadline(id
, false);
1366 if (id
== getActiveArticleId()) {
1367 setActiveArticleId(0);
1370 if (event
) Event
.stop(event
);
1374 exception_error("cdmCollapseArticle", e
);
1378 function cdmExpandArticle(id
) {
1380 console
.log("cdmExpandArticle " + id
);
1382 if (!$("RROW-" + id
)) return false;
1384 var oldrow
= $("RROW-" + getActiveArticleId());
1386 var elem
= $("CICD-" + getActiveArticleId());
1388 if (id
== getActiveArticleId() && Element
.visible(elem
))
1391 selectArticles("none");
1393 var old_offset
= $("RROW-" + id
).offsetTop
;
1395 if (getActiveArticleId() && elem
&& !getInitParam("cdm_expanded")) {
1396 var collapse
= $$("div#RROW-" + getActiveArticleId() +
1397 " span[class='collapseBtn']")[0];
1400 Element
.show("CEXC-" + getActiveArticleId());
1401 Element
.hide(collapse
);
1404 if (oldrow
) oldrow
.removeClassName("active");
1406 setActiveArticleId(id
);
1408 elem
= $("CICD-" + id
);
1410 var collapse
= $$("div#RROW-" + id
+
1411 " span[class='collapseBtn']")[0];
1413 var cencw
= $("CENCW-" + id
);
1415 if (!Element
.visible(elem
)) {
1417 cencw
.innerHTML
= htmlspecialchars_decode(cencw
.innerHTML
);
1418 cencw
.setAttribute('id', '');
1419 Element
.show(cencw
);
1423 Element
.hide("CEXC-" + id
);
1424 Element
.show(collapse
);
1427 var new_offset
= $("RROW-" + id
).offsetTop
;
1429 if (old_offset
> new_offset
)
1430 $("headlines-frame").scrollTop
-= (old_offset
-new_offset
);
1432 toggleUnread(id
, 0, true);
1434 $("RROW-" + id
).addClassName("active");
1437 exception_error("cdmExpandArticle", e
);
1443 function fixHeadlinesOrder(ids
) {
1445 for (var i
= 0; i
< ids
.length
; i
++) {
1446 var e
= $("RROW-" + ids
[i
]);
1450 e
.removeClassName("even");
1451 e
.addClassName("odd");
1453 e
.removeClassName("odd");
1454 e
.addClassName("even");
1459 exception_error("fixHeadlinesOrder", e
);
1463 function getArticleUnderPointer() {
1464 return post_under_pointer
;
1467 function scrollArticle(offset
) {
1470 var ci
= $("content-insert");
1472 ci
.scrollTop
+= offset
;
1475 var hi
= $("headlines-frame");
1477 hi
.scrollTop
+= offset
;
1482 exception_error("scrollArticle", e
);
1486 function show_labels_in_headlines(transport
) {
1488 var data
= JSON
.parse(transport
.responseText
);
1491 data
['info-for-headlines'].each(function(elem
) {
1492 var ctr
= $("HLLCTR-" + elem
.id
);
1494 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1498 exception_error("show_labels_in_headlines", e
);
1502 function dismissArticle(id
) {
1504 var elem
= $("RROW-" + id
);
1508 toggleUnread(id
, 0, true);
1510 new Effect
.Fade(elem
, {duration
: 0.5});
1512 if (id
== getActiveArticleId()) {
1513 setActiveArticleId(0);
1517 exception_error("dismissArticle", e
);
1521 function dismissSelectedArticles() {
1524 var ids
= getVisibleArticleIds();
1528 for (var i
= 0; i
< ids
.length
; i
++) {
1529 var elem
= $("RROW-" + ids
[i
]);
1531 if (elem
.className
&& elem
.hasClassName("Selected") &&
1532 ids
[i
] != getActiveArticleId()) {
1533 new Effect
.Fade(elem
, {duration
: 0.5});
1541 selectionToggleUnread(false);
1543 fixHeadlinesOrder(tmp
);
1546 exception_error("dismissSelectedArticles", e
);
1550 function dismissReadArticles() {
1553 var ids
= getVisibleArticleIds();
1556 for (var i
= 0; i
< ids
.length
; i
++) {
1557 var elem
= $("RROW-" + ids
[i
]);
1559 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1560 !elem
.hasClassName("Selected")) {
1562 new Effect
.Fade(elem
, {duration
: 0.5});
1568 fixHeadlinesOrder(tmp
);
1571 exception_error("dismissSelectedArticles", e
);
1575 function getVisibleArticleIds() {
1580 getLoadedArticleIds().each(function(id
) {
1581 var elem
= $("RROW-" + id
);
1582 if (elem
&& Element
.visible(elem
))
1587 exception_error("getVisibleArticleIds", e
);
1593 function cdmClicked(event
, id
) {
1595 //var shift_key = event.shiftKey;
1597 if (!event
.ctrlKey
) {
1599 if (!getInitParam("cdm_expanded")) {
1600 return cdmExpandArticle(id
);
1603 var elem
= $("RROW-" + getActiveArticleId());
1605 if (elem
) elem
.removeClassName("active");
1607 selectArticles("none");
1610 var elem
= $("RROW-" + id
);
1611 var article_is_unread
= elem
.hasClassName("Unread");
1613 elem
.removeClassName("Unread");
1614 elem
.addClassName("active");
1616 setActiveArticleId(id
);
1618 if (article_is_unread
) {
1619 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1622 var query
= "?op=rpc&method=catchupSelected" +
1623 "&cmode=0&ids=" + param_escape(id
);
1625 new Ajax
.Request("backend.php", {
1627 onComplete: function(transport
) {
1628 handle_rpc_json(transport
);
1631 return !event
.shiftKey
;
1635 toggleSelected(id
, true);
1637 var elem
= $("RROW-" + id
);
1638 var article_is_unread
= elem
.hasClassName("Unread");
1640 if (article_is_unread
) {
1641 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1644 toggleUnread(id
, 0, false);
1646 openArticleInNewWindow(id
);
1649 var unread_in_buffer
= $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1650 request_counters(unread_in_buffer
== 0);
1653 exception_error("cdmClicked");
1659 function hlClicked(event
, id
) {
1661 if (event
.which
== 2) {
1664 } else if (event
.ctrlKey
) {
1665 toggleSelected(id
, true);
1666 toggleUnread(id
, 0, false);
1667 openArticleInNewWindow(id
);
1675 exception_error("hlClicked");
1679 function getFirstVisibleHeadlineId() {
1680 var rows
= getVisibleArticleIds();
1685 function getLastVisibleHeadlineId() {
1686 var rows
= getVisibleArticleIds();
1687 return rows
[rows
.length
-1];
1690 function openArticleInNewWindow(id
) {
1691 toggleUnread(id
, 0, false);
1692 window
.open("backend.php?op=article&method=redirect&id=" + id
);
1695 function isCdmMode() {
1696 return getInitParam("combined_display_mode");
1699 function markHeadline(id
, marked
) {
1700 if (marked
== undefined) marked
= true;
1702 var row
= $("RROW-" + id
);
1704 var check
= dijit
.byId("RCHK-" + id
);
1707 check
.attr("checked", marked
);
1711 row
.addClassName("Selected");
1713 row
.removeClassName("Selected");
1717 function getRelativePostIds(id
, limit
) {
1723 if (!limit
) limit
= 6; //3
1725 var ids
= getVisibleArticleIds();
1727 for (var i
= 0; i
< ids
.length
; i
++) {
1729 for (var k
= 1; k
<= limit
; k
++) {
1730 //if (i > k-1) tmp.push(ids[i-k]);
1731 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1738 exception_error("getRelativePostIds", e
);
1744 function correctHeadlinesOffset(id
) {
1748 var container
= $("headlines-frame");
1749 var row
= $("RROW-" + id
);
1751 if (!container
|| !row
) return;
1753 var viewport
= container
.offsetHeight
;
1755 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1756 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1758 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1759 //console.log("Vport: " + viewport);
1761 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1762 container
.scrollTop
= row
.offsetTop
;
1763 } else if (rel_offset_bottom
> viewport
) {
1765 /* doesn't properly work with Opera in some cases because
1766 Opera fucks up element scrolling */
1768 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1772 exception_error("correctHeadlinesOffset", e
);
1777 function headlineActionsChange(elem
) {
1780 elem
.attr('value', 'false');
1782 exception_error("headlineActionsChange", e
);
1786 function closeArticlePanel() {
1788 if (dijit
.byId("content-insert"))
1789 dijit
.byId("headlines-wrap-inner").removeChild(
1790 dijit
.byId("content-insert"));
1793 function initHeadlinesMenu() {
1795 if (dijit
.byId("headlinesMenu"))
1796 dijit
.byId("headlinesMenu").destroyRecursive();
1801 nodes
= $$("#headlines-frame > div[id*=RROW]");
1803 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1806 nodes
.each(function(node
) {
1810 var menu
= new dijit
.Menu({
1811 id
: "headlinesMenu",
1815 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1816 var callerNode
= event
.target
, match
= null, tries
= 0;
1818 while (match
== null && callerNode
&& tries
<= 3) {
1819 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1820 callerNode
= callerNode
.parentNode
;
1824 if (match
) this.callerRowId
= parseInt(match
[1]);
1828 /* if (!isCdmMode())
1829 menu.addChild(new dijit.MenuItem({
1830 label: __("View article"),
1831 onClick: function(event) {
1832 view(this.getParent().callerRowId);
1835 menu
.addChild(new dijit
.MenuItem({
1836 label
: __("Open original article"),
1837 onClick: function(event
) {
1838 openArticleInNewWindow(this.getParent().callerRowId
);
1841 menu
.addChild(new dijit
.MenuItem({
1842 label
: __("Display article URL"),
1843 onClick: function(event
) {
1844 displayArticleUrl(this.getParent().callerRowId
);
1847 menu
.addChild(new dijit
.MenuSeparator());
1849 menu
.addChild(new dijit
.MenuItem({
1850 label
: __("Toggle unread"),
1851 onClick: function(event
) {
1852 var ids
= getSelectedArticleIds2();
1854 var id
= this.getParent().callerRowId
+ "";
1855 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1857 selectionToggleUnread(undefined, false, true, ids
);
1860 menu
.addChild(new dijit
.MenuItem({
1861 label
: __("Toggle marked"),
1862 onClick: function(event
) {
1863 var ids
= getSelectedArticleIds2();
1865 var id
= this.getParent().callerRowId
+ "";
1866 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1868 selectionToggleMarked(undefined, false, true, ids
);
1871 menu
.addChild(new dijit
.MenuItem({
1872 label
: __("Toggle published"),
1873 onClick: function(event
) {
1874 var ids
= getSelectedArticleIds2();
1876 var id
= this.getParent().callerRowId
+ "";
1877 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1879 selectionTogglePublished(undefined, false, true, ids
);
1882 menu
.addChild(new dijit
.MenuSeparator());
1884 menu
.addChild(new dijit
.MenuItem({
1885 label
: __("Mark above as read"),
1886 onClick: function(event
) {
1887 catchupRelativeToArticle(0, this.getParent().callerRowId
);
1890 menu
.addChild(new dijit
.MenuItem({
1891 label
: __("Mark below as read"),
1892 onClick: function(event
) {
1893 catchupRelativeToArticle(1, this.getParent().callerRowId
);
1897 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1901 menu
.addChild(new dijit
.MenuSeparator());
1903 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1904 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1906 labels
.each(function(label
) {
1907 var id
= label
.id
[0];
1908 var bare_id
= id
.substr(id
.indexOf(":")+1);
1909 var name
= label
.name
[0];
1911 bare_id
= feed_to_label_id(bare_id
);
1913 labelAddMenu
.addChild(new dijit
.MenuItem({
1916 onClick: function(event
) {
1917 var ids
= getSelectedArticleIds2();
1919 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1921 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1923 selectionAssignLabel(this.labelId
, ids
);
1926 labelDelMenu
.addChild(new dijit
.MenuItem({
1929 onClick: function(event
) {
1930 var ids
= getSelectedArticleIds2();
1932 var id
= this.getParent().ownerMenu
.callerRowId
+ "";
1934 ids
= ids
.size() != 0 && ids
.indexOf(id
) != -1 ? ids
: [id
];
1936 selectionRemoveLabel(this.labelId
, ids
);
1941 menu
.addChild(new dijit
.PopupMenuItem({
1942 label
: __("Assign label"),
1943 popup
: labelAddMenu
,
1946 menu
.addChild(new dijit
.PopupMenuItem({
1947 label
: __("Remove label"),
1948 popup
: labelDelMenu
,
1956 exception_error("initHeadlinesMenu", e
);
1961 function player(elem
) {
1962 var aid
= elem
.getAttribute("audio-id");
1963 var status
= elem
.getAttribute("status");
1971 elem
.innerHTML
= __("Playing...");
1972 elem
.title
= __("Click to pause");
1973 elem
.addClassName("playing");
1977 elem
.innerHTML
= __("Play");
1978 elem
.title
= __("Click to play");
1979 elem
.removeClassName("playing");
1982 elem
.setAttribute("status", status
);
1984 alert("Your browser doesn't seem to support HTML5 audio.");
1988 function cache_set(id
, obj
) {
1989 //console.log("cache_set: " + id);
1992 sessionStorage
[id
] = obj
;
1994 sessionStorage
.clear();
1998 function cache_get(id
) {
2000 return sessionStorage
[id
];
2003 function cache_clear() {
2005 sessionStorage
.clear();
2008 function cache_delete(id
) {
2010 sessionStorage
.removeItem(id
);
2013 function cancelSearch() {
2018 exception_error("cancelSearch", e
);
2022 function setSelectionScore() {
2024 var ids
= getSelectedArticleIds2();
2026 if (ids
.length
> 0) {
2029 var score
= prompt(__("Please enter new score for selected articles:"), score
);
2031 if (score
!= undefined) {
2032 var query
= "op=article&method=setScore&id=" + param_escape(ids
.toString()) +
2033 "&score=" + param_escape(score
);
2035 new Ajax
.Request("backend.php", {
2037 onComplete: function(transport
) {
2038 var reply
= JSON
.parse(transport
.responseText
);
2042 ids
.each(function(id
) {
2043 var row
= $("RROW-" + id
);
2046 var pic
= row
.getElementsByClassName("hlScorePic")[0];
2049 pic
.src
= pic
.src
.replace(/score_.*?\.png/,
2050 reply
["score_pic"]);
2051 pic
.setAttribute("score", score
);
2060 alert(__("No articles are selected."));
2063 exception_error("setSelectionScore", e
);
2067 function changeScore(id
, pic
) {
2069 var score
= pic
.getAttribute("score");
2071 var new_score
= prompt(__("Please enter new score for this article:"), score
);
2073 if (new_score
!= undefined) {
2075 var query
= "op=article&method=setScore&id=" + param_escape(id
) +
2076 "&score=" + param_escape(new_score
);
2078 new Ajax
.Request("backend.php", {
2080 onComplete: function(transport
) {
2081 var reply
= JSON
.parse(transport
.responseText
);
2084 pic
.src
= pic
.src
.replace(/score_.*?\.png/, reply
["score_pic"]);
2085 pic
.setAttribute("score", new_score
);
2090 exception_error("changeScore", e
);
2094 function displayArticleUrl(id
) {
2096 var query
= "op=rpc&method=getlinktitlebyid&id=" + param_escape(id
);
2098 new Ajax
.Request("backend.php", {
2100 onComplete: function(transport
) {
2101 var reply
= JSON
.parse(transport
.responseText
);
2103 if (reply
&& reply
.link
) {
2104 prompt(__("Article URL:"), reply
.link
);
2108 exception_error("changeScore", e
);
2112 function openSelectedAttachment(elem
) {
2114 var url
= elem
[elem
.selectedIndex
].value
;
2118 elem
.selectedIndex
= 0;
2122 exception_error("openSelectedAttachment", e
);