]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
1 var active_post_id
= false;
3 var article_cache
= new Array();
5 var vgroup_last_feed
= false;
6 var post_under_pointer
= false;
8 var last_requested_article
= false;
10 var catchup_id_batch
= [];
11 var catchup_timeout_id
= false;
12 var feed_precache_timeout_id
= false;
13 var precache_idle_timeout_id
= false;
15 var cids_requested
= [];
17 var has_storage
= 'sessionStorage' in window
&& window
['sessionStorage'] !== null;
19 function headlines_callback2(transport
, offset
, background
) {
21 handle_rpc_json(transport
);
23 loading_set_progress(25);
25 console
.log("headlines_callback2 [offset=" + offset
+ "] B:" + background
);
33 reply
= JSON
.parse(transport
.responseText
);
40 is_cat
= reply
['headlines']['is_cat'];
41 feed_id
= reply
['headlines']['id'];
44 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], reply
['headlines']['content']);
48 setActiveFeedId(feed_id
, is_cat
);
52 $("headlines-frame").scrollTop
= 0;
56 var headlines_count
= reply
['headlines-info']['count'];
58 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
60 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
61 _infscroll_disable
= 1;
63 _infscroll_disable
= 0;
66 var counters
= reply
['counters'];
67 var articles
= reply
['articles'];
68 var runtime_info
= reply
['runtime-info'];
71 dijit
.byId("headlines-frame").attr('content',
72 reply
['headlines']['content']);
74 dijit
.byId("headlines-toolbar").attr('content',
75 reply
['headlines']['toolbar']);
77 var hsp
= $("headlines-spacer");
78 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
80 dijit
.byId('headlines-frame').domNode
.appendChild(hsp
);
85 if (headlines_count
> 0) {
86 console
.log("adding some more headlines...");
88 var c
= dijit
.byId("headlines-frame");
89 var ids
= getSelectedArticleIds2();
91 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
93 var hsp
= $("headlines-spacer");
96 c
.domNode
.removeChild(hsp
);
98 $$("#headlines-tmp > div").each(function(row
) {
99 row
.style
.display
= 'none';
100 c
.domNode
.appendChild(row
);
103 if (!hsp
) hsp
= new Element("DIV", {"id": "headlines-spacer"});
105 fixHeadlinesOrder(getLoadedArticleIds());
107 c
.domNode
.appendChild(hsp
);
109 console
.log("restore selected ids: " + ids
);
111 for (var i
= 0; i
< ids
.length
; i
++) {
112 markHeadline(ids
[i
]);
117 $$("#headlines-frame > div[id*=RROW]").each(
119 if (!Element
.visible(child
))
120 new Effect
.Appear(child
, { duration
: 0.5 });
124 console
.log("no new headlines received");
126 var hsp
= $("headlines-spacer");
128 if (hsp
) hsp
.innerHTML
= "";
132 if (headlines_count
> 0)
133 cache_headlines(feed_id
, is_cat
, reply
['headlines']['toolbar'], $("headlines-frame").innerHTML
);
136 for (var i
= 0; i
< articles
.length
; i
++) {
137 var a_id
= articles
[i
]['id'];
138 cache_set("article:" + a_id
, articles
[i
]['content']);
141 console
.log("no cached articles received");
144 // do not precache stuff after fresh feed
146 precache_headlines();
149 parse_counters(counters
);
154 console
.warn("headlines_callback: returned no XML object");
155 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
156 __('Could not update headlines (invalid object received)') + "</div>");
159 _infscroll_request_sent
= 0;
164 exception_error("headlines_callback2", e
, transport
);
168 function render_article(article
) {
170 dijit
.byId("headlines-wrap-inner").addChild(
171 dijit
.byId("content-insert"));
173 var c
= dijit
.byId("content-insert");
176 c
.domNode
.scrollTop
= 0;
179 c
.attr('content', article
);
181 correctHeadlinesOffset(getActiveArticleId());
188 exception_error("render_article", e
);
192 function showArticleInHeadlines(id
) {
196 selectArticles("none");
198 var crow
= $("RROW-" + id
);
202 var article_is_unread
= crow
.hasClassName("Unread");
204 crow
.removeClassName("Unread");
206 selectArticles('none');
208 var upd_img_pic
= $("FUPDPIC-" + id
);
210 var view_mode
= false;
213 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
214 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
219 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
220 upd_img_pic
.src
.match("fresh_sign.png"))) {
222 upd_img_pic
.src
= "images/blank_icon.gif";
224 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
226 } else if (article_is_unread
&& view_mode
== "all_articles") {
227 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
232 if (article_is_unread
)
233 _force_scheduled_update
= true;
236 exception_error("showArticleInHeadlines", e
);
240 function article_callback2(transport
, id
) {
242 console
.log("article_callback2 " + id
);
244 handle_rpc_json(transport
);
246 var reply
= JSON
.parse(transport
.responseText
);
250 var upic
= $('FUPDPIC-' + id
);
252 if (upic
) upic
.src
= 'images/blank_icon.gif';
254 reply
.each(function(article
) {
255 if (active_post_id
== article
['id']) {
256 render_article(article
['content']);
258 cids_requested
.remove(article
['id']);
260 cache_set("article:" + article
['id'], article
['content']);
263 // if (id != last_requested_article) {
264 // console.log("requested article id is out of sequence, aborting");
269 console
.warn("article_callback: returned invalid data");
271 render_article("<div class='whiteBox'>" +
272 __('Could not display article (invalid data received)') + "</div>");
278 if (!_infscroll_disable
&&
279 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
289 exception_error("article_callback2", e
, transport
);
295 console
.log("loading article: " + id
);
297 var cached_article
= cache_get("article:" + id
);
299 console
.log("cache check result: " + (cached_article
!= false));
303 var query
= "?op=view&id=" + param_escape(id
);
305 var neighbor_ids
= getRelativePostIds(id
);
307 /* only request uncached articles */
309 var cids_to_request
= [];
311 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
312 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
313 if (!cache_get("article:" + neighbor_ids
[i
])) {
314 cids_to_request
.push(neighbor_ids
[i
]);
315 cids_requested
.push(neighbor_ids
[i
]);
319 console
.log("additional ids: " + cids_to_request
.toString());
321 query
= query
+ "&cids=" + cids_to_request
.toString();
323 var crow
= $("RROW-" + id
);
324 var article_is_unread
= crow
.hasClassName("Unread");
327 showArticleInHeadlines(id
);
329 precache_headlines();
331 if (!cached_article
) {
333 var upic
= $('FUPDPIC-' + id
);
336 upic
.src
= getInitParam("sign_progress");
339 } else if (cached_article
&& article_is_unread
) {
341 query
= query
+ "&mode=prefetch";
343 render_article(cached_article
);
345 } else if (cached_article
) {
347 query
= query
+ "&mode=prefetch_old";
348 render_article(cached_article
);
350 // if we don't need to request any relative ids, we might as well skip
351 // the server roundtrip altogether
352 if (cids_to_request
.length
== 0) {
355 if (!_infscroll_disable
&&
356 $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) {
368 last_requested_article
= id
;
372 new Ajax
.Request("backend.php", {
374 onComplete: function(transport
) {
375 article_callback2(transport
, id
);
381 exception_error("view", e
);
386 return toggleMark(id
);
390 return togglePub(id
);
393 function toggleMark(id
, client_only
) {
395 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
397 var img
= $("FMPIC-" + id
);
401 if (img
.src
.match("mark_unset")) {
402 img
.src
= img
.src
.replace("mark_unset", "mark_set");
403 img
.alt
= __("Unstar article");
404 query
= query
+ "&mark=1";
407 img
.src
= img
.src
.replace("mark_set", "mark_unset");
408 img
.alt
= __("Star article");
409 query
= query
+ "&mark=0";
412 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
415 new Ajax
.Request("backend.php", {
417 onComplete: function(transport
) {
418 handle_rpc_json(transport
);
423 exception_error("toggleMark", e
);
427 function togglePub(id
, client_only
, no_effects
, note
) {
429 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
431 if (note
!= undefined) {
432 query
= query
+ "¬e=" + param_escape(note
);
434 query
= query
+ "¬e=undefined";
437 var img
= $("FPPIC-" + id
);
441 if (img
.src
.match("pub_unset") || note
!= undefined) {
442 img
.src
= img
.src
.replace("pub_unset", "pub_set");
443 img
.alt
= __("Unpublish article");
444 query
= query
+ "&pub=1";
447 img
.src
= img
.src
.replace("pub_set", "pub_unset");
448 img
.alt
= __("Publish article");
450 query
= query
+ "&pub=0";
453 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
456 new Ajax
.Request("backend.php", {
458 onComplete: function(transport
) {
459 handle_rpc_json(transport
);
464 exception_error("togglePub", e
);
468 function moveToPost(mode
) {
472 var rows
= getVisibleArticleIds();
477 if (!$('RROW-' + active_post_id
)) {
478 active_post_id
= false;
481 if (active_post_id
== false) {
482 next_id
= getFirstVisibleHeadlineId();
483 prev_id
= getLastVisibleHeadlineId();
485 for (var i
= 0; i
< rows
.length
; i
++) {
486 if (rows
[i
] == active_post_id
) {
493 if (mode
== "next") {
497 cdmExpandArticle(next_id
);
498 cdmScrollToArticleId(next_id
);
501 correctHeadlinesOffset(next_id
);
502 view(next_id
, getActiveFeedId());
507 if (mode
== "prev") {
510 cdmExpandArticle(prev_id
);
511 cdmScrollToArticleId(prev_id
);
513 correctHeadlinesOffset(prev_id
);
514 view(prev_id
, getActiveFeedId());
520 exception_error("moveToPost", e
);
524 function toggleSelected(id
, force_on
) {
527 var cb
= $("RCHK-" + id
);
528 var row
= $("RROW-" + id
);
531 if (row
.hasClassName('Selected') && !force_on
) {
532 row
.removeClassName('Selected');
533 if (cb
) cb
.checked
= false;
535 row
.addClassName('Selected');
536 if (cb
) cb
.checked
= true;
540 exception_error("toggleSelected", e
);
544 function toggleUnread_afh(effect
) {
547 var elem
= effect
.element
;
548 elem
.style
.backgroundColor
= "";
551 exception_error("toggleUnread_afh", e
);
555 function toggleUnread(id
, cmode
, effect
) {
558 var row
= $("RROW-" + id
);
560 if (cmode
== undefined || cmode
== 2) {
561 if (row
.hasClassName("Unread")) {
562 row
.removeClassName("Unread");
565 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
566 afterFinish
: toggleUnread_afh
,
567 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
571 row
.addClassName("Unread");
574 } else if (cmode
== 0) {
576 row
.removeClassName("Unread");
579 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
580 afterFinish
: toggleUnread_afh
,
581 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
584 } else if (cmode
== 1) {
585 row
.addClassName("Unread");
588 if (cmode
== undefined) cmode
= 2;
590 var query
= "?op=rpc&subop=catchupSelected" +
591 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
593 // notify_progress("Loading, please wait...");
595 new Ajax
.Request("backend.php", {
597 onComplete: function(transport
) {
598 handle_rpc_json(transport
);
604 exception_error("toggleUnread", e
);
608 function selectionRemoveLabel(id
, ids
) {
611 if (!ids
) var ids
= getSelectedArticleIds2();
613 if (ids
.length
== 0) {
614 alert(__("No articles are selected."));
618 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
619 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
623 new Ajax
.Request("backend.php", {
625 onComplete: function(transport
) {
626 handle_rpc_json(transport
);
627 show_labels_in_headlines(transport
);
631 exception_error("selectionAssignLabel", e
);
636 function selectionAssignLabel(id
, ids
) {
639 if (!ids
) ids
= getSelectedArticleIds2();
641 if (ids
.length
== 0) {
642 alert(__("No articles are selected."));
646 var query
= "?op=rpc&subop=assignToLabel&ids=" +
647 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
651 new Ajax
.Request("backend.php", {
653 onComplete: function(transport
) {
654 handle_rpc_json(transport
);
655 show_labels_in_headlines(transport
);
659 exception_error("selectionAssignLabel", e
);
664 function selectionToggleUnread(set_state
, callback
, no_error
) {
666 var rows
= getSelectedArticleIds2();
668 if (rows
.length
== 0 && !no_error
) {
669 alert(__("No articles are selected."));
673 for (i
= 0; i
< rows
.length
; i
++) {
674 var row
= $("RROW-" + rows
[i
]);
676 if (set_state
== undefined) {
677 if (row
.hasClassName("Unread")) {
678 row
.removeClassName("Unread");
680 row
.addClassName("Unread");
684 if (set_state
== false) {
685 row
.removeClassName("Unread");
688 if (set_state
== true) {
689 row
.addClassName("Unread");
694 if (rows
.length
> 0) {
698 if (set_state
== undefined) {
700 } else if (set_state
== true) {
702 } else if (set_state
== false) {
706 var query
= "?op=rpc&subop=catchupSelected" +
707 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
709 notify_progress("Loading, please wait...");
711 new Ajax
.Request("backend.php", {
713 onComplete: function(transport
) {
714 handle_rpc_json(transport
);
715 if (callback
) callback(transport
);
721 exception_error("selectionToggleUnread", e
);
725 function selectionToggleMarked() {
728 var rows
= getSelectedArticleIds2();
730 if (rows
.length
== 0) {
731 alert(__("No articles are selected."));
735 for (i
= 0; i
< rows
.length
; i
++) {
736 toggleMark(rows
[i
], true, true);
739 if (rows
.length
> 0) {
741 var query
= "?op=rpc&subop=markSelected&ids=" +
742 param_escape(rows
.toString()) + "&cmode=2";
744 new Ajax
.Request("backend.php", {
746 onComplete: function(transport
) {
747 handle_rpc_json(transport
);
753 exception_error("selectionToggleMarked", e
);
757 function selectionTogglePublished() {
760 var rows
= getSelectedArticleIds2();
762 if (rows
.length
== 0) {
763 alert(__("No articles are selected."));
767 for (i
= 0; i
< rows
.length
; i
++) {
768 togglePub(rows
[i
], true, true);
771 if (rows
.length
> 0) {
773 var query
= "?op=rpc&subop=publishSelected&ids=" +
774 param_escape(rows
.toString()) + "&cmode=2";
776 new Ajax
.Request("backend.php", {
778 onComplete: function(transport
) {
779 handle_rpc_json(transport
);
785 exception_error("selectionToggleMarked", e
);
789 function getSelectedArticleIds2() {
793 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
795 rv
.push(child
.id
.replace("RROW-", ""));
801 function getLoadedArticleIds() {
804 var children
= $$("#headlines-frame > div[id*=RROW-]");
806 children
.each(function(child
) {
807 rv
.push(child
.id
.replace("RROW-", ""));
814 // mode = all,none,unread,invert
815 function selectArticles(mode
) {
818 var children
= $$("#headlines-frame > div[id*=RROW]");
820 children
.each(function(child
) {
821 var id
= child
.id
.replace("RROW-", "");
822 var cb
= $("RCHK-" + id
);
825 child
.addClassName("Selected");
827 } else if (mode
== "unread") {
828 if (child
.hasClassName("Unread")) {
829 child
.addClassName("Selected");
832 child
.removeClassName("Selected");
835 } else if (mode
== "invert") {
836 if (child
.hasClassName("Selected")) {
837 child
.removeClassName("Selected");
840 child
.addClassName("Selected");
845 child
.removeClassName("Selected");
851 exception_error("selectArticles", e
);
855 function catchupPage() {
857 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
859 var str
= __("Mark all visible articles in %s as read?");
861 str
= str
.replace("%s", fn
);
863 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
867 selectArticles('all');
868 selectionToggleUnread(false, 'viewCurrentFeed()', true)
869 selectArticles('none');
872 function deleteSelection() {
876 var rows
= getSelectedArticleIds2();
878 if (rows
.length
== 0) {
879 alert(__("No articles are selected."));
883 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
887 if (getActiveFeedId() != 0) {
888 str
= __("Delete %d selected articles in %s?");
890 str
= __("Delete %d selected articles?");
893 str
= str
.replace("%d", rows
.length
);
894 str
= str
.replace("%s", fn
);
896 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
900 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
904 new Ajax
.Request("backend.php", {
906 onComplete: function(transport
) {
907 handle_rpc_json(transport
);
912 exception_error("deleteSelection", e
);
916 function archiveSelection() {
920 var rows
= getSelectedArticleIds2();
922 if (rows
.length
== 0) {
923 alert(__("No articles are selected."));
927 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
931 if (getActiveFeedId() != 0) {
932 str
= __("Archive %d selected articles in %s?");
935 str
= __("Move %d archived articles back?");
939 str
= str
.replace("%d", rows
.length
);
940 str
= str
.replace("%s", fn
);
942 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
946 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
950 for (var i
= 0; i
< rows
.length
; i
++) {
951 cache_delete("article:" + rows
[i
]);
954 new Ajax
.Request("backend.php", {
956 onComplete: function(transport
) {
957 handle_rpc_json(transport
);
962 exception_error("archiveSelection", e
);
966 function catchupSelection() {
970 var rows
= getSelectedArticleIds2();
972 if (rows
.length
== 0) {
973 alert(__("No articles are selected."));
977 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
979 var str
= __("Mark %d selected articles in %s as read?");
981 str
= str
.replace("%d", rows
.length
);
982 str
= str
.replace("%s", fn
);
984 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
988 selectionToggleUnread(false, 'viewCurrentFeed()', true)
991 exception_error("catchupSelection", e
);
995 function editArticleTags(id
) {
996 var query
= "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id
);
998 if (dijit
.byId("editTagsDlg"))
999 dijit
.byId("editTagsDlg").destroyRecursive();
1001 dialog
= new dijit
.Dialog({
1003 title
: __("Edit article Tags"),
1004 style
: "width: 600px",
1005 execute: function() {
1006 if (this.validate()) {
1007 var query
= dojo
.objectToQuery(this.attr('value'));
1009 notify_progress("Saving article tags...", true);
1011 new Ajax
.Request("backend.php", {
1013 onComplete: function(transport
) {
1017 var data
= JSON
.parse(transport
.responseText
);
1020 var tags_str
= article
.tags
;
1021 var id
= tags_str
.id
;
1023 var tags
= $("ATSTR-" + id
);
1024 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
1026 if (tags
) tags
.innerHTML
= tags_str
.content
;
1027 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1029 cache_delete("article:" + id
);
1038 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1039 dojo
.disconnect(tmph
);
1041 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1042 "backend.php?op=rpc&subop=completeTags",
1043 { tokens
: ',', paramName
: "search" });
1050 function cdmScrollToArticleId(id
) {
1052 var ctr
= $("headlines-frame");
1053 var e
= $("RROW-" + id
);
1055 if (!e
|| !ctr
) return;
1057 ctr
.scrollTop
= e
.offsetTop
;
1060 exception_error("cdmScrollToArticleId", e
);
1064 function getActiveArticleId() {
1065 return active_post_id
;
1068 function postMouseIn(id
) {
1069 post_under_pointer
= id
;
1072 function postMouseOut(id
) {
1073 post_under_pointer
= false;
1076 function headlines_scroll_handler(e
) {
1078 var hsp
= $("headlines-spacer");
1080 if (!_infscroll_disable
) {
1081 if (hsp
&& (e
.scrollTop
+ e
.offsetHeight
> hsp
.offsetTop
) ||
1082 e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1084 hsp
.innerHTML
= "<img src='images/indicator_tiny.gif'> " +
1085 __("Loading, please wait...");
1087 loadMoreHeadlines();
1089 //viewNextFeedPage();
1092 if (hsp
) hsp
.innerHTML
= "";
1095 if (getInitParam("cdm_auto_catchup") == 1) {
1097 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1099 if ($("headlines-frame").scrollTop
>
1100 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1102 var id
= child
.id
.replace("RROW-", "");
1104 if (catchup_id_batch
.indexOf(id
) == -1)
1105 catchup_id_batch
.push(id
);
1109 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1110 window
.clearTimeout(catchup_timeout_id
);
1111 catchup_timeout_id
= window
.setTimeout('catchupBatchedArticles()',
1117 console
.warn("headlines_scroll_handler: " + e
);
1121 function catchupBatchedArticles() {
1123 if (catchup_id_batch
.length
> 0 && !_infscroll_request_sent
) {
1125 var query
= "?op=rpc&subop=catchupSelected" +
1126 "&cmode=0&ids=" + param_escape(catchup_id_batch
.toString());
1128 new Ajax
.Request("backend.php", {
1130 onComplete: function(transport
) {
1131 handle_rpc_json(transport
);
1133 catchup_id_batch
.each(function(id
) {
1134 var elem
= $("RROW-" + id
);
1135 if (elem
) elem
.removeClassName("Unread");
1138 catchup_id_batch
= [];
1143 exception_error("catchupBatchedArticles", e
);
1147 function catchupRelativeToArticle(below
) {
1152 if (!getActiveArticleId()) {
1153 alert(__("No article is selected."));
1157 var visible_ids
= getVisibleArticleIds();
1159 var ids_to_mark
= new Array();
1162 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1163 if (visible_ids
[i
] != getActiveArticleId()) {
1164 var e
= $("RROW-" + visible_ids
[i
]);
1166 if (e
&& e
.hasClassName("Unread")) {
1167 ids_to_mark
.push(visible_ids
[i
]);
1174 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1175 if (visible_ids
[i
] != getActiveArticleId()) {
1176 var e
= $("RROW-" + visible_ids
[i
]);
1178 if (e
&& e
.hasClassName("Unread")) {
1179 ids_to_mark
.push(visible_ids
[i
]);
1187 if (ids_to_mark
.length
== 0) {
1188 alert(__("No articles found to mark"));
1190 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1192 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1194 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1195 var e
= $("RROW-" + ids_to_mark
[i
]);
1196 e
.removeClassName("Unread");
1199 var query
= "?op=rpc&subop=catchupSelected" +
1200 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1202 new Ajax
.Request("backend.php", {
1204 onComplete: function(transport
) {
1205 handle_rpc_json(transport
);
1212 exception_error("catchupRelativeToArticle", e
);
1216 function cdmExpandArticle(id
) {
1221 var elem
= $("CICD-" + active_post_id
);
1223 var upd_img_pic
= $("FUPDPIC-" + id
);
1225 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1226 upd_img_pic
.src
.match("fresh_sign.png"))) {
1228 upd_img_pic
.src
= "images/blank_icon.gif";
1231 if (id
== active_post_id
&& Element
.visible(elem
))
1234 selectArticles("none");
1236 var old_offset
= $("RROW-" + id
).offsetTop
;
1238 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1240 Element
.show("CEXC-" + active_post_id
);
1243 active_post_id
= id
;
1245 elem
= $("CICD-" + id
);
1247 if (!Element
.visible(elem
)) {
1249 Element
.hide("CEXC-" + id
);
1251 if ($("CWRAP-" + id
).innerHTML
== "") {
1253 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1255 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1256 __("Loading, please wait...") + "</div>";
1258 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1260 var neighbor_ids
= getRelativePostIds(id
);
1262 /* only request uncached articles */
1263 var cids_to_request
= [];
1265 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1266 if (cids_requested
.indexOf(neighbor_ids
[i
]) == -1)
1267 if ($("CWRAP-" + neighbor_ids
[i
]).innerHTML
== "") {
1268 cids_to_request
.push(neighbor_ids
[i
]);
1269 cids_requested
.push(neighbor_ids
[i
]);
1273 console
.log("additional ids: " + cids_to_request
.toString());
1275 query
= query
+ "&cids=" + cids_to_request
.toString();
1279 new Ajax
.Request("backend.php", {
1281 onComplete: function(transport
) {
1283 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1285 handle_rpc_json(transport
);
1287 var reply
= JSON
.parse(transport
.responseText
);
1289 reply
.each(function(article
) {
1290 $("CWRAP-" + article
['id']).innerHTML
= article
['content']
1291 cids_requested
.remove(article
['id']);
1298 var new_offset
= $("RROW-" + id
).offsetTop
;
1300 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1302 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1303 $("headlines-frame").scrollTop
= new_offset
;
1305 toggleUnread(id
, 0, true);
1309 exception_error("cdmExpandArticle", e
);
1315 function fixHeadlinesOrder(ids
) {
1317 for (var i
= 0; i
< ids
.length
; i
++) {
1318 var e
= $("RROW-" + ids
[i
]);
1322 e
.removeClassName("even");
1323 e
.addClassName("odd");
1325 e
.removeClassName("odd");
1326 e
.addClassName("even");
1331 exception_error("fixHeadlinesOrder", e
);
1335 function getArticleUnderPointer() {
1336 return post_under_pointer
;
1339 function zoomToArticle(event
, id
) {
1341 var cached_article
= cache_get("article: " + id
);
1343 if (dijit
.byId("ATAB-" + id
))
1344 if (!event
|| !event
.shiftKey
)
1345 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1347 if (dijit
.byId("ATSTRTIP-" + id
))
1348 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1350 if (cached_article
) {
1351 //closeArticlePanel();
1353 var article_pane
= new dijit
.layout
.ContentPane({
1354 title
: __("Loading...") , content
: cached_article
,
1355 style
: 'padding : 0px;',
1359 dijit
.byId("content-tabs").addChild(article_pane
);
1361 if (!event
|| !event
.shiftKey
)
1362 dijit
.byId("content-tabs").selectChild(article_pane
);
1364 if ($("PTITLE-" + id
))
1365 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1369 var query
= "?op=rpc&subop=getArticles&ids=" + param_escape(id
);
1371 notify_progress("Loading, please wait...", true);
1373 new Ajax
.Request("backend.php", {
1375 onComplete: function(transport
) {
1378 var reply
= JSON
.parse(transport
.responseText
);
1381 //closeArticlePanel();
1383 var content
= reply
[0]['content'];
1385 var article_pane
= new dijit
.layout
.ContentPane({
1386 title
: "article-" + id
, content
: content
,
1387 style
: 'padding : 0px;',
1391 dijit
.byId("content-tabs").addChild(article_pane
);
1393 if (!event
|| !event
.shiftKey
)
1394 dijit
.byId("content-tabs").selectChild(article_pane
);
1396 if ($("PTITLE-" + id
))
1397 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1404 exception_error("zoomToArticle", e
);
1408 function scrollArticle(offset
) {
1411 var ci
= $("content-insert");
1413 ci
.scrollTop
+= offset
;
1416 var hi
= $("headlines-frame");
1418 hi
.scrollTop
+= offset
;
1423 exception_error("scrollArticle", e
);
1427 function show_labels_in_headlines(transport
) {
1429 var data
= JSON
.parse(transport
.responseText
);
1432 data
['info-for-headlines'].each(function(elem
) {
1433 var ctr
= $("HLLCTR-" + elem
.id
);
1435 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1438 cache_headlines(getActiveFeedId(), activeFeedIsCat(), null, $("headlines-frame").innerHTML
);
1442 exception_error("show_labels_in_headlines", e
);
1446 /* function toggleHeadlineActions() {
1448 var e = $("headlineActionsBody");
1449 var p = $("headlineActionsDrop");
1451 if (!Element.visible(e)) {
1458 e.style.left = (p.offsetLeft + 1) + "px";
1459 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
1462 exception_error("toggleHeadlineActions", e);
1466 /* function publishWithNote(id, def_note) {
1468 if (!def_note) def_note = '';
1470 var note = prompt(__("Please enter a note for this article:"), def_note);
1472 if (note != undefined) {
1473 togglePub(id, false, false, note);
1477 exception_error("publishWithNote", e);
1481 function emailArticle(id
) {
1484 var ids
= getSelectedArticleIds2();
1486 if (ids
.length
== 0) {
1487 alert(__("No articles are selected."));
1491 id
= ids
.toString();
1494 if (dijit
.byId("emailArticleDlg"))
1495 dijit
.byId("emailArticleDlg").destroyRecursive();
1497 var query
= "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id
);
1499 dialog
= new dijit
.Dialog({
1500 id
: "emailArticleDlg",
1501 title
: __("Forward article by email"),
1502 style
: "width: 600px",
1503 execute: function() {
1504 if (this.validate()) {
1506 new Ajax
.Request("backend.php", {
1507 parameters
: dojo
.objectToQuery(this.attr('value')),
1508 onComplete: function(transport
) {
1510 var reply
= JSON
.parse(transport
.responseText
);
1512 var error
= reply
['error'];
1515 alert(__('Error sending email:') + ' ' + error
);
1517 notify_info('Your message has been sent.');
1526 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1527 dojo
.disconnect(tmph
);
1529 new Ajax
.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1530 "backend.php?op=rpc&subop=completeEmails",
1531 { tokens
: '', paramName
: "search" });
1536 /* displayDlg('emailArticle', id,
1538 document.forms['article_email_form'].destination.focus();
1540 new Ajax.Autocompleter('destination', 'destination_choices',
1541 "backend.php?op=rpc&subop=completeEmails",
1542 { tokens: '', paramName: "search" });
1547 exception_error("emailArticle", e
);
1551 function dismissArticle(id
) {
1553 var elem
= $("RROW-" + id
);
1555 toggleUnread(id
, 0, true);
1557 new Effect
.Fade(elem
, {duration
: 0.5});
1559 active_post_id
= false;
1562 exception_error("dismissArticle", e
);
1566 function dismissSelectedArticles() {
1569 var ids
= getVisibleArticleIds();
1573 for (var i
= 0; i
< ids
.length
; i
++) {
1574 var elem
= $("RROW-" + ids
[i
]);
1576 if (elem
.className
&& elem
.hasClassName("Selected") &&
1577 ids
[i
] != active_post_id
) {
1578 new Effect
.Fade(elem
, {duration
: 0.5});
1586 selectionToggleUnread(false);
1588 fixHeadlinesOrder(tmp
);
1591 exception_error("dismissSelectedArticles", e
);
1595 function dismissReadArticles() {
1598 var ids
= getVisibleArticleIds();
1601 for (var i
= 0; i
< ids
.length
; i
++) {
1602 var elem
= $("RROW-" + ids
[i
]);
1604 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1605 !elem
.hasClassName("Selected")) {
1607 new Effect
.Fade(elem
, {duration
: 0.5});
1613 fixHeadlinesOrder(tmp
);
1616 exception_error("dismissSelectedArticles", e
);
1620 function getVisibleArticleIds() {
1625 getLoadedArticleIds().each(function(id
) {
1626 var elem
= $("RROW-" + id
);
1627 if (elem
&& Element
.visible(elem
))
1632 exception_error("getVisibleArticleIds", e
);
1638 function cdmClicked(event
, id
) {
1640 var shift_key
= event
.shiftKey
;
1644 if (!event
.ctrlKey
) {
1646 if (!getInitParam("cdm_expanded")) {
1647 return cdmExpandArticle(id
);
1650 selectArticles("none");
1653 var elem
= $("RROW-" + id
);
1656 elem
.removeClassName("Unread");
1658 var upd_img_pic
= $("FUPDPIC-" + id
);
1660 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1661 upd_img_pic
.src
.match("fresh_sign.png"))) {
1663 upd_img_pic
.src
= "images/blank_icon.gif";
1666 active_post_id
= id
;
1668 var query
= "?op=rpc&subop=catchupSelected" +
1669 "&cmode=0&ids=" + param_escape(id
);
1671 new Ajax
.Request("backend.php", {
1673 onComplete: function(transport
) {
1674 handle_rpc_json(transport
);
1681 toggleSelected(id
, true);
1682 toggleUnread(id
, 0, false);
1683 zoomToArticle(event
, id
);
1687 exception_error("cdmClicked");
1693 function postClicked(event
, id
) {
1696 if (!event
.ctrlKey
) {
1699 postOpenInNewTab(event
, id
);
1704 exception_error("postClicked");
1708 function hlOpenInNewTab(event
, id
) {
1709 toggleUnread(id
, 0, false);
1710 zoomToArticle(event
, id
);
1713 function postOpenInNewTab(event
, id
) {
1714 closeArticlePanel(id
);
1715 zoomToArticle(event
, id
);
1718 function hlClicked(event
, id
) {
1720 if (event
.which
== 2) {
1723 } else if (event
.altKey
) {
1724 openArticleInNewWindow(id
);
1725 } else if (!event
.ctrlKey
) {
1730 toggleUnread(id
, 0, false);
1731 zoomToArticle(event
, id
);
1736 exception_error("hlClicked");
1740 function getFirstVisibleHeadlineId() {
1741 var rows
= getVisibleArticleIds();
1746 function getLastVisibleHeadlineId() {
1747 var rows
= getVisibleArticleIds();
1748 return rows
[rows
.length
-1];
1751 function openArticleInNewWindow(id
) {
1752 toggleUnread(id
, 0, false);
1753 window
.open("backend.php?op=la&id=" + id
);
1756 function isCdmMode() {
1757 return getInitParam("combined_display_mode");
1760 function markHeadline(id
) {
1761 var row
= $("RROW-" + id
);
1763 var check
= $("RCHK-" + id
);
1766 check
.checked
= true;
1769 row
.addClassName("Selected");
1773 function getRelativePostIds(id
, limit
) {
1779 if (!limit
) limit
= 6; //3
1781 var ids
= getVisibleArticleIds();
1783 for (var i
= 0; i
< ids
.length
; i
++) {
1785 for (var k
= 1; k
<= limit
; k
++) {
1786 //if (i > k-1) tmp.push(ids[i-k]);
1787 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1794 exception_error("getRelativePostIds", e
);
1800 function correctHeadlinesOffset(id
) {
1804 var container
= $("headlines-frame");
1805 var row
= $("RROW-" + id
);
1807 var viewport
= container
.offsetHeight
;
1809 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1810 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
1812 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1813 //console.log("Vport: " + viewport);
1815 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
1816 container
.scrollTop
= row
.offsetTop
;
1817 } else if (rel_offset_bottom
> viewport
) {
1819 /* doesn't properly work with Opera in some cases because
1820 Opera fucks up element scrolling */
1822 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
1826 exception_error("correctHeadlinesOffset", e
);
1831 function headlineActionsChange(elem
) {
1834 elem
.attr('value', 'false');
1836 exception_error("headlineActionsChange", e
);
1840 function closeArticlePanel() {
1842 var tabs
= dijit
.byId("content-tabs");
1843 var child
= tabs
.selectedChildWidget
;
1845 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
1846 tabs
.removeChild(child
);
1849 if (dijit
.byId("content-insert"))
1850 dijit
.byId("headlines-wrap-inner").removeChild(
1851 dijit
.byId("content-insert"));
1855 function initHeadlinesMenu() {
1857 if (dijit
.byId("headlinesMenu"))
1858 dijit
.byId("headlinesMenu").destroyRecursive();
1863 nodes
= $$("#headlines-frame > div[id*=RROW]");
1865 nodes
= $$("#headlines-frame span[id*=RTITLE]");
1868 nodes
.each(function(node
) {
1872 var menu
= new dijit
.Menu({
1873 id
: "headlinesMenu",
1877 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
1878 var callerNode
= event
.target
, match
= null, tries
= 0;
1880 while (match
== null && callerNode
&& tries
<= 3) {
1881 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
1882 callerNode
= callerNode
.parentNode
;
1886 if (match
) this.callerRowId
= parseInt(match
[1]);
1890 /* if (!isCdmMode())
1891 menu.addChild(new dijit.MenuItem({
1892 label: __("View article"),
1893 onClick: function(event) {
1894 view(this.getParent().callerRowId);
1897 menu
.addChild(new dijit
.MenuItem({
1898 label
: __("Open original article"),
1899 onClick: function(event
) {
1900 openArticleInNewWindow(this.getParent().callerRowId
);
1903 menu
.addChild(new dijit
.MenuItem({
1904 label
: __("View in a tt-rss tab"),
1905 onClick: function(event
) {
1906 hlOpenInNewTab(event
, this.getParent().callerRowId
);
1909 // menu.addChild(new dijit.MenuSeparator());
1911 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
1915 menu
.addChild(new dijit
.MenuSeparator());
1917 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
1918 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
1920 labels
.each(function(label
) {
1921 var id
= label
.id
[0];
1922 var bare_id
= id
.substr(id
.indexOf(":")+1);
1923 var name
= label
.name
[0];
1925 bare_id
= -11-bare_id
;
1927 labelAddMenu
.addChild(new dijit
.MenuItem({
1930 onClick: function(event
) {
1931 selectionAssignLabel(this.labelId
,
1932 [this.getParent().ownerMenu
.callerRowId
]);
1935 labelDelMenu
.addChild(new dijit
.MenuItem({
1938 onClick: function(event
) {
1939 selectionRemoveLabel(this.labelId
,
1940 [this.getParent().ownerMenu
.callerRowId
]);
1945 menu
.addChild(new dijit
.PopupMenuItem({
1946 label
: __("Assign label"),
1947 popup
: labelAddMenu
,
1950 menu
.addChild(new dijit
.PopupMenuItem({
1951 label
: __("Remove label"),
1952 popup
: labelDelMenu
,
1960 exception_error("initHeadlinesMenu", e
);
1964 function tweetArticle(id
) {
1966 var query
= "?op=rpc&subop=getTweetInfo&id=" + param_escape(id
);
1971 var ts
= d
.getTime();
1973 var w
= window
.open('backend.php?op=loading', 'ttrss_tweet',
1974 "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
1976 new Ajax
.Request("backend.php", {
1978 onComplete: function(transport
) {
1979 var ti
= JSON
.parse(transport
.responseText
);
1981 var share_url
= "http://twitter.com/share?_=" + ts
+
1982 "&text=" + param_escape(ti
.title
) +
1983 "&url=" + param_escape(ti
.link
);
1985 w
.location
.href
= share_url
;
1991 exception_error("tweetArticle", e
);
1995 function editArticleNote(id
) {
1998 var query
= "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id
);
2000 if (dijit
.byId("editNoteDlg"))
2001 dijit
.byId("editNoteDlg").destroyRecursive();
2003 dialog
= new dijit
.Dialog({
2005 title
: __("Edit article note"),
2006 style
: "width: 600px",
2007 execute: function() {
2008 if (this.validate()) {
2009 var query
= dojo
.objectToQuery(this.attr('value'));
2011 notify_progress("Saving article note...", true);
2013 new Ajax
.Request("backend.php", {
2015 onComplete: function(transport
) {
2019 var reply
= JSON
.parse(transport
.responseText
);
2021 cache_delete("article:" + id
);
2023 var elem
= $("POSTNOTE-" + id
);
2027 elem
.innerHTML
= reply
.note
;
2029 if (reply
.raw_length
!= 0)
2030 new Effect
.Appear(elem
);
2042 exception_error("editArticleNote", e
);
2046 function player(elem
) {
2047 var aid
= elem
.getAttribute("audio-id");
2048 var status
= elem
.getAttribute("status");
2056 elem
.innerHTML
= __("Playing...");
2057 elem
.title
= __("Click to pause");
2058 elem
.addClassName("playing");
2062 elem
.innerHTML
= __("Play");
2063 elem
.title
= __("Click to play");
2064 elem
.removeClassName("playing");
2067 elem
.setAttribute("status", status
);
2069 alert("Your browser doesn't seem to support HTML5 audio.");
2073 function cache_set(id
, obj
) {
2074 //console.log("cache_set: " + id);
2077 sessionStorage
[id
] = obj
;
2079 sessionStorage
.clear();
2083 function cache_get(id
) {
2085 return sessionStorage
[id
];
2088 function cache_clear() {
2090 sessionStorage
.clear();
2093 function cache_delete(id
) {
2095 sessionStorage
.removeItem(id
);
2098 function cache_headlines(feed
, is_cat
, toolbar_obj
, content_obj
) {
2099 if (toolbar_obj
&& content_obj
) {
2100 cache_set("feed:" + feed
+ ":" + is_cat
,
2101 JSON
.stringify({toolbar
: toolbar_obj
, content
: content_obj
}));
2104 obj
= cache_get("feed:" + feed
+ ":" + is_cat
);
2107 obj
= JSON
.parse(obj
);
2109 if (toolbar_obj
) obj
.toolbar
= toolbar_obj
;
2110 if (content_obj
) obj
.content
= content_obj
;
2112 cache_set("feed:" + feed
+ ":" + is_cat
, JSON
.stringify(obj
));
2116 console
.warn("cache_headlines failed: " + e
);
2121 function render_local_headlines(feed
, is_cat
, obj
) {
2124 dijit
.byId("headlines-toolbar").attr('content',
2127 dijit
.byId("headlines-frame").attr('content',
2130 dojo
.parser
.parse('headlines-toolbar');
2132 $("headlines-frame").scrollTop
= 0;
2133 selectArticles('none');
2134 setActiveFeedId(feed
, is_cat
);
2135 initHeadlinesMenu();
2137 precache_headlines();
2140 exception_error("render_local_headlines", e
);
2144 function precache_headlines_idle() {
2146 if (!feed_precache_timeout_id
) {
2147 var feeds
= dijit
.byId("feedTree").getVisibleUnreadFeeds();
2150 feeds
.each(function(item
) {
2151 if (parseInt(item
[0]) > 0 && !cache_get("feed:" + item
[0] + ":" + item
[1]))
2152 uncached
.push(item
);
2155 if (uncached
.length
> 0) {
2156 var rf
= uncached
[Math
.floor(Math
.random()*uncached
.length
)];
2157 viewfeed(rf
[0], '', rf
[1], 0, true);
2160 precache_idle_timeout_id
= setTimeout("precache_headlines_idle()", 5000);
2163 exception_error("precache_headlines_idle", e
);
2167 function precache_headlines() {
2170 if (!feed_precache_timeout_id
) {
2171 feed_precache_timeout_id
= window
.setTimeout(function() {
2172 var nuf
= getNextUnreadFeed(getActiveFeedId(), activeFeedIsCat());
2173 var nf
= dijit
.byId("feedTree").getNextFeed(getActiveFeedId(), activeFeedIsCat());
2175 if (nuf
&& !cache_get("feed:" + nuf
+ ":" + activeFeedIsCat()))
2176 viewfeed(nuf
, '', activeFeedIsCat(), 0, true);
2178 if (nf
!= nuf
&& nf
&& !cache_get("feed:" + nf
[0] + ":" + nf
[1]))
2179 viewfeed(nf
[0], '', nf
[1], 0, true);
2181 window
.setTimeout(function() {
2182 feed_precache_timeout_id
= false;
2189 exception_error("precache_headlines", e
);