]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
fd188797674f08b310f1dac4ae09fe3d0440c529
1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var article_cache
= new Array();
7 var vgroup_last_feed
= false;
8 var post_under_pointer
= false;
10 var last_requested_article
= false;
12 var preload_id_batch
= [];
13 var preload_timeout_id
= false;
17 function headlines_callback2(transport
, feed_cur_page
) {
19 handle_rpc_json(transport
);
21 loading_set_progress(25);
23 console
.log("headlines_callback2 [page=" + feed_cur_page
+ "]");
31 reply
= JSON
.parse(transport
.responseText
);
38 is_cat
= reply
['headlines']['is_cat'];
39 feed_id
= reply
['headlines']['id'];
41 setActiveFeedId(feed_id
, is_cat
);
43 var update_btn
= document
.forms
["main_toolbar_form"].update
;
45 update_btn
.disabled
= !(feed_id
>= 0 && !is_cat
);
48 if (feed_cur_page
== 0) {
49 $("headlines-frame").scrollTop
= 0;
53 var headlines_count
= reply
['headlines-info']['count'];
54 var headlines_unread
= reply
['headlines-info']['unread'];
56 vgroup_last_feed
= reply
['headlines-info']['vgroup_last_feed'];
58 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
59 _infscroll_disable
= 1;
61 _infscroll_disable
= 0;
64 var counters
= reply
['counters'];
65 var articles
= reply
['articles'];
66 var runtime_info
= reply
['runtime-info'];
68 if (feed_cur_page
== 0) {
69 dijit
.byId("headlines-frame").attr('content',
70 reply
['headlines']['content']);
72 dijit
.byId("headlines-toolbar").attr('content',
73 reply
['headlines']['toolbar']);
78 if (headlines_count
> 0) {
79 console
.log("adding some more headlines...");
81 var c
= dijit
.byId("headlines-frame");
82 var ids
= getSelectedArticleIds2();
84 $("headlines-tmp").innerHTML
= reply
['headlines']['content'];
86 $$("#headlines-tmp > div").each(function(row
) {
87 c
.domNode
.appendChild(row
);
90 console
.log("restore selected ids: " + ids
);
92 for (var i
= 0; i
< ids
.length
; i
++) {
99 console
.log("no new headlines received");
104 for (var i
= 0; i
< articles
.length
; i
++) {
105 var a_id
= articles
[i
]['id'];
106 cache_inject(a_id
, articles
[i
]['content']);
109 console
.log("no cached articles received");
113 parse_counters(counters
);
118 console
.warn("headlines_callback: returned no XML object");
119 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
120 __('Could not update headlines (invalid object received)') + "</div>");
123 _feed_cur_page
= feed_cur_page
;
124 _infscroll_request_sent
= 0;
129 exception_error("headlines_callback2", e
, transport
);
133 function render_article(article
) {
135 dijit
.byId("headlines-wrap-inner").addChild(
136 dijit
.byId("content-insert"));
138 var c
= dijit
.byId("content-insert");
141 c
.domNode
.scrollTop
= 0;
144 c
.attr('content', article
);
146 correctHeadlinesOffset(getActiveArticleId());
153 exception_error("render_article", e
);
157 function showArticleInHeadlines(id
) {
161 selectArticles("none");
163 var crow
= $("RROW-" + id
);
167 var article_is_unread
= crow
.hasClassName("Unread");
169 crow
.removeClassName("Unread");
171 selectArticles('none');
173 var upd_img_pic
= $("FUPDPIC-" + id
);
175 var cache_prefix
= "";
177 if (activeFeedIsCat()) {
183 var view_mode
= false;
186 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
187 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
192 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
193 upd_img_pic
.src
.match("fresh_sign.png"))) {
195 upd_img_pic
.src
= "images/blank_icon.gif";
197 cache_invalidate(cache_prefix
+ getActiveFeedId());
199 /* cache_inject(cache_prefix + getActiveFeedId(),
200 $("headlines-frame").innerHTML,
201 getFeedUnread(getActiveFeedId())); */
203 } else if (article_is_unread
&& view_mode
== "all_articles") {
205 cache_invalidate(cache_prefix
+ getActiveFeedId());
207 /* cache_inject(cache_prefix + getActiveFeedId(),
208 $("headlines-frame").innerHTML,
209 getFeedUnread(getActiveFeedId())-1); */
211 } else if (article_is_unread
) {
212 cache_invalidate(cache_prefix
+ getActiveFeedId());
217 if (article_is_unread
)
218 _force_scheduled_update
= true;
221 exception_error("showArticleInHeadlines", e
);
225 function article_callback2(transport
, id
) {
227 console
.log("article_callback2 " + id
);
229 handle_rpc_json(transport
);
231 var reply
= JSON
.parse(transport
.responseText
);
234 var upic
= $('FUPDPIC-' + id
);
236 if (upic
) upic
.src
= 'images/blank_icon.gif';
238 if (id
!= last_requested_article
) {
239 console
.log("requested article id is out of sequence, aborting");
243 reply
.each(function(article
) {
244 if (active_post_id
== article
['id']) {
245 render_article(article
['content']);
247 cache_inject(article
['id'], article
['content']);
251 console
.warn("article_callback: returned invalid data");
253 render_article("<div class='whiteBox'>" +
254 __('Could not display article (invalid data received)') + "</div>");
257 var date
= new Date();
258 last_article_view
= date
.getTime() / 1000;
264 exception_error("article_callback2", e
, transport
);
270 console
.log("loading article: " + id
);
272 var cached_article
= cache_find(id
);
274 console
.log("cache check result: " + (cached_article
!= false));
278 var query
= "?op=view&id=" + param_escape(id
);
280 var neighbor_ids
= getRelativePostIds(active_post_id
);
282 /* only request uncached articles */
284 var cids_to_request
= Array();
286 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
287 if (!cache_check(neighbor_ids
[i
])) {
288 cids_to_request
.push(neighbor_ids
[i
]);
292 console
.log("additional ids: " + cids_to_request
.toString());
294 query
= query
+ "&cids=" + cids_to_request
.toString();
296 var crow
= $("RROW-" + id
);
297 var article_is_unread
= crow
.hasClassName("Unread");
300 showArticleInHeadlines(id
);
302 if (!cached_article
) {
304 var upic
= $('FUPDPIC-' + id
);
307 upic
.src
= getInitParam("sign_progress");
310 } else if (cached_article
&& article_is_unread
) {
312 query
= query
+ "&mode=prefetch";
314 render_article(cached_article
);
316 } else if (cached_article
) {
318 query
= query
+ "&mode=prefetch_old";
319 render_article(cached_article
);
325 last_requested_article
= id
;
327 new Ajax
.Request("backend.php", {
329 onComplete: function(transport
) {
330 article_callback2(transport
, id
);
336 exception_error("view", e
);
341 return toggleMark(id
);
345 return togglePub(id
);
348 function toggleMark(id
, client_only
) {
350 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
352 var img
= $("FMPIC-" + id
);
356 if (img
.src
.match("mark_unset")) {
357 img
.src
= img
.src
.replace("mark_unset", "mark_set");
358 img
.alt
= __("Unstar article");
359 query
= query
+ "&mark=1";
362 img
.src
= img
.src
.replace("mark_set", "mark_unset");
363 img
.alt
= __("Star article");
364 query
= query
+ "&mark=0";
368 new Ajax
.Request("backend.php", {
370 onComplete: function(transport
) {
371 handle_rpc_json(transport
);
376 exception_error("toggleMark", e
);
380 function togglePub(id
, client_only
, no_effects
, note
) {
382 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
384 if (note
!= undefined) {
385 query
= query
+ "¬e=" + param_escape(note
);
387 query
= query
+ "¬e=undefined";
390 var img
= $("FPPIC-" + id
);
394 if (img
.src
.match("pub_unset") || note
!= undefined) {
395 img
.src
= img
.src
.replace("pub_unset", "pub_set");
396 img
.alt
= __("Unpublish article");
397 query
= query
+ "&pub=1";
400 img
.src
= img
.src
.replace("pub_set", "pub_unset");
401 img
.alt
= __("Publish article");
403 query
= query
+ "&pub=0";
407 new Ajax
.Request("backend.php", {
409 onComplete: function(transport
) {
410 handle_rpc_json(transport
);
415 exception_error("togglePub", e
);
419 function moveToPost(mode
) {
423 var rows
= getVisibleArticleIds();
428 if (!$('RROW-' + active_post_id
)) {
429 active_post_id
= false;
432 if (active_post_id
== false) {
433 next_id
= getFirstVisibleHeadlineId();
434 prev_id
= getLastVisibleHeadlineId();
436 for (var i
= 0; i
< rows
.length
; i
++) {
437 if (rows
[i
] == active_post_id
) {
444 if (mode
== "next") {
448 cdmExpandArticle(next_id
);
449 cdmScrollToArticleId(next_id
);
452 correctHeadlinesOffset(next_id
);
453 view(next_id
, getActiveFeedId());
458 if (mode
== "prev") {
461 cdmExpandArticle(prev_id
);
462 cdmScrollToArticleId(prev_id
);
464 correctHeadlinesOffset(prev_id
);
465 view(prev_id
, getActiveFeedId());
471 exception_error("moveToPost", e
);
475 function toggleSelected(id
, force_on
) {
478 var cb
= $("RCHK-" + id
);
479 var row
= $("RROW-" + id
);
482 if (row
.hasClassName('Selected') && !force_on
) {
483 row
.removeClassName('Selected');
484 if (cb
) cb
.checked
= false;
486 row
.addClassName('Selected');
487 if (cb
) cb
.checked
= true;
491 exception_error("toggleSelected", e
);
495 function toggleUnread_afh(effect
) {
498 var elem
= effect
.element
;
499 elem
.style
.backgroundColor
= "";
502 exception_error("toggleUnread_afh", e
);
506 function toggleUnread(id
, cmode
, effect
) {
509 var row
= $("RROW-" + id
);
511 if (cmode
== undefined || cmode
== 2) {
512 if (row
.hasClassName("Unread")) {
513 row
.removeClassName("Unread");
516 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
517 afterFinish
: toggleUnread_afh
,
518 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
522 row
.addClassName("Unread");
525 } else if (cmode
== 0) {
527 row
.removeClassName("Unread");
530 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
531 afterFinish
: toggleUnread_afh
,
532 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
535 } else if (cmode
== 1) {
536 row
.addClassName("Unread");
539 if (cmode
== undefined) cmode
= 2;
541 var query
= "?op=rpc&subop=catchupSelected" +
542 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
544 // notify_progress("Loading, please wait...");
546 new Ajax
.Request("backend.php", {
548 onComplete: function(transport
) {
549 handle_rpc_json(transport
);
555 exception_error("toggleUnread", e
);
559 function selectionRemoveLabel(id
, ids
) {
562 if (!ids
) var ids
= getSelectedArticleIds2();
564 if (ids
.length
== 0) {
565 alert(__("No articles are selected."));
569 // var ok = confirm(__("Remove selected articles from label?"));
573 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
574 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
578 // notify_progress("Loading, please wait...");
580 cache_invalidate("F:" + (-11 - id
));
582 new Ajax
.Request("backend.php", {
584 onComplete: function(transport
) {
585 handle_rpc_json(transport
);
586 show_labels_in_headlines(transport
);
592 exception_error("selectionAssignLabel", e
);
597 function selectionAssignLabel(id
, ids
) {
600 if (!ids
) ids
= getSelectedArticleIds2();
602 if (ids
.length
== 0) {
603 alert(__("No articles are selected."));
607 // var ok = confirm(__("Assign selected articles to label?"));
611 cache_invalidate("F:" + (-11 - id
));
613 var query
= "?op=rpc&subop=assignToLabel&ids=" +
614 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
618 // notify_progress("Loading, please wait...");
620 new Ajax
.Request("backend.php", {
622 onComplete: function(transport
) {
623 handle_rpc_json(transport
);
624 show_labels_in_headlines(transport
);
630 exception_error("selectionAssignLabel", e
);
635 function selectionToggleUnread(set_state
, callback
, no_error
) {
637 var rows
= getSelectedArticleIds2();
639 if (rows
.length
== 0 && !no_error
) {
640 alert(__("No articles are selected."));
644 for (i
= 0; i
< rows
.length
; i
++) {
645 var row
= $("RROW-" + rows
[i
]);
647 if (set_state
== undefined) {
648 if (row
.hasClassName("Unread")) {
649 row
.removeClassName("Unread");
651 row
.addClassName("Unread");
655 if (set_state
== false) {
656 row
.removeClassName("Unread");
659 if (set_state
== true) {
660 row
.addClassName("Unread");
665 if (rows
.length
> 0) {
669 if (set_state
== undefined) {
671 } else if (set_state
== true) {
673 } else if (set_state
== false) {
677 var query
= "?op=rpc&subop=catchupSelected" +
678 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
680 notify_progress("Loading, please wait...");
682 new Ajax
.Request("backend.php", {
684 onComplete: function(transport
) {
685 handle_rpc_json(transport
);
686 if (callback
) callback(transport
);
692 exception_error("selectionToggleUnread", e
);
696 function selectionToggleMarked() {
699 var rows
= getSelectedArticleIds2();
701 if (rows
.length
== 0) {
702 alert(__("No articles are selected."));
706 for (i
= 0; i
< rows
.length
; i
++) {
707 toggleMark(rows
[i
], true, true);
710 if (rows
.length
> 0) {
712 var query
= "?op=rpc&subop=markSelected&ids=" +
713 param_escape(rows
.toString()) + "&cmode=2";
715 new Ajax
.Request("backend.php", {
717 onComplete: function(transport
) {
718 handle_rpc_json(transport
);
724 exception_error("selectionToggleMarked", e
);
728 function selectionTogglePublished() {
731 var rows
= getSelectedArticleIds2();
733 if (rows
.length
== 0) {
734 alert(__("No articles are selected."));
738 for (i
= 0; i
< rows
.length
; i
++) {
739 togglePub(rows
[i
], true, true);
742 if (rows
.length
> 0) {
744 var query
= "?op=rpc&subop=publishSelected&ids=" +
745 param_escape(rows
.toString()) + "&cmode=2";
747 new Ajax
.Request("backend.php", {
749 onComplete: function(transport
) {
750 handle_rpc_json(transport
);
756 exception_error("selectionToggleMarked", e
);
760 function getSelectedArticleIds2() {
764 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
766 rv
.push(child
.id
.replace("RROW-", ""));
772 function getLoadedArticleIds() {
775 var children
= $$("#headlines-frame > div[id*=RROW-]");
777 children
.each(function(child
) {
778 rv
.push(child
.id
.replace("RROW-", ""));
785 // mode = all,none,unread,invert
786 function selectArticles(mode
) {
789 var children
= $$("#headlines-frame > div[id*=RROW]");
791 children
.each(function(child
) {
792 var id
= child
.id
.replace("RROW-", "");
793 var cb
= $("RCHK-" + id
);
796 child
.addClassName("Selected");
798 } else if (mode
== "unread") {
799 if (child
.hasClassName("Unread")) {
800 child
.addClassName("Selected");
803 child
.removeClassName("Selected");
806 } else if (mode
== "invert") {
807 if (child
.hasClassName("Selected")) {
808 child
.removeClassName("Selected");
811 child
.addClassName("Selected");
816 child
.removeClassName("Selected");
822 exception_error("selectArticles", e
);
826 function catchupPage() {
828 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
830 var str
= __("Mark all visible articles in %s as read?");
832 str
= str
.replace("%s", fn
);
834 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
838 selectArticles('all');
839 selectionToggleUnread(false, 'viewCurrentFeed()', true)
840 selectArticles('none');
843 function deleteSelection() {
847 var rows
= getSelectedArticleIds2();
849 if (rows
.length
== 0) {
850 alert(__("No articles are selected."));
854 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
858 if (getActiveFeedId() != 0) {
859 str
= __("Delete %d selected articles in %s?");
861 str
= __("Delete %d selected articles?");
864 str
= str
.replace("%d", rows
.length
);
865 str
= str
.replace("%s", fn
);
867 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
871 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
875 new Ajax
.Request("backend.php", {
877 onComplete: function(transport
) {
878 handle_rpc_json(transport
);
883 exception_error("deleteSelection", e
);
887 function archiveSelection() {
891 var rows
= getSelectedArticleIds2();
893 if (rows
.length
== 0) {
894 alert(__("No articles are selected."));
898 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
902 if (getActiveFeedId() != 0) {
903 str
= __("Archive %d selected articles in %s?");
906 str
= __("Move %d archived articles back?");
910 str
= str
.replace("%d", rows
.length
);
911 str
= str
.replace("%s", fn
);
913 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
917 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
921 for (var i
= 0; i
< rows
.length
; i
++) {
922 cache_invalidate(rows
[i
]);
925 new Ajax
.Request("backend.php", {
927 onComplete: function(transport
) {
928 handle_rpc_json(transport
);
933 exception_error("archiveSelection", e
);
937 function catchupSelection() {
941 var rows
= getSelectedArticleIds2();
943 if (rows
.length
== 0) {
944 alert(__("No articles are selected."));
948 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
950 var str
= __("Mark %d selected articles in %s as read?");
952 str
= str
.replace("%d", rows
.length
);
953 str
= str
.replace("%s", fn
);
955 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
959 selectionToggleUnread(false, 'viewCurrentFeed()', true)
962 exception_error("catchupSelection", e
);
966 function editArticleTags(id
) {
967 var query
= "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id
);
969 if (dijit
.byId("editTagsDlg"))
970 dijit
.byId("editTagsDlg").destroyRecursive();
972 dialog
= new dijit
.Dialog({
974 title
: __("Edit article Tags"),
975 style
: "width: 600px",
976 execute: function() {
977 if (this.validate()) {
978 var query
= dojo
.objectToQuery(this.attr('value'));
980 notify_progress("Saving article tags...", true);
982 new Ajax
.Request("backend.php", {
984 onComplete: function(transport
) {
988 var data
= JSON
.parse(transport
.responseText
);
991 var tags_str
= data
.tags_str
;
992 var id
= tags_str
.id
;
994 var tags
= $("ATSTR-" + id
);
995 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
997 if (tags
) tags
.innerHTML
= tags_str
.content
;
998 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1000 cache_invalidate(id
);
1009 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1010 dojo
.disconnect(tmph
);
1012 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1013 "backend.php?op=rpc&subop=completeTags",
1014 { tokens
: ',', paramName
: "search" });
1021 function cdmScrollToArticleId(id
) {
1023 var ctr
= $("headlines-frame");
1024 var e
= $("RROW-" + id
);
1026 if (!e
|| !ctr
) return;
1028 ctr
.scrollTop
= e
.offsetTop
;
1031 exception_error("cdmScrollToArticleId", e
);
1035 function cache_inject(id
, article
, param
) {
1038 if (!cache_check_param(id
, param
)) {
1039 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1041 var date
= new Date();
1042 var ts
= Math
.round(date
.getTime() / 1000);
1046 cache_obj
["id"] = id
;
1047 cache_obj
["data"] = article
;
1048 cache_obj
["param"] = param
;
1050 if (param
) id
= id
+ ":" + param
;
1052 cache_added
["TS:" + id
] = ts
;
1054 if (has_local_storage())
1055 sessionStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1057 article_cache
.push(cache_obj
);
1060 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1063 exception_error("cache_inject", e
);
1067 function cache_find(id
) {
1069 if (has_local_storage()) {
1070 var cache_obj
= sessionStorage
.getItem(id
);
1073 cache_obj
= JSON
.parse(cache_obj
);
1076 return cache_obj
['data'];
1080 for (var i
= 0; i
< article_cache
.length
; i
++) {
1081 if (article_cache
[i
]["id"] == id
) {
1082 return article_cache
[i
]["data"];
1089 function cache_find_param(id
, param
) {
1091 if (has_local_storage()) {
1093 if (param
) id
= id
+ ":" + param
;
1095 var cache_obj
= sessionStorage
.getItem(id
);
1098 cache_obj
= JSON
.parse(cache_obj
);
1101 return cache_obj
['data'];
1105 for (var i
= 0; i
< article_cache
.length
; i
++) {
1106 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1107 return article_cache
[i
]["data"];
1115 function cache_check(id
) {
1116 if (has_local_storage()) {
1117 if (sessionStorage
.getItem(id
))
1120 for (var i
= 0; i
< article_cache
.length
; i
++) {
1121 if (article_cache
[i
]["id"] == id
) {
1129 function cache_check_param(id
, param
) {
1130 if (has_local_storage()) {
1132 if (param
) id
= id
+ ":" + param
;
1134 if (sessionStorage
.getItem(id
))
1138 for (var i
= 0; i
< article_cache
.length
; i
++) {
1139 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1147 function cache_expire() {
1148 if (has_local_storage()) {
1150 var date
= new Date();
1151 var timestamp
= Math
.round(date
.getTime() / 1000);
1153 for (var i
= 0; i
< sessionStorage
.length
; i
++) {
1155 var id
= sessionStorage
.key(i
);
1157 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1158 sessionStorage
.removeItem(id
);
1163 while (article_cache
.length
> 25) {
1164 article_cache
.shift();
1169 function cache_flush() {
1170 if (has_local_storage()) {
1171 sessionStorage
.clear();
1173 article_cache
= new Array();
1177 function cache_invalidate(id
) {
1179 if (has_local_storage()) {
1183 for (var i
= 0; i
< sessionStorage
.length
; i
++) {
1184 var key
= sessionStorage
.key(i
);
1186 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1188 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1189 sessionStorage
.removeItem(key
);
1200 while (i
< article_cache
.length
) {
1201 if (article_cache
[i
]["id"] == id
) {
1202 //console.log("cache_invalidate: removed id " + id);
1203 article_cache
.splice(i
, 1);
1210 //console.log("cache_invalidate: id not found: " + id);
1213 exception_error("cache_invalidate", e
);
1217 function getActiveArticleId() {
1218 return active_post_id
;
1221 function preloadBatchedArticles() {
1224 var query
= "?op=rpc&subop=getArticles&ids=" +
1225 preload_id_batch
.toString();
1227 new Ajax
.Request("backend.php", {
1229 onComplete: function(transport
) {
1231 preload_id_batch
= [];
1233 var articles
= JSON
.parse(transport
.responseText
);
1235 for (var i
= 0; i
< articles
.length
; i
++) {
1236 var id
= articles
[i
]['id'];
1237 if (!cache_check(id
)) {
1238 cache_inject(id
, articles
[i
]['content']);
1239 console
.log("preloaded article: " + id
);
1245 exception_error("preloadBatchedArticles", e
);
1249 function preloadArticleUnderPointer(id
) {
1251 if (getInitParam("bw_limit") == "1") return;
1253 if (post_under_pointer
== id
&& !cache_check(id
)) {
1255 console
.log("trying to preload article " + id
);
1257 var neighbor_ids
= getRelativePostIds(id
, 1);
1259 /* only request uncached articles */
1261 if (preload_id_batch
.indexOf(id
) == -1) {
1262 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1263 if (!cache_check(neighbor_ids
[i
])) {
1264 preload_id_batch
.push(neighbor_ids
[i
]);
1269 if (preload_id_batch
.indexOf(id
) == -1)
1270 preload_id_batch
.push(id
);
1272 //console.log("preload ids batch: " + preload_id_batch.toString());
1274 window
.clearTimeout(preload_timeout_id
);
1275 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1279 exception_error("preloadArticleUnderPointer", e
);
1283 function postMouseIn(id
) {
1285 if (post_under_pointer
!= id
) {
1286 post_under_pointer
= id
;
1288 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1293 exception_error("postMouseIn", e
);
1297 function postMouseOut(id
) {
1299 post_under_pointer
= false;
1301 exception_error("postMouseOut", e
);
1305 function headlines_scroll_handler(e
) {
1308 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1309 if (!_infscroll_disable
) {
1315 if (getInitParam("cdm_auto_catchup") == 1) {
1319 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1321 if ($("headlines-frame").scrollTop
>
1322 (child
.offsetTop
+ child
.offsetHeight
)) {
1324 ids
.push(child
.id
.replace("RROW-", ""));
1328 if (ids
.length
> 0) {
1330 var query
= "?op=rpc&subop=catchupSelected" +
1331 "&cmode=0&ids=" + param_escape(ids
.toString());
1333 new Ajax
.Request("backend.php", {
1335 onComplete: function(transport
) {
1336 handle_rpc_json(transport
);
1338 ids
.each(function(id
) {
1339 var elem
= $("RROW-" + id
);
1340 if (elem
) elem
.removeClassName("Unread");
1346 exception_error("headlines_scroll_handler", e
);
1350 function catchupRelativeToArticle(below
) {
1355 if (!getActiveArticleId()) {
1356 alert(__("No article is selected."));
1360 var visible_ids
= getVisibleArticleIds();
1362 var ids_to_mark
= new Array();
1365 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1366 if (visible_ids
[i
] != getActiveArticleId()) {
1367 var e
= $("RROW-" + visible_ids
[i
]);
1369 if (e
&& e
.hasClassName("Unread")) {
1370 ids_to_mark
.push(visible_ids
[i
]);
1377 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1378 if (visible_ids
[i
] != getActiveArticleId()) {
1379 var e
= $("RROW-" + visible_ids
[i
]);
1381 if (e
&& e
.hasClassName("Unread")) {
1382 ids_to_mark
.push(visible_ids
[i
]);
1390 if (ids_to_mark
.length
== 0) {
1391 alert(__("No articles found to mark"));
1393 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1395 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1397 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1398 var e
= $("RROW-" + ids_to_mark
[i
]);
1399 e
.removeClassName("Unread");
1402 var query
= "?op=rpc&subop=catchupSelected" +
1403 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1405 new Ajax
.Request("backend.php", {
1407 onComplete: function(transport
) {
1408 handle_rpc_json(transport
);
1415 exception_error("catchupRelativeToArticle", e
);
1419 function cdmExpandArticle(id
) {
1424 var elem
= $("CICD-" + active_post_id
);
1426 var upd_img_pic
= $("FUPDPIC-" + id
);
1428 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1429 upd_img_pic
.src
.match("fresh_sign.png"))) {
1431 upd_img_pic
.src
= "images/blank_icon.gif";
1434 if (id
== active_post_id
&& Element
.visible(elem
))
1437 selectArticles("none");
1439 var old_offset
= $("RROW-" + id
).offsetTop
;
1441 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1443 Element
.show("CEXC-" + active_post_id
);
1446 active_post_id
= id
;
1448 elem
= $("CICD-" + id
);
1450 if (!Element
.visible(elem
)) {
1452 Element
.hide("CEXC-" + id
);
1454 if ($("CWRAP-" + id
).innerHTML
== "") {
1456 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1458 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1459 __("Loading, please wait...") + "</div>";
1461 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1463 //console.log(query);
1465 new Ajax
.Request("backend.php", {
1467 onComplete: function(transport
) {
1468 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1470 handle_rpc_json(transport
);
1472 var reply
= JSON
.parse(transport
.responseText
);
1475 var article
= reply
['article']['content'];
1476 var recv_id
= reply
['article']['id'];
1479 $("CWRAP-" + id
).innerHTML
= article
;
1482 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1490 var new_offset
= $("RROW-" + id
).offsetTop
;
1492 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1494 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1495 $("headlines-frame").scrollTop
= new_offset
;
1497 toggleUnread(id
, 0, true);
1501 exception_error("cdmExpandArticle", e
);
1507 function fixHeadlinesOrder(ids
) {
1509 for (var i
= 0; i
< ids
.length
; i
++) {
1510 var e
= $("RROW-" + ids
[i
]);
1514 e
.removeClassName("even");
1515 e
.addClassName("odd");
1517 e
.removeClassName("odd");
1518 e
.addClassName("even");
1523 exception_error("fixHeadlinesOrder", e
);
1527 function getArticleUnderPointer() {
1528 return post_under_pointer
;
1531 function zoomToArticle(event
, id
) {
1533 var cached_article
= cache_find(id
);
1535 if (dijit
.byId("ATAB-" + id
))
1536 if (!event
|| !event
.shiftKey
)
1537 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1539 if (dijit
.byId("ATSTRTIP-" + id
))
1540 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1542 if (cached_article
) {
1543 //closeArticlePanel();
1545 var article_pane
= new dijit
.layout
.ContentPane({
1546 title
: __("Loading...") , content
: cached_article
,
1547 style
: 'padding : 0px;',
1551 dijit
.byId("content-tabs").addChild(article_pane
);
1553 if (!event
|| !event
.shiftKey
)
1554 dijit
.byId("content-tabs").selectChild(article_pane
);
1556 if ($("PTITLE-" + id
))
1557 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1561 var query
= "?op=rpc&subop=getArticles&ids=" + param_escape(id
);
1563 notify_progress("Loading, please wait...", true);
1565 new Ajax
.Request("backend.php", {
1567 onComplete: function(transport
) {
1570 var reply
= JSON
.parse(transport
.responseText
);
1573 //closeArticlePanel();
1575 var content
= reply
[0]['content'];
1577 var article_pane
= new dijit
.layout
.ContentPane({
1578 title
: "article-" + id
, content
: content
,
1579 style
: 'padding : 0px;',
1583 dijit
.byId("content-tabs").addChild(article_pane
);
1585 if (!event
|| !event
.shiftKey
)
1586 dijit
.byId("content-tabs").selectChild(article_pane
);
1588 if ($("PTITLE-" + id
))
1589 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1596 exception_error("zoomToArticle", e
);
1600 function scrollArticle(offset
) {
1603 var ci
= $("content-insert");
1605 ci
.scrollTop
+= offset
;
1608 var hi
= $("headlines-frame");
1610 hi
.scrollTop
+= offset
;
1615 exception_error("scrollArticle", e
);
1619 function show_labels_in_headlines(transport
) {
1621 var data
= JSON
.parse(transport
.responseText
);
1624 data
['info-for-headlines'].each(function(elem
) {
1625 var ctr
= $("HLLCTR-" + elem
.id
);
1627 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1631 exception_error("show_labels_in_headlines", e
);
1635 function toggleHeadlineActions() {
1637 var e
= $("headlineActionsBody");
1638 var p
= $("headlineActionsDrop");
1640 if (!Element
.visible(e
)) {
1647 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1648 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
1651 exception_error("toggleHeadlineActions", e
);
1655 /* function publishWithNote(id, def_note) {
1657 if (!def_note) def_note = '';
1659 var note = prompt(__("Please enter a note for this article:"), def_note);
1661 if (note != undefined) {
1662 togglePub(id, false, false, note);
1666 exception_error("publishWithNote", e);
1670 function emailArticle(id
) {
1673 var ids
= getSelectedArticleIds2();
1675 if (ids
.length
== 0) {
1676 alert(__("No articles are selected."));
1680 id
= ids
.toString();
1683 if (dijit
.byId("emailArticleDlg"))
1684 dijit
.byId("emailArticleDlg").destroyRecursive();
1686 var query
= "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id
);
1688 dialog
= new dijit
.Dialog({
1689 id
: "emailArticleDlg",
1690 title
: __("Forward article by email"),
1691 style
: "width: 600px",
1692 execute: function() {
1693 if (this.validate()) {
1695 new Ajax
.Request("backend.php", {
1696 parameters
: dojo
.objectToQuery(this.attr('value')),
1697 onComplete: function(transport
) {
1699 var reply
= JSON
.parse(transport
.responseText
);
1701 var error
= reply
['error'];
1704 alert(__('Error sending email:') + ' ' + error
);
1706 notify_info('Your message has been sent.');
1715 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1716 dojo
.disconnect(tmph
);
1718 new Ajax
.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1719 "backend.php?op=rpc&subop=completeEmails",
1720 { tokens
: '', paramName
: "search" });
1725 /* displayDlg('emailArticle', id,
1727 document.forms['article_email_form'].destination.focus();
1729 new Ajax.Autocompleter('destination', 'destination_choices',
1730 "backend.php?op=rpc&subop=completeEmails",
1731 { tokens: '', paramName: "search" });
1736 exception_error("emailArticle", e
);
1740 function dismissArticle(id
) {
1742 var elem
= $("RROW-" + id
);
1744 toggleUnread(id
, 0, true);
1746 new Effect
.Fade(elem
, {duration
: 0.5});
1748 active_post_id
= false;
1751 exception_error("dismissArticle", e
);
1755 function dismissSelectedArticles() {
1758 var ids
= getVisibleArticleIds();
1762 for (var i
= 0; i
< ids
.length
; i
++) {
1763 var elem
= $("RROW-" + ids
[i
]);
1765 if (elem
.className
&& elem
.hasClassName("Selected") &&
1766 ids
[i
] != active_post_id
) {
1767 new Effect
.Fade(elem
, {duration
: 0.5});
1775 selectionToggleUnread(false);
1777 fixHeadlinesOrder(tmp
);
1780 exception_error("dismissSelectedArticles", e
);
1784 function dismissReadArticles() {
1787 var ids
= getVisibleArticleIds();
1790 for (var i
= 0; i
< ids
.length
; i
++) {
1791 var elem
= $("RROW-" + ids
[i
]);
1793 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1794 !elem
.hasClassName("Selected")) {
1796 new Effect
.Fade(elem
, {duration
: 0.5});
1802 fixHeadlinesOrder(tmp
);
1805 exception_error("dismissSelectedArticles", e
);
1809 function getVisibleArticleIds() {
1814 getLoadedArticleIds().each(function(id
) {
1815 var elem
= $("RROW-" + id
);
1816 if (elem
&& Element
.visible(elem
))
1821 exception_error("getVisibleArticleIds", e
);
1827 function cdmClicked(event
, id
) {
1829 var shift_key
= event
.shiftKey
;
1833 if (!event
.ctrlKey
) {
1835 if (!getInitParam("cdm_expanded")) {
1836 return cdmExpandArticle(id
);
1839 selectArticles("none");
1842 var elem
= $("RROW-" + id
);
1845 elem
.removeClassName("Unread");
1847 var upd_img_pic
= $("FUPDPIC-" + id
);
1849 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1850 upd_img_pic
.src
.match("fresh_sign.png"))) {
1852 upd_img_pic
.src
= "images/blank_icon.gif";
1855 active_post_id
= id
;
1857 var query
= "?op=rpc&subop=catchupSelected" +
1858 "&cmode=0&ids=" + param_escape(id
);
1860 new Ajax
.Request("backend.php", {
1862 onComplete: function(transport
) {
1863 handle_rpc_json(transport
);
1870 toggleSelected(id
, true);
1871 toggleUnread(id
, 0, false);
1872 zoomToArticle(event
, id
);
1876 exception_error("cdmClicked");
1882 function postClicked(event
, id
) {
1885 if (!event
.ctrlKey
) {
1888 postOpenInNewTab(event
, id
);
1893 exception_error("postClicked");
1897 function hlOpenInNewTab(event
, id
) {
1898 toggleUnread(id
, 0, false);
1899 zoomToArticle(event
, id
);
1902 function postOpenInNewTab(event
, id
) {
1903 closeArticlePanel(id
);
1904 zoomToArticle(event
, id
);
1907 function hlClicked(event
, id
) {
1909 if (event
.which
== 2) {
1912 } else if (event
.altKey
) {
1913 openArticleInNewWindow(id
);
1914 } else if (!event
.ctrlKey
) {
1919 toggleUnread(id
, 0, false);
1920 zoomToArticle(event
, id
);
1925 exception_error("hlClicked");
1929 function getFirstVisibleHeadlineId() {
1930 var rows
= getVisibleArticleIds();
1935 function getLastVisibleHeadlineId() {
1936 var rows
= getVisibleArticleIds();
1937 return rows
[rows
.length
-1];
1940 function openArticleInNewWindow(id
) {
1941 toggleUnread(id
, 0, false);
1942 window
.open("backend.php?op=la&id=" + id
);
1945 function isCdmMode() {
1946 return getInitParam("combined_display_mode");
1949 function markHeadline(id
) {
1950 var row
= $("RROW-" + id
);
1952 var check
= $("RCHK-" + id
);
1955 check
.checked
= true;
1958 row
.addClassName("Selected");
1962 function getRelativePostIds(id
, limit
) {
1968 if (!limit
) limit
= 3;
1970 var ids
= getVisibleArticleIds();
1972 for (var i
= 0; i
< ids
.length
; i
++) {
1974 for (var k
= 1; k
<= limit
; k
++) {
1975 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
1976 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1983 exception_error("getRelativePostIds", e
);
1989 function correctHeadlinesOffset(id
) {
1993 var container
= $("headlines-frame");
1994 var row
= $("RROW-" + id
);
1996 var viewport
= container
.offsetHeight
;
1998 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
1999 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2001 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2002 //console.log("Vport: " + viewport);
2004 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2005 container
.scrollTop
= row
.offsetTop
;
2006 } else if (rel_offset_bottom
> viewport
) {
2008 /* doesn't properly work with Opera in some cases because
2009 Opera fucks up element scrolling */
2011 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2015 exception_error("correctHeadlinesOffset", e
);
2020 function headlineActionsChange(elem
) {
2023 elem
.attr('value', 'false');
2025 exception_error("headlineActionsChange", e
);
2029 function closeArticlePanel() {
2031 var tabs
= dijit
.byId("content-tabs");
2032 var child
= tabs
.selectedChildWidget
;
2034 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
2035 tabs
.removeChild(child
);
2038 if (dijit
.byId("content-insert"))
2039 dijit
.byId("headlines-wrap-inner").removeChild(
2040 dijit
.byId("content-insert"));
2044 function initHeadlinesMenu() {
2046 if (dijit
.byId("headlinesMenu"))
2047 dijit
.byId("headlinesMenu").destroyRecursive();
2052 nodes
= $$("#headlines-frame > div[id*=RROW]");
2054 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2057 nodes
.each(function(node
) {
2061 var menu
= new dijit
.Menu({
2062 id
: "headlinesMenu",
2066 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2067 var callerNode
= event
.target
, match
= null, tries
= 0;
2069 while (match
== null && callerNode
&& tries
<= 3) {
2070 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2071 callerNode
= callerNode
.parentNode
;
2075 if (match
) this.callerRowId
= parseInt(match
[1]);
2079 /* if (!isCdmMode())
2080 menu.addChild(new dijit.MenuItem({
2081 label: __("View article"),
2082 onClick: function(event) {
2083 view(this.getParent().callerRowId);
2086 menu
.addChild(new dijit
.MenuItem({
2087 label
: __("Open original article"),
2088 onClick: function(event
) {
2089 openArticleInNewWindow(this.getParent().callerRowId
);
2092 menu
.addChild(new dijit
.MenuItem({
2093 label
: __("View in a tt-rss tab"),
2094 onClick: function(event
) {
2095 hlOpenInNewTab(event
, this.getParent().callerRowId
);
2098 // menu.addChild(new dijit.MenuSeparator());
2100 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2104 menu
.addChild(new dijit
.MenuSeparator());
2106 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2107 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2109 labels
.each(function(label
) {
2110 var id
= label
.id
[0];
2111 var bare_id
= id
.substr(id
.indexOf(":")+1);
2112 var name
= label
.name
[0];
2114 bare_id
= -11-bare_id
;
2116 labelAddMenu
.addChild(new dijit
.MenuItem({
2119 onClick: function(event
) {
2120 selectionAssignLabel(this.labelId
,
2121 [this.getParent().ownerMenu
.callerRowId
]);
2124 labelDelMenu
.addChild(new dijit
.MenuItem({
2127 onClick: function(event
) {
2128 selectionRemoveLabel(this.labelId
,
2129 [this.getParent().ownerMenu
.callerRowId
]);
2134 menu
.addChild(new dijit
.PopupMenuItem({
2135 label
: __("Assign label"),
2136 popup
: labelAddMenu
,
2139 menu
.addChild(new dijit
.PopupMenuItem({
2140 label
: __("Remove label"),
2141 popup
: labelDelMenu
,
2149 exception_error("initHeadlinesMenu", e
);
2153 function tweetArticle(id
) {
2155 var query
= "?op=rpc&subop=getTweetInfo&id=" + param_escape(id
);
2160 var ts
= d
.getTime();
2162 var w
= window
.open('backend.php?op=loading', 'ttrss_tweet',
2163 "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
2165 new Ajax
.Request("backend.php", {
2167 onComplete: function(transport
) {
2168 var ti
= JSON
.parse(transport
.responseText
);
2170 var share_url
= "http://twitter.com/share?_=" + ts
+
2171 "&text=" + param_escape(ti
.title
) +
2172 "&url=" + param_escape(ti
.link
);
2174 w
.location
.href
= share_url
;
2180 exception_error("tweetArticle", e
);
2184 function editArticleNote(id
) {
2187 var query
= "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id
);
2189 if (dijit
.byId("editNoteDlg"))
2190 dijit
.byId("editNoteDlg").destroyRecursive();
2192 dialog
= new dijit
.Dialog({
2194 title
: __("Edit article note"),
2195 style
: "width: 600px",
2196 execute: function() {
2197 if (this.validate()) {
2198 var query
= dojo
.objectToQuery(this.attr('value'));
2200 notify_progress("Saving article note...", true);
2202 new Ajax
.Request("backend.php", {
2204 onComplete: function(transport
) {
2208 var reply
= JSON
.parse(transport
.responseText
);
2210 cache_invalidate(id
);
2212 var elem
= $("POSTNOTE-" + id
);
2216 elem
.innerHTML
= reply
.note
;
2218 if (reply
.raw_length
!= 0)
2219 new Effect
.Appear(elem
);
2231 exception_error("editArticleNote", e
);
2235 function player(elem
) {
2236 var aid
= elem
.getAttribute("audio-id");
2237 var status
= elem
.getAttribute("status");
2245 elem
.innerHTML
= __("Playing...");
2246 elem
.title
= __("Click to pause");
2247 elem
.addClassName("playing");
2251 elem
.innerHTML
= __("Play");
2252 elem
.title
= __("Click to play");
2253 elem
.removeClassName("playing");
2256 elem
.setAttribute("status", status
);
2258 alert("Your browser doesn't seem to support HTML5 audio.");