]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
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
;
329 new Ajax
.Request("backend.php", {
331 onComplete: function(transport
) {
332 article_callback2(transport
, id
);
338 exception_error("view", e
);
343 return toggleMark(id
);
347 return togglePub(id
);
350 function toggleMark(id
, client_only
) {
352 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
354 var img
= $("FMPIC-" + id
);
358 if (img
.src
.match("mark_unset")) {
359 img
.src
= img
.src
.replace("mark_unset", "mark_set");
360 img
.alt
= __("Unstar article");
361 query
= query
+ "&mark=1";
364 img
.src
= img
.src
.replace("mark_set", "mark_unset");
365 img
.alt
= __("Star article");
366 query
= query
+ "&mark=0";
370 new Ajax
.Request("backend.php", {
372 onComplete: function(transport
) {
373 handle_rpc_json(transport
);
378 exception_error("toggleMark", e
);
382 function togglePub(id
, client_only
, no_effects
, note
) {
384 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
386 if (note
!= undefined) {
387 query
= query
+ "¬e=" + param_escape(note
);
389 query
= query
+ "¬e=undefined";
392 var img
= $("FPPIC-" + id
);
396 if (img
.src
.match("pub_unset") || note
!= undefined) {
397 img
.src
= img
.src
.replace("pub_unset", "pub_set");
398 img
.alt
= __("Unpublish article");
399 query
= query
+ "&pub=1";
402 img
.src
= img
.src
.replace("pub_set", "pub_unset");
403 img
.alt
= __("Publish article");
405 query
= query
+ "&pub=0";
409 new Ajax
.Request("backend.php", {
411 onComplete: function(transport
) {
412 handle_rpc_json(transport
);
417 exception_error("togglePub", e
);
421 function moveToPost(mode
) {
425 var rows
= getVisibleArticleIds();
430 if (!$('RROW-' + active_post_id
)) {
431 active_post_id
= false;
434 if (active_post_id
== false) {
435 next_id
= getFirstVisibleHeadlineId();
436 prev_id
= getLastVisibleHeadlineId();
438 for (var i
= 0; i
< rows
.length
; i
++) {
439 if (rows
[i
] == active_post_id
) {
446 if (mode
== "next") {
450 cdmExpandArticle(next_id
);
451 cdmScrollToArticleId(next_id
);
454 correctHeadlinesOffset(next_id
);
455 view(next_id
, getActiveFeedId());
460 if (mode
== "prev") {
463 cdmExpandArticle(prev_id
);
464 cdmScrollToArticleId(prev_id
);
466 correctHeadlinesOffset(prev_id
);
467 view(prev_id
, getActiveFeedId());
473 exception_error("moveToPost", e
);
477 function toggleSelected(id
, force_on
) {
480 var cb
= $("RCHK-" + id
);
481 var row
= $("RROW-" + id
);
484 if (row
.hasClassName('Selected') && !force_on
) {
485 row
.removeClassName('Selected');
486 if (cb
) cb
.checked
= false;
488 row
.addClassName('Selected');
489 if (cb
) cb
.checked
= true;
493 exception_error("toggleSelected", e
);
497 function toggleUnread_afh(effect
) {
500 var elem
= effect
.element
;
501 elem
.style
.backgroundColor
= "";
504 exception_error("toggleUnread_afh", e
);
508 function toggleUnread(id
, cmode
, effect
) {
511 var row
= $("RROW-" + id
);
513 if (cmode
== undefined || cmode
== 2) {
514 if (row
.hasClassName("Unread")) {
515 row
.removeClassName("Unread");
518 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
519 afterFinish
: toggleUnread_afh
,
520 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
524 row
.addClassName("Unread");
527 } else if (cmode
== 0) {
529 row
.removeClassName("Unread");
532 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
533 afterFinish
: toggleUnread_afh
,
534 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
537 } else if (cmode
== 1) {
538 row
.addClassName("Unread");
541 if (cmode
== undefined) cmode
= 2;
543 var query
= "?op=rpc&subop=catchupSelected" +
544 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
546 // notify_progress("Loading, please wait...");
548 new Ajax
.Request("backend.php", {
550 onComplete: function(transport
) {
551 handle_rpc_json(transport
);
557 exception_error("toggleUnread", e
);
561 function selectionRemoveLabel(id
, ids
) {
564 if (!ids
) var ids
= getSelectedArticleIds2();
566 if (ids
.length
== 0) {
567 alert(__("No articles are selected."));
571 // var ok = confirm(__("Remove selected articles from label?"));
575 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
576 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
580 // notify_progress("Loading, please wait...");
582 cache_invalidate("F:" + (-11 - id
));
584 new Ajax
.Request("backend.php", {
586 onComplete: function(transport
) {
587 handle_rpc_json(transport
);
588 show_labels_in_headlines(transport
);
594 exception_error("selectionAssignLabel", e
);
599 function selectionAssignLabel(id
, ids
) {
602 if (!ids
) ids
= getSelectedArticleIds2();
604 if (ids
.length
== 0) {
605 alert(__("No articles are selected."));
609 // var ok = confirm(__("Assign selected articles to label?"));
613 cache_invalidate("F:" + (-11 - id
));
615 var query
= "?op=rpc&subop=assignToLabel&ids=" +
616 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
620 // notify_progress("Loading, please wait...");
622 new Ajax
.Request("backend.php", {
624 onComplete: function(transport
) {
625 handle_rpc_json(transport
);
626 show_labels_in_headlines(transport
);
632 exception_error("selectionAssignLabel", e
);
637 function selectionToggleUnread(set_state
, callback
, no_error
) {
639 var rows
= getSelectedArticleIds2();
641 if (rows
.length
== 0 && !no_error
) {
642 alert(__("No articles are selected."));
646 for (i
= 0; i
< rows
.length
; i
++) {
647 var row
= $("RROW-" + rows
[i
]);
649 if (set_state
== undefined) {
650 if (row
.hasClassName("Unread")) {
651 row
.removeClassName("Unread");
653 row
.addClassName("Unread");
657 if (set_state
== false) {
658 row
.removeClassName("Unread");
661 if (set_state
== true) {
662 row
.addClassName("Unread");
667 if (rows
.length
> 0) {
671 if (set_state
== undefined) {
673 } else if (set_state
== true) {
675 } else if (set_state
== false) {
679 var query
= "?op=rpc&subop=catchupSelected" +
680 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
682 notify_progress("Loading, please wait...");
684 new Ajax
.Request("backend.php", {
686 onComplete: function(transport
) {
687 handle_rpc_json(transport
);
688 if (callback
) callback(transport
);
694 exception_error("selectionToggleUnread", e
);
698 function selectionToggleMarked() {
701 var rows
= getSelectedArticleIds2();
703 if (rows
.length
== 0) {
704 alert(__("No articles are selected."));
708 for (i
= 0; i
< rows
.length
; i
++) {
709 toggleMark(rows
[i
], true, true);
712 if (rows
.length
> 0) {
714 var query
= "?op=rpc&subop=markSelected&ids=" +
715 param_escape(rows
.toString()) + "&cmode=2";
717 new Ajax
.Request("backend.php", {
719 onComplete: function(transport
) {
720 handle_rpc_json(transport
);
726 exception_error("selectionToggleMarked", e
);
730 function selectionTogglePublished() {
733 var rows
= getSelectedArticleIds2();
735 if (rows
.length
== 0) {
736 alert(__("No articles are selected."));
740 for (i
= 0; i
< rows
.length
; i
++) {
741 togglePub(rows
[i
], true, true);
744 if (rows
.length
> 0) {
746 var query
= "?op=rpc&subop=publishSelected&ids=" +
747 param_escape(rows
.toString()) + "&cmode=2";
749 new Ajax
.Request("backend.php", {
751 onComplete: function(transport
) {
752 handle_rpc_json(transport
);
758 exception_error("selectionToggleMarked", e
);
762 function getSelectedArticleIds2() {
766 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
768 rv
.push(child
.id
.replace("RROW-", ""));
774 function getLoadedArticleIds() {
777 var children
= $$("#headlines-frame > div[id*=RROW-]");
779 children
.each(function(child
) {
780 rv
.push(child
.id
.replace("RROW-", ""));
787 // mode = all,none,unread,invert
788 function selectArticles(mode
) {
791 var children
= $$("#headlines-frame > div[id*=RROW]");
793 children
.each(function(child
) {
794 var id
= child
.id
.replace("RROW-", "");
795 var cb
= $("RCHK-" + id
);
798 child
.addClassName("Selected");
800 } else if (mode
== "unread") {
801 if (child
.hasClassName("Unread")) {
802 child
.addClassName("Selected");
805 child
.removeClassName("Selected");
808 } else if (mode
== "invert") {
809 if (child
.hasClassName("Selected")) {
810 child
.removeClassName("Selected");
813 child
.addClassName("Selected");
818 child
.removeClassName("Selected");
824 exception_error("selectArticles", e
);
828 function catchupPage() {
830 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
832 var str
= __("Mark all visible articles in %s as read?");
834 str
= str
.replace("%s", fn
);
836 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
840 selectArticles('all');
841 selectionToggleUnread(false, 'viewCurrentFeed()', true)
842 selectArticles('none');
845 function deleteSelection() {
849 var rows
= getSelectedArticleIds2();
851 if (rows
.length
== 0) {
852 alert(__("No articles are selected."));
856 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
860 if (getActiveFeedId() != 0) {
861 str
= __("Delete %d selected articles in %s?");
863 str
= __("Delete %d selected articles?");
866 str
= str
.replace("%d", rows
.length
);
867 str
= str
.replace("%s", fn
);
869 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
873 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
877 new Ajax
.Request("backend.php", {
879 onComplete: function(transport
) {
880 handle_rpc_json(transport
);
885 exception_error("deleteSelection", e
);
889 function archiveSelection() {
893 var rows
= getSelectedArticleIds2();
895 if (rows
.length
== 0) {
896 alert(__("No articles are selected."));
900 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
904 if (getActiveFeedId() != 0) {
905 str
= __("Archive %d selected articles in %s?");
908 str
= __("Move %d archived articles back?");
912 str
= str
.replace("%d", rows
.length
);
913 str
= str
.replace("%s", fn
);
915 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
919 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
923 for (var i
= 0; i
< rows
.length
; i
++) {
924 cache_invalidate(rows
[i
]);
927 new Ajax
.Request("backend.php", {
929 onComplete: function(transport
) {
930 handle_rpc_json(transport
);
935 exception_error("archiveSelection", e
);
939 function catchupSelection() {
943 var rows
= getSelectedArticleIds2();
945 if (rows
.length
== 0) {
946 alert(__("No articles are selected."));
950 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
952 var str
= __("Mark %d selected articles in %s as read?");
954 str
= str
.replace("%d", rows
.length
);
955 str
= str
.replace("%s", fn
);
957 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
961 selectionToggleUnread(false, 'viewCurrentFeed()', true)
964 exception_error("catchupSelection", e
);
968 function editArticleTags(id
) {
969 var query
= "backend.php?op=dlg&id=editArticleTags¶m=" + param_escape(id
);
971 if (dijit
.byId("editTagsDlg"))
972 dijit
.byId("editTagsDlg").destroyRecursive();
974 dialog
= new dijit
.Dialog({
976 title
: __("Edit article Tags"),
977 style
: "width: 600px",
978 execute: function() {
979 if (this.validate()) {
980 var query
= dojo
.objectToQuery(this.attr('value'));
982 notify_progress("Saving article tags...", true);
984 new Ajax
.Request("backend.php", {
986 onComplete: function(transport
) {
990 var data
= JSON
.parse(transport
.responseText
);
993 var tags_str
= data
.tags_str
;
994 var id
= tags_str
.id
;
996 var tags
= $("ATSTR-" + id
);
997 var tooltip
= dijit
.byId("ATSTRTIP-" + id
);
999 if (tags
) tags
.innerHTML
= tags_str
.content
;
1000 if (tooltip
) tooltip
.attr('label', tags_str
.content_full
);
1002 cache_invalidate(id
);
1011 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1012 dojo
.disconnect(tmph
);
1014 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1015 "backend.php?op=rpc&subop=completeTags",
1016 { tokens
: ',', paramName
: "search" });
1023 function cdmScrollToArticleId(id
) {
1025 var ctr
= $("headlines-frame");
1026 var e
= $("RROW-" + id
);
1028 if (!e
|| !ctr
) return;
1030 ctr
.scrollTop
= e
.offsetTop
;
1033 exception_error("cdmScrollToArticleId", e
);
1037 function cache_inject(id
, article
, param
) {
1040 if (!cache_check_param(id
, param
)) {
1041 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1043 var date
= new Date();
1044 var ts
= Math
.round(date
.getTime() / 1000);
1048 cache_obj
["id"] = id
;
1049 cache_obj
["data"] = article
;
1050 cache_obj
["param"] = param
;
1052 if (param
) id
= id
+ ":" + param
;
1054 cache_added
["TS:" + id
] = ts
;
1056 if (has_local_storage())
1057 sessionStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1059 article_cache
.push(cache_obj
);
1062 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1065 exception_error("cache_inject", e
);
1069 function cache_find(id
) {
1071 if (has_local_storage()) {
1072 var cache_obj
= sessionStorage
.getItem(id
);
1075 cache_obj
= JSON
.parse(cache_obj
);
1078 return cache_obj
['data'];
1082 for (var i
= 0; i
< article_cache
.length
; i
++) {
1083 if (article_cache
[i
]["id"] == id
) {
1084 return article_cache
[i
]["data"];
1091 function cache_find_param(id
, param
) {
1093 if (has_local_storage()) {
1095 if (param
) id
= id
+ ":" + param
;
1097 var cache_obj
= sessionStorage
.getItem(id
);
1100 cache_obj
= JSON
.parse(cache_obj
);
1103 return cache_obj
['data'];
1107 for (var i
= 0; i
< article_cache
.length
; i
++) {
1108 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1109 return article_cache
[i
]["data"];
1117 function cache_check(id
) {
1118 if (has_local_storage()) {
1119 if (sessionStorage
.getItem(id
))
1122 for (var i
= 0; i
< article_cache
.length
; i
++) {
1123 if (article_cache
[i
]["id"] == id
) {
1131 function cache_check_param(id
, param
) {
1132 if (has_local_storage()) {
1134 if (param
) id
= id
+ ":" + param
;
1136 if (sessionStorage
.getItem(id
))
1140 for (var i
= 0; i
< article_cache
.length
; i
++) {
1141 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1149 function cache_expire() {
1150 if (has_local_storage()) {
1152 var date
= new Date();
1153 var timestamp
= Math
.round(date
.getTime() / 1000);
1155 for (var i
= 0; i
< sessionStorage
.length
; i
++) {
1157 var id
= sessionStorage
.key(i
);
1159 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1160 sessionStorage
.removeItem(id
);
1165 while (article_cache
.length
> 25) {
1166 article_cache
.shift();
1171 function cache_flush() {
1172 if (has_local_storage()) {
1173 sessionStorage
.clear();
1175 article_cache
= new Array();
1179 function cache_invalidate(id
) {
1181 if (has_local_storage()) {
1185 for (var i
= 0; i
< sessionStorage
.length
; i
++) {
1186 var key
= sessionStorage
.key(i
);
1188 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1190 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1191 sessionStorage
.removeItem(key
);
1202 while (i
< article_cache
.length
) {
1203 if (article_cache
[i
]["id"] == id
) {
1204 //console.log("cache_invalidate: removed id " + id);
1205 article_cache
.splice(i
, 1);
1212 //console.log("cache_invalidate: id not found: " + id);
1215 exception_error("cache_invalidate", e
);
1219 function getActiveArticleId() {
1220 return active_post_id
;
1223 function preloadBatchedArticles() {
1226 var query
= "?op=rpc&subop=getArticles&ids=" +
1227 preload_id_batch
.toString();
1229 new Ajax
.Request("backend.php", {
1231 onComplete: function(transport
) {
1233 preload_id_batch
= [];
1235 var articles
= JSON
.parse(transport
.responseText
);
1237 for (var i
= 0; i
< articles
.length
; i
++) {
1238 var id
= articles
[i
]['id'];
1239 if (!cache_check(id
)) {
1240 cache_inject(id
, articles
[i
]['content']);
1241 console
.log("preloaded article: " + id
);
1247 exception_error("preloadBatchedArticles", e
);
1251 function preloadArticleUnderPointer(id
) {
1253 if (getInitParam("bw_limit") == "1") return;
1255 if (post_under_pointer
== id
&& !cache_check(id
)) {
1257 console
.log("trying to preload article " + id
);
1259 var neighbor_ids
= getRelativePostIds(id
, 1);
1261 /* only request uncached articles */
1263 if (preload_id_batch
.indexOf(id
) == -1) {
1264 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1265 if (!cache_check(neighbor_ids
[i
])) {
1266 preload_id_batch
.push(neighbor_ids
[i
]);
1271 if (preload_id_batch
.indexOf(id
) == -1)
1272 preload_id_batch
.push(id
);
1274 //console.log("preload ids batch: " + preload_id_batch.toString());
1276 window
.clearTimeout(preload_timeout_id
);
1277 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1281 exception_error("preloadArticleUnderPointer", e
);
1285 function postMouseIn(id
) {
1287 if (post_under_pointer
!= id
) {
1288 post_under_pointer
= id
;
1290 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1295 exception_error("postMouseIn", e
);
1299 function postMouseOut(id
) {
1301 post_under_pointer
= false;
1303 exception_error("postMouseOut", e
);
1307 function headlines_scroll_handler(e
) {
1310 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1311 if (!_infscroll_disable
) {
1317 if (getInitParam("cdm_auto_catchup") == 1) {
1321 $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1323 if ($("headlines-frame").scrollTop
>
1324 (child
.offsetTop
+ child
.offsetHeight
/2)) {
1326 ids
.push(child
.id
.replace("RROW-", ""));
1330 if (ids
.length
> 0) {
1332 var query
= "?op=rpc&subop=catchupSelected" +
1333 "&cmode=0&ids=" + param_escape(ids
.toString());
1335 new Ajax
.Request("backend.php", {
1337 onComplete: function(transport
) {
1338 handle_rpc_json(transport
);
1340 ids
.each(function(id
) {
1341 var elem
= $("RROW-" + id
);
1342 if (elem
) elem
.removeClassName("Unread");
1348 exception_error("headlines_scroll_handler", e
);
1352 function catchupRelativeToArticle(below
) {
1357 if (!getActiveArticleId()) {
1358 alert(__("No article is selected."));
1362 var visible_ids
= getVisibleArticleIds();
1364 var ids_to_mark
= new Array();
1367 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1368 if (visible_ids
[i
] != getActiveArticleId()) {
1369 var e
= $("RROW-" + visible_ids
[i
]);
1371 if (e
&& e
.hasClassName("Unread")) {
1372 ids_to_mark
.push(visible_ids
[i
]);
1379 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1380 if (visible_ids
[i
] != getActiveArticleId()) {
1381 var e
= $("RROW-" + visible_ids
[i
]);
1383 if (e
&& e
.hasClassName("Unread")) {
1384 ids_to_mark
.push(visible_ids
[i
]);
1392 if (ids_to_mark
.length
== 0) {
1393 alert(__("No articles found to mark"));
1395 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1397 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1399 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1400 var e
= $("RROW-" + ids_to_mark
[i
]);
1401 e
.removeClassName("Unread");
1404 var query
= "?op=rpc&subop=catchupSelected" +
1405 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1407 new Ajax
.Request("backend.php", {
1409 onComplete: function(transport
) {
1410 handle_rpc_json(transport
);
1417 exception_error("catchupRelativeToArticle", e
);
1421 function cdmExpandArticle(id
) {
1426 var elem
= $("CICD-" + active_post_id
);
1428 var upd_img_pic
= $("FUPDPIC-" + id
);
1430 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1431 upd_img_pic
.src
.match("fresh_sign.png"))) {
1433 upd_img_pic
.src
= "images/blank_icon.gif";
1436 if (id
== active_post_id
&& Element
.visible(elem
))
1439 selectArticles("none");
1441 var old_offset
= $("RROW-" + id
).offsetTop
;
1443 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1445 Element
.show("CEXC-" + active_post_id
);
1448 active_post_id
= id
;
1450 elem
= $("CICD-" + id
);
1452 if (!Element
.visible(elem
)) {
1454 Element
.hide("CEXC-" + id
);
1456 if ($("CWRAP-" + id
).innerHTML
== "") {
1458 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1460 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1461 __("Loading, please wait...") + "</div>";
1463 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1465 //console.log(query);
1467 new Ajax
.Request("backend.php", {
1469 onComplete: function(transport
) {
1470 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1472 handle_rpc_json(transport
);
1474 var reply
= JSON
.parse(transport
.responseText
);
1477 var article
= reply
['article']['content'];
1478 var recv_id
= reply
['article']['id'];
1481 $("CWRAP-" + id
).innerHTML
= article
;
1484 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1492 var new_offset
= $("RROW-" + id
).offsetTop
;
1494 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1496 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1497 $("headlines-frame").scrollTop
= new_offset
;
1499 toggleUnread(id
, 0, true);
1503 exception_error("cdmExpandArticle", e
);
1509 function fixHeadlinesOrder(ids
) {
1511 for (var i
= 0; i
< ids
.length
; i
++) {
1512 var e
= $("RROW-" + ids
[i
]);
1516 e
.removeClassName("even");
1517 e
.addClassName("odd");
1519 e
.removeClassName("odd");
1520 e
.addClassName("even");
1525 exception_error("fixHeadlinesOrder", e
);
1529 function getArticleUnderPointer() {
1530 return post_under_pointer
;
1533 function zoomToArticle(event
, id
) {
1535 var cached_article
= cache_find(id
);
1537 if (dijit
.byId("ATAB-" + id
))
1538 if (!event
|| !event
.shiftKey
)
1539 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1541 if (dijit
.byId("ATSTRTIP-" + id
))
1542 dijit
.byId("ATSTRTIP-" + id
).destroyRecursive();
1544 if (cached_article
) {
1545 //closeArticlePanel();
1547 var article_pane
= new dijit
.layout
.ContentPane({
1548 title
: __("Loading...") , content
: cached_article
,
1549 style
: 'padding : 0px;',
1553 dijit
.byId("content-tabs").addChild(article_pane
);
1555 if (!event
|| !event
.shiftKey
)
1556 dijit
.byId("content-tabs").selectChild(article_pane
);
1558 if ($("PTITLE-" + id
))
1559 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1563 var query
= "?op=rpc&subop=getArticles&ids=" + param_escape(id
);
1565 notify_progress("Loading, please wait...", true);
1567 new Ajax
.Request("backend.php", {
1569 onComplete: function(transport
) {
1572 var reply
= JSON
.parse(transport
.responseText
);
1575 //closeArticlePanel();
1577 var content
= reply
[0]['content'];
1579 var article_pane
= new dijit
.layout
.ContentPane({
1580 title
: "article-" + id
, content
: content
,
1581 style
: 'padding : 0px;',
1585 dijit
.byId("content-tabs").addChild(article_pane
);
1587 if (!event
|| !event
.shiftKey
)
1588 dijit
.byId("content-tabs").selectChild(article_pane
);
1590 if ($("PTITLE-" + id
))
1591 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1598 exception_error("zoomToArticle", e
);
1602 function scrollArticle(offset
) {
1605 var ci
= $("content-insert");
1607 ci
.scrollTop
+= offset
;
1610 var hi
= $("headlines-frame");
1612 hi
.scrollTop
+= offset
;
1617 exception_error("scrollArticle", e
);
1621 function show_labels_in_headlines(transport
) {
1623 var data
= JSON
.parse(transport
.responseText
);
1626 data
['info-for-headlines'].each(function(elem
) {
1627 var ctr
= $("HLLCTR-" + elem
.id
);
1629 if (ctr
) ctr
.innerHTML
= elem
.labels
;
1633 exception_error("show_labels_in_headlines", e
);
1637 function toggleHeadlineActions() {
1639 var e
= $("headlineActionsBody");
1640 var p
= $("headlineActionsDrop");
1642 if (!Element
.visible(e
)) {
1649 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1650 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
1653 exception_error("toggleHeadlineActions", e
);
1657 /* function publishWithNote(id, def_note) {
1659 if (!def_note) def_note = '';
1661 var note = prompt(__("Please enter a note for this article:"), def_note);
1663 if (note != undefined) {
1664 togglePub(id, false, false, note);
1668 exception_error("publishWithNote", e);
1672 function emailArticle(id
) {
1675 var ids
= getSelectedArticleIds2();
1677 if (ids
.length
== 0) {
1678 alert(__("No articles are selected."));
1682 id
= ids
.toString();
1685 if (dijit
.byId("emailArticleDlg"))
1686 dijit
.byId("emailArticleDlg").destroyRecursive();
1688 var query
= "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id
);
1690 dialog
= new dijit
.Dialog({
1691 id
: "emailArticleDlg",
1692 title
: __("Forward article by email"),
1693 style
: "width: 600px",
1694 execute: function() {
1695 if (this.validate()) {
1697 new Ajax
.Request("backend.php", {
1698 parameters
: dojo
.objectToQuery(this.attr('value')),
1699 onComplete: function(transport
) {
1701 var reply
= JSON
.parse(transport
.responseText
);
1703 var error
= reply
['error'];
1706 alert(__('Error sending email:') + ' ' + error
);
1708 notify_info('Your message has been sent.');
1717 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1718 dojo
.disconnect(tmph
);
1720 new Ajax
.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1721 "backend.php?op=rpc&subop=completeEmails",
1722 { tokens
: '', paramName
: "search" });
1727 /* displayDlg('emailArticle', id,
1729 document.forms['article_email_form'].destination.focus();
1731 new Ajax.Autocompleter('destination', 'destination_choices',
1732 "backend.php?op=rpc&subop=completeEmails",
1733 { tokens: '', paramName: "search" });
1738 exception_error("emailArticle", e
);
1742 function dismissArticle(id
) {
1744 var elem
= $("RROW-" + id
);
1746 toggleUnread(id
, 0, true);
1748 new Effect
.Fade(elem
, {duration
: 0.5});
1750 active_post_id
= false;
1753 exception_error("dismissArticle", e
);
1757 function dismissSelectedArticles() {
1760 var ids
= getVisibleArticleIds();
1764 for (var i
= 0; i
< ids
.length
; i
++) {
1765 var elem
= $("RROW-" + ids
[i
]);
1767 if (elem
.className
&& elem
.hasClassName("Selected") &&
1768 ids
[i
] != active_post_id
) {
1769 new Effect
.Fade(elem
, {duration
: 0.5});
1777 selectionToggleUnread(false);
1779 fixHeadlinesOrder(tmp
);
1782 exception_error("dismissSelectedArticles", e
);
1786 function dismissReadArticles() {
1789 var ids
= getVisibleArticleIds();
1792 for (var i
= 0; i
< ids
.length
; i
++) {
1793 var elem
= $("RROW-" + ids
[i
]);
1795 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1796 !elem
.hasClassName("Selected")) {
1798 new Effect
.Fade(elem
, {duration
: 0.5});
1804 fixHeadlinesOrder(tmp
);
1807 exception_error("dismissSelectedArticles", e
);
1811 function getVisibleArticleIds() {
1816 getLoadedArticleIds().each(function(id
) {
1817 var elem
= $("RROW-" + id
);
1818 if (elem
&& Element
.visible(elem
))
1823 exception_error("getVisibleArticleIds", e
);
1829 function cdmClicked(event
, id
) {
1831 var shift_key
= event
.shiftKey
;
1835 if (!event
.ctrlKey
) {
1837 if (!getInitParam("cdm_expanded")) {
1838 return cdmExpandArticle(id
);
1841 selectArticles("none");
1844 var elem
= $("RROW-" + id
);
1847 elem
.removeClassName("Unread");
1849 var upd_img_pic
= $("FUPDPIC-" + id
);
1851 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1852 upd_img_pic
.src
.match("fresh_sign.png"))) {
1854 upd_img_pic
.src
= "images/blank_icon.gif";
1857 active_post_id
= id
;
1859 var query
= "?op=rpc&subop=catchupSelected" +
1860 "&cmode=0&ids=" + param_escape(id
);
1862 new Ajax
.Request("backend.php", {
1864 onComplete: function(transport
) {
1865 handle_rpc_json(transport
);
1872 toggleSelected(id
, true);
1873 toggleUnread(id
, 0, false);
1874 zoomToArticle(event
, id
);
1878 exception_error("cdmClicked");
1884 function postClicked(event
, id
) {
1887 if (!event
.ctrlKey
) {
1890 postOpenInNewTab(event
, id
);
1895 exception_error("postClicked");
1899 function hlOpenInNewTab(event
, id
) {
1900 toggleUnread(id
, 0, false);
1901 zoomToArticle(event
, id
);
1904 function postOpenInNewTab(event
, id
) {
1905 closeArticlePanel(id
);
1906 zoomToArticle(event
, id
);
1909 function hlClicked(event
, id
) {
1911 if (event
.which
== 2) {
1914 } else if (event
.altKey
) {
1915 openArticleInNewWindow(id
);
1916 } else if (!event
.ctrlKey
) {
1921 toggleUnread(id
, 0, false);
1922 zoomToArticle(event
, id
);
1927 exception_error("hlClicked");
1931 function getFirstVisibleHeadlineId() {
1932 var rows
= getVisibleArticleIds();
1937 function getLastVisibleHeadlineId() {
1938 var rows
= getVisibleArticleIds();
1939 return rows
[rows
.length
-1];
1942 function openArticleInNewWindow(id
) {
1943 toggleUnread(id
, 0, false);
1944 window
.open("backend.php?op=la&id=" + id
);
1947 function isCdmMode() {
1948 return getInitParam("combined_display_mode");
1951 function markHeadline(id
) {
1952 var row
= $("RROW-" + id
);
1954 var check
= $("RCHK-" + id
);
1957 check
.checked
= true;
1960 row
.addClassName("Selected");
1964 function getRelativePostIds(id
, limit
) {
1970 if (!limit
) limit
= 3;
1972 var ids
= getVisibleArticleIds();
1974 for (var i
= 0; i
< ids
.length
; i
++) {
1976 for (var k
= 1; k
<= limit
; k
++) {
1977 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
1978 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
1985 exception_error("getRelativePostIds", e
);
1991 function correctHeadlinesOffset(id
) {
1995 var container
= $("headlines-frame");
1996 var row
= $("RROW-" + id
);
1998 var viewport
= container
.offsetHeight
;
2000 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2001 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2003 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2004 //console.log("Vport: " + viewport);
2006 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2007 container
.scrollTop
= row
.offsetTop
;
2008 } else if (rel_offset_bottom
> viewport
) {
2010 /* doesn't properly work with Opera in some cases because
2011 Opera fucks up element scrolling */
2013 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2017 exception_error("correctHeadlinesOffset", e
);
2022 function headlineActionsChange(elem
) {
2025 elem
.attr('value', 'false');
2027 exception_error("headlineActionsChange", e
);
2031 function closeArticlePanel() {
2033 var tabs
= dijit
.byId("content-tabs");
2034 var child
= tabs
.selectedChildWidget
;
2036 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
2037 tabs
.removeChild(child
);
2040 if (dijit
.byId("content-insert"))
2041 dijit
.byId("headlines-wrap-inner").removeChild(
2042 dijit
.byId("content-insert"));
2046 function initHeadlinesMenu() {
2048 if (dijit
.byId("headlinesMenu"))
2049 dijit
.byId("headlinesMenu").destroyRecursive();
2054 nodes
= $$("#headlines-frame > div[id*=RROW]");
2056 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2059 nodes
.each(function(node
) {
2063 var menu
= new dijit
.Menu({
2064 id
: "headlinesMenu",
2068 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2069 var callerNode
= event
.target
, match
= null, tries
= 0;
2071 while (match
== null && callerNode
&& tries
<= 3) {
2072 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2073 callerNode
= callerNode
.parentNode
;
2077 if (match
) this.callerRowId
= parseInt(match
[1]);
2081 /* if (!isCdmMode())
2082 menu.addChild(new dijit.MenuItem({
2083 label: __("View article"),
2084 onClick: function(event) {
2085 view(this.getParent().callerRowId);
2088 menu
.addChild(new dijit
.MenuItem({
2089 label
: __("Open original article"),
2090 onClick: function(event
) {
2091 openArticleInNewWindow(this.getParent().callerRowId
);
2094 menu
.addChild(new dijit
.MenuItem({
2095 label
: __("View in a tt-rss tab"),
2096 onClick: function(event
) {
2097 hlOpenInNewTab(event
, this.getParent().callerRowId
);
2100 // menu.addChild(new dijit.MenuSeparator());
2102 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2106 menu
.addChild(new dijit
.MenuSeparator());
2108 var labelAddMenu
= new dijit
.Menu({ownerMenu
: menu
});
2109 var labelDelMenu
= new dijit
.Menu({ownerMenu
: menu
});
2111 labels
.each(function(label
) {
2112 var id
= label
.id
[0];
2113 var bare_id
= id
.substr(id
.indexOf(":")+1);
2114 var name
= label
.name
[0];
2116 bare_id
= -11-bare_id
;
2118 labelAddMenu
.addChild(new dijit
.MenuItem({
2121 onClick: function(event
) {
2122 selectionAssignLabel(this.labelId
,
2123 [this.getParent().ownerMenu
.callerRowId
]);
2126 labelDelMenu
.addChild(new dijit
.MenuItem({
2129 onClick: function(event
) {
2130 selectionRemoveLabel(this.labelId
,
2131 [this.getParent().ownerMenu
.callerRowId
]);
2136 menu
.addChild(new dijit
.PopupMenuItem({
2137 label
: __("Assign label"),
2138 popup
: labelAddMenu
,
2141 menu
.addChild(new dijit
.PopupMenuItem({
2142 label
: __("Remove label"),
2143 popup
: labelDelMenu
,
2151 exception_error("initHeadlinesMenu", e
);
2155 function tweetArticle(id
) {
2157 var query
= "?op=rpc&subop=getTweetInfo&id=" + param_escape(id
);
2162 var ts
= d
.getTime();
2164 var w
= window
.open('backend.php?op=loading', 'ttrss_tweet',
2165 "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
2167 new Ajax
.Request("backend.php", {
2169 onComplete: function(transport
) {
2170 var ti
= JSON
.parse(transport
.responseText
);
2172 var share_url
= "http://twitter.com/share?_=" + ts
+
2173 "&text=" + param_escape(ti
.title
) +
2174 "&url=" + param_escape(ti
.link
);
2176 w
.location
.href
= share_url
;
2182 exception_error("tweetArticle", e
);
2186 function editArticleNote(id
) {
2189 var query
= "backend.php?op=dlg&id=editArticleNote¶m=" + param_escape(id
);
2191 if (dijit
.byId("editNoteDlg"))
2192 dijit
.byId("editNoteDlg").destroyRecursive();
2194 dialog
= new dijit
.Dialog({
2196 title
: __("Edit article note"),
2197 style
: "width: 600px",
2198 execute: function() {
2199 if (this.validate()) {
2200 var query
= dojo
.objectToQuery(this.attr('value'));
2202 notify_progress("Saving article note...", true);
2204 new Ajax
.Request("backend.php", {
2206 onComplete: function(transport
) {
2210 var reply
= JSON
.parse(transport
.responseText
);
2212 cache_invalidate(id
);
2214 var elem
= $("POSTNOTE-" + id
);
2218 elem
.innerHTML
= reply
.note
;
2220 if (reply
.raw_length
!= 0)
2221 new Effect
.Appear(elem
);
2233 exception_error("editArticleNote", e
);
2237 function player(elem
) {
2238 var aid
= elem
.getAttribute("audio-id");
2239 var status
= elem
.getAttribute("status");
2247 elem
.innerHTML
= __("Playing...");
2248 elem
.title
= __("Click to pause");
2249 elem
.addClassName("playing");
2253 elem
.innerHTML
= __("Play");
2254 elem
.title
= __("Click to play");
2255 elem
.removeClassName("playing");
2258 elem
.setAttribute("status", status
);
2260 alert("Your browser doesn't seem to support HTML5 audio.");