]>
git.wh0rd.org - tt-rss.git/blob - viewfeed.js
fbcba1489aa5cd1b4cae12ff47e8ff5adca8e7be
1 var active_post_id
= false;
2 var last_article_view
= false;
3 var active_real_feed_id
= false;
5 var _cdm_wd_timeout
= false;
6 var _cdm_wd_vishist
= new Array();
8 var article_cache
= new Array();
10 var vgroup_last_feed
= false;
11 var post_under_pointer
= false;
13 var last_requested_article
= false;
15 var preload_id_batch
= [];
16 var preload_timeout_id
= false;
20 function catchup_callback2(transport
, callback
) {
22 console
.log("catchup_callback2 " + transport
+ ", " + callback
);
24 handle_rpc_reply(transport
);
26 setTimeout(callback
, 10);
29 exception_error("catchup_callback2", e
, transport
);
33 function headlines_callback2(transport
, feed_cur_page
) {
36 if (!handle_rpc_reply(transport
)) return;
38 loading_set_progress(25);
40 console
.log("headlines_callback2 [page=" + feed_cur_page
+ "]");
42 if (!transport_error_check(transport
)) return;
47 if (transport
.responseXML
) {
48 var headlines
= transport
.responseXML
.getElementsByTagName("headlines")[0];
50 is_cat
= headlines
.getAttribute("is_cat");
51 feed_id
= headlines
.getAttribute("id");
52 setActiveFeedId(feed_id
, is_cat
);
56 var update_btn
= document
.forms
["main_toolbar_form"].update
;
58 update_btn
.disabled
= !(feed_id
>= 0 && !is_cat
);
61 if (feed_cur_page
== 0) {
62 $("headlines-frame").scrollTop
= 0;
66 if (transport
.responseXML
) {
67 var response
= transport
.responseXML
;
69 var headlines
= response
.getElementsByTagName("headlines")[0];
71 var headlines_content
= headlines
.getElementsByTagName("content")[0];
72 var headlines_toolbar
= headlines
.getElementsByTagName("toolbar")[0];
74 var headlines_info
= response
.getElementsByTagName("headlines-info")[0];
77 headlines_info
= JSON
.parse(headlines_info
.firstChild
.nodeValue
);
79 console
.error("didn't find headlines-info object in response");
83 var headlines_count
= headlines_info
.count
;
84 var headlines_unread
= headlines_info
.unread
;
85 var disable_cache
= headlines_info
.disable_cache
;
87 vgroup_last_feed
= headlines_info
.vgroup_last_feed
;
89 if (parseInt(headlines_count
) < getInitParam("default_article_limit")) {
90 _infscroll_disable
= 1;
92 _infscroll_disable
= 0;
95 var counters
= response
.getElementsByTagName("counters")[0];
96 var articles
= response
.getElementsByTagName("article");
97 var runtime_info
= response
.getElementsByTagName("runtime-info");
99 if (feed_cur_page
== 0) {
101 dijit
.byId("headlines-frame").attr('content',
102 headlines_content
.firstChild
.nodeValue
);
104 dijit
.byId("headlines-toolbar").attr('content',
105 headlines_toolbar
.firstChild
.nodeValue
);
107 $$("#headlines-frame a.twitter-share-button").each(
108 function(btn
) { var tbtn
= new twttr
.TweetButton(btn
);
113 var cache_prefix
= "";
121 cache_invalidate(cache_prefix
+ feed_id
);
123 if (!disable_cache
) {
124 cache_inject(cache_prefix
+ feed_id
,
125 $("headlines-frame").innerHTML
, headlines_unread
);
129 console
.warn("headlines_callback: returned no data");
130 dijit
.byId("headlines-frame").attr('content',
131 "<div class='whiteBox'>" +
132 __('Could not update headlines (missing XML data)') + "</div>");
137 if (headlines_count
> 0) {
138 console
.log("adding some more headlines...");
140 var c
= dijit
.byId("headlines-frame");
141 var ids
= getSelectedArticleIds2();
143 c
.attr('content', c
.attr('content') +
144 headlines_content
.firstChild
.nodeValue
);
146 console
.log("restore selected ids: " + ids
);
148 for (var i
= 0; i
< ids
.length
; i
++) {
149 markHeadline(ids
[i
]);
155 console
.log("no new headlines received");
158 console
.warn("headlines_callback: returned no data");
159 notify_error("Error while trying to load more headlines");
165 for (var i
= 0; i
< articles
.length
; i
++) {
166 var a_id
= articles
[i
].getAttribute("id");
167 //console.log("found id: " + a_id);
168 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
171 console
.log("no cached articles received");
175 parse_counters(counters
);
180 parse_runtime_info(runtime_info
[0]);
184 console
.warn("headlines_callback: returned no XML object");
185 dijit
.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
186 __('Could not update headlines (missing XML object)') + "</div>");
190 if (_cdm_wd_timeout
) window
.clearTimeout(_cdm_wd_timeout
);
193 getActiveFeedId() != -3 &&
194 getInitParam("cdm_auto_catchup") == 1) {
195 console
.log("starting CDM watchdog");
196 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 5000);
197 _cdm_wd_vishist
= new Array();
199 console
.log("not in CDM mode or watchdog disabled");
202 _feed_cur_page
= feed_cur_page
;
203 _infscroll_request_sent
= 0;
208 exception_error("headlines_callback2", e
, transport
);
212 function render_article(article
) {
214 dijit
.byId("headlines-wrap-inner").addChild(
215 dijit
.byId("content-insert"));
217 var c
= dijit
.byId("content-insert");
220 c
.domNode
.scrollTop
= 0;
223 c
.attr('content', article
);
225 correctHeadlinesOffset(getActiveArticleId());
227 $$("#content-insert a.twitter-share-button").each(
228 function(btn
) { var tbtn
= new twttr
.TweetButton(btn
); tbtn
.render(); });
231 exception_error("render_article", e
);
235 function showArticleInHeadlines(id
) {
239 selectArticles("none");
241 var crow
= $("RROW-" + id
);
245 var article_is_unread
= crow
.hasClassName("Unread");
247 crow
.removeClassName("Unread");
249 selectArticles('none');
251 var upd_img_pic
= $("FUPDPIC-" + id
);
253 var cache_prefix
= "";
255 if (activeFeedIsCat()) {
261 var view_mode
= false;
264 view_mode
= document
.forms
['main_toolbar_form'].view_mode
;
265 view_mode
= view_mode
[view_mode
.selectedIndex
].value
;
270 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
271 upd_img_pic
.src
.match("fresh_sign.png"))) {
273 upd_img_pic
.src
= "images/blank_icon.gif";
275 cache_invalidate(cache_prefix
+ getActiveFeedId());
277 cache_inject(cache_prefix
+ getActiveFeedId(),
278 $("headlines-frame").innerHTML
,
279 getFeedUnread(getActiveFeedId()));
281 } else if (article_is_unread
&& view_mode
== "all_articles") {
283 cache_invalidate(cache_prefix
+ getActiveFeedId());
285 cache_inject(cache_prefix
+ getActiveFeedId(),
286 $("headlines-frame").innerHTML
,
287 getFeedUnread(getActiveFeedId())-1);
289 } else if (article_is_unread
) {
290 cache_invalidate(cache_prefix
+ getActiveFeedId());
295 if (article_is_unread
)
296 _force_scheduled_update
= true;
299 exception_error("showArticleInHeadlines", e
);
303 function article_callback2(transport
, id
) {
305 console
.log("article_callback2 " + id
);
307 if (!handle_rpc_reply(transport
)) return;
309 if (transport
.responseXML
) {
311 if (!transport_error_check(transport
)) return;
313 var upic
= $('FUPDPIC-' + id
);
316 upic
.src
= 'images/blank_icon.gif';
319 if (id
!= last_requested_article
) {
320 console
.log("requested article id is out of sequence, aborting");
324 // active_post_id = id;
326 //console.log("looking for articles to cache...");
328 var articles
= transport
.responseXML
.getElementsByTagName("article");
330 for (var i
= 0; i
< articles
.length
; i
++) {
331 var a_id
= articles
[i
].getAttribute("id");
333 //console.log("found id: " + a_id);
335 if (a_id
== active_post_id
) {
336 //console.log("active article, rendering...");
337 render_article(articles
[i
].firstChild
.nodeValue
);
340 cache_inject(a_id
, articles
[i
].firstChild
.nodeValue
);
344 // showArticleInHeadlines(id);
346 var reply
= transport
.responseXML
.firstChild
.firstChild
;
349 console
.warn("article_callback: returned no XML object");
350 //var f = $("content-frame");
351 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
354 var date
= new Date();
355 last_article_view
= date
.getTime() / 1000;
361 exception_error("article_callback2", e
, transport
);
367 console
.log("loading article: " + id
);
369 var cached_article
= cache_find(id
);
371 console
.log("cache check result: " + (cached_article
!= false));
375 var query
= "?op=view&id=" + param_escape(id
);
377 var neighbor_ids
= getRelativePostIds(active_post_id
);
379 /* only request uncached articles */
381 var cids_to_request
= Array();
383 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
384 if (!cache_check(neighbor_ids
[i
])) {
385 cids_to_request
.push(neighbor_ids
[i
]);
389 console
.log("additional ids: " + cids_to_request
.toString());
391 query
= query
+ "&cids=" + cids_to_request
.toString();
393 var crow
= $("RROW-" + id
);
394 var article_is_unread
= crow
.hasClassName("Unread");
397 showArticleInHeadlines(id
);
399 if (!cached_article
) {
401 var upic
= $('FUPDPIC-' + id
);
404 upic
.src
= getInitParam("sign_progress");
407 } else if (cached_article
&& article_is_unread
) {
409 query
= query
+ "&mode=prefetch";
411 render_article(cached_article
);
413 } else if (cached_article
) {
415 query
= query
+ "&mode=prefetch_old";
416 render_article(cached_article
);
422 last_requested_article
= id
;
424 new Ajax
.Request("backend.php", {
426 onComplete: function(transport
) {
427 article_callback2(transport
, id
);
433 exception_error("view", e
);
438 return toggleMark(id
);
442 return togglePub(id
);
445 function toggleMark(id
, client_only
) {
447 var query
= "?op=rpc&id=" + id
+ "&subop=mark";
449 var img
= $("FMPIC-" + id
);
453 if (img
.src
.match("mark_unset")) {
454 img
.src
= img
.src
.replace("mark_unset", "mark_set");
455 img
.alt
= __("Unstar article");
456 query
= query
+ "&mark=1";
459 img
.src
= img
.src
.replace("mark_set", "mark_unset");
460 img
.alt
= __("Star article");
461 query
= query
+ "&mark=0";
465 new Ajax
.Request("backend.php", {
467 onComplete: function(transport
) {
468 handle_rpc_reply(transport
);
473 exception_error("toggleMark", e
);
477 function togglePub(id
, client_only
, no_effects
, note
) {
479 var query
= "?op=rpc&id=" + id
+ "&subop=publ";
481 if (note
!= undefined) {
482 query
= query
+ "¬e=" + param_escape(note
);
484 query
= query
+ "¬e=undefined";
487 var img
= $("FPPIC-" + id
);
491 if (img
.src
.match("pub_unset") || note
!= undefined) {
492 img
.src
= img
.src
.replace("pub_unset", "pub_set");
493 img
.alt
= __("Unpublish article");
494 query
= query
+ "&pub=1";
497 img
.src
= img
.src
.replace("pub_set", "pub_unset");
498 img
.alt
= __("Publish article");
500 query
= query
+ "&pub=0";
504 new Ajax
.Request("backend.php", {
506 onComplete: function(transport
) {
507 handle_rpc_reply(transport
);
509 var note
= transport
.responseXML
.getElementsByTagName("note")[0];
512 var note_id
= note
.getAttribute("id");
513 var note_size
= note
.getAttribute("size");
514 var note_content
= note
.firstChild
.nodeValue
;
516 var container
= $('POSTNOTE-' + note_id
);
518 cache_invalidate(note_id
);
521 if (note_size
== "0") {
522 Element
.hide(container
);
524 container
.innerHTML
= note_content
;
525 Element
.show(container
);
534 exception_error("togglePub", e
);
538 function moveToPost(mode
) {
542 var rows
= getVisibleArticleIds();
547 if (!$('RROW-' + active_post_id
)) {
548 active_post_id
= false;
551 if (active_post_id
== false) {
552 next_id
= getFirstVisibleHeadlineId();
553 prev_id
= getLastVisibleHeadlineId();
555 for (var i
= 0; i
< rows
.length
; i
++) {
556 if (rows
[i
] == active_post_id
) {
563 if (mode
== "next") {
567 cdmExpandArticle(next_id
);
568 cdmScrollToArticleId(next_id
);
571 correctHeadlinesOffset(next_id
);
572 view(next_id
, getActiveFeedId());
577 if (mode
== "prev") {
580 cdmExpandArticle(prev_id
);
581 cdmScrollToArticleId(prev_id
);
583 correctHeadlinesOffset(prev_id
);
584 view(prev_id
, getActiveFeedId());
590 exception_error("moveToPost", e
);
594 function toggleSelected(id
, force_on
) {
597 var cb
= $("RCHK-" + id
);
598 var row
= $("RROW-" + id
);
601 if (row
.hasClassName('Selected') && !force_on
) {
602 row
.removeClassName('Selected');
603 if (cb
) cb
.checked
= false;
605 row
.addClassName('Selected');
606 if (cb
) cb
.checked
= true;
610 exception_error("toggleSelected", e
);
614 function toggleUnread_afh(effect
) {
617 var elem
= effect
.element
;
618 elem
.style
.backgroundColor
= "";
621 exception_error("toggleUnread_afh", e
);
625 function toggleUnread(id
, cmode
, effect
) {
628 var row
= $("RROW-" + id
);
630 if (cmode
== undefined || cmode
== 2) {
631 if (row
.hasClassName("Unread")) {
632 row
.removeClassName("Unread");
635 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
636 afterFinish
: toggleUnread_afh
,
637 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
641 row
.addClassName("Unread");
644 } else if (cmode
== 0) {
646 row
.removeClassName("Unread");
649 new Effect
.Highlight(row
, {duration
: 1, startcolor
: "#fff7d5",
650 afterFinish
: toggleUnread_afh
,
651 queue
: { position
:'end', scope
: 'TMRQ-' + id
, limit
: 1 } } );
654 } else if (cmode
== 1) {
655 row
.addClassName("Unread");
658 if (cmode
== undefined) cmode
= 2;
660 var query
= "?op=rpc&subop=catchupSelected" +
661 "&cmode=" + param_escape(cmode
) + "&ids=" + param_escape(id
);
663 // notify_progress("Loading, please wait...");
665 new Ajax
.Request("backend.php", {
667 onComplete: function(transport
) {
668 handle_rpc_reply(transport
);
674 exception_error("toggleUnread", e
);
678 function selectionRemoveLabel(id
, ids
) {
681 if (!ids
) var ids
= getSelectedArticleIds2();
683 if (ids
.length
== 0) {
684 alert(__("No articles are selected."));
688 // var ok = confirm(__("Remove selected articles from label?"));
692 var query
= "?op=rpc&subop=removeFromLabel&ids=" +
693 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
697 // notify_progress("Loading, please wait...");
699 cache_invalidate("F:" + (-11 - id
));
701 new Ajax
.Request("backend.php", {
703 onComplete: function(transport
) {
704 show_labels_in_headlines(transport
);
705 handle_rpc_reply(transport
);
711 exception_error("selectionAssignLabel", e
);
716 function selectionAssignLabel(id
, ids
) {
719 if (!ids
) ids
= getSelectedArticleIds2();
721 if (ids
.length
== 0) {
722 alert(__("No articles are selected."));
726 // var ok = confirm(__("Assign selected articles to label?"));
730 cache_invalidate("F:" + (-11 - id
));
732 var query
= "?op=rpc&subop=assignToLabel&ids=" +
733 param_escape(ids
.toString()) + "&lid=" + param_escape(id
);
737 // notify_progress("Loading, please wait...");
739 new Ajax
.Request("backend.php", {
741 onComplete: function(transport
) {
742 show_labels_in_headlines(transport
);
743 handle_rpc_reply(transport
);
749 exception_error("selectionAssignLabel", e
);
754 function selectionToggleUnread(set_state
, callback_func
, no_error
) {
756 var rows
= getSelectedArticleIds2();
758 if (rows
.length
== 0 && !no_error
) {
759 alert(__("No articles are selected."));
763 for (i
= 0; i
< rows
.length
; i
++) {
764 var row
= $("RROW-" + rows
[i
]);
766 if (set_state
== undefined) {
767 if (row
.hasClassName("Unread")) {
768 row
.removeClassName("Unread");
770 row
.addClassName("Unread");
774 if (set_state
== false) {
775 row
.removeClassName("Unread");
778 if (set_state
== true) {
779 row
.addClassName("Unread");
784 if (rows
.length
> 0) {
788 if (set_state
== undefined) {
790 } else if (set_state
== true) {
792 } else if (set_state
== false) {
796 var query
= "?op=rpc&subop=catchupSelected" +
797 "&cmode=" + cmode
+ "&ids=" + param_escape(rows
.toString());
799 notify_progress("Loading, please wait...");
801 new Ajax
.Request("backend.php", {
803 onComplete: function(transport
) {
804 catchup_callback2(transport
, callback_func
);
810 exception_error("selectionToggleUnread", e
);
814 function selectionToggleMarked() {
817 var rows
= getSelectedArticleIds2();
819 if (rows
.length
== 0) {
820 alert(__("No articles are selected."));
824 for (i
= 0; i
< rows
.length
; i
++) {
825 toggleMark(rows
[i
], true, true);
828 if (rows
.length
> 0) {
830 var query
= "?op=rpc&subop=markSelected&ids=" +
831 param_escape(rows
.toString()) + "&cmode=2";
833 new Ajax
.Request("backend.php", {
835 onComplete: function(transport
) {
836 handle_rpc_reply(transport
);
842 exception_error("selectionToggleMarked", e
);
846 function selectionTogglePublished() {
849 var rows
= getSelectedArticleIds2();
851 if (rows
.length
== 0) {
852 alert(__("No articles are selected."));
856 for (i
= 0; i
< rows
.length
; i
++) {
857 togglePub(rows
[i
], true, true);
860 if (rows
.length
> 0) {
862 var query
= "?op=rpc&subop=publishSelected&ids=" +
863 param_escape(rows
.toString()) + "&cmode=2";
865 new Ajax
.Request("backend.php", {
867 onComplete: function(transport
) {
868 handle_rpc_reply(transport
);
874 exception_error("selectionToggleMarked", e
);
878 function getSelectedArticleIds2() {
882 $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
884 rv
.push(child
.id
.replace("RROW-", ""));
890 function getLoadedArticleIds() {
893 var children
= $$("#headlines-frame > div[id*=RROW-]");
895 children
.each(function(child
) {
896 rv
.push(child
.id
.replace("RROW-", ""));
903 // mode = all,none,unread,invert
904 function selectArticles(mode
) {
907 var children
= $$("#headlines-frame > div[id*=RROW]");
909 children
.each(function(child
) {
910 var id
= child
.id
.replace("RROW-", "");
911 var cb
= $("RCHK-" + id
);
914 child
.addClassName("Selected");
916 } else if (mode
== "unread") {
917 if (child
.hasClassName("Unread")) {
918 child
.addClassName("Selected");
921 child
.removeClassName("Selected");
924 } else if (mode
== "invert") {
925 if (child
.hasClassName("Selected")) {
926 child
.removeClassName("Selected");
929 child
.addClassName("Selected");
934 child
.removeClassName("Selected");
940 exception_error("selectArticles", e
);
944 function catchupPage() {
946 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
948 var str
= __("Mark all visible articles in %s as read?");
950 str
= str
.replace("%s", fn
);
952 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
956 selectArticles('all');
957 selectionToggleUnread(false, 'viewCurrentFeed()', true)
958 selectArticles('none');
961 function deleteSelection() {
965 var rows
= getSelectedArticleIds2();
967 if (rows
.length
== 0) {
968 alert(__("No articles are selected."));
972 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
976 if (getActiveFeedId() != 0) {
977 str
= __("Delete %d selected articles in %s?");
979 str
= __("Delete %d selected articles?");
982 str
= str
.replace("%d", rows
.length
);
983 str
= str
.replace("%s", fn
);
985 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
989 query
= "?op=rpc&subop=delete&ids=" + param_escape(rows
);
993 new Ajax
.Request("backend.php", {
995 onComplete: function(transport
) {
1000 exception_error("deleteSelection", e
);
1004 function archiveSelection() {
1008 var rows
= getSelectedArticleIds2();
1010 if (rows
.length
== 0) {
1011 alert(__("No articles are selected."));
1015 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1019 if (getActiveFeedId() != 0) {
1020 str
= __("Archive %d selected articles in %s?");
1023 str
= __("Move %d archived articles back?");
1027 str
= str
.replace("%d", rows
.length
);
1028 str
= str
.replace("%s", fn
);
1030 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1034 query
= "?op=rpc&subop="+op
+"&ids=" + param_escape(rows
);
1038 for (var i
= 0; i
< rows
.length
; i
++) {
1039 cache_invalidate(rows
[i
]);
1042 new Ajax
.Request("backend.php", {
1044 onComplete: function(transport
) {
1049 exception_error("archiveSelection", e
);
1053 function catchupSelection() {
1057 var rows
= getSelectedArticleIds2();
1059 if (rows
.length
== 0) {
1060 alert(__("No articles are selected."));
1064 var fn
= getFeedName(getActiveFeedId(), activeFeedIsCat());
1066 var str
= __("Mark %d selected articles in %s as read?");
1068 str
= str
.replace("%d", rows
.length
);
1069 str
= str
.replace("%s", fn
);
1071 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str
)) {
1075 selectionToggleUnread(false, 'viewCurrentFeed()', true)
1078 exception_error("catchupSelection", e
);
1082 function editArticleTags(id
, feed_id
, cdm_enabled
) {
1083 displayDlg('editArticleTags', id
,
1085 $("tags_str").focus();
1087 new Ajax
.Autocompleter('tags_str', 'tags_choices',
1088 "backend.php?op=rpc&subop=completeTags",
1089 { tokens
: ',', paramName
: "search" });
1093 function editTagsSave() {
1095 notify_progress("Saving article tags...");
1097 var form
= document
.forms
["tag_edit_form"];
1099 var query
= Form
.serialize("tag_edit_form");
1101 query
= "?op=rpc&subop=setArticleTags&" + query
;
1105 new Ajax
.Request("backend.php", {
1107 onComplete: function(transport
) {
1109 //console.log("tags saved...");
1114 if (transport
.responseXML
) {
1115 var tags_str
= transport
.responseXML
.getElementsByTagName("tags-str")[0];
1118 var id
= tags_str
.getAttribute("id");
1121 var tags
= $("ATSTR-" + id
);
1123 tags
.innerHTML
= tags_str
.firstChild
.nodeValue
;
1126 cache_invalidate(id
);
1132 exception_error("editTagsSave", e
);
1137 function editTagsInsert() {
1140 var form
= document
.forms
["tag_edit_form"];
1142 var found_tags
= form
.found_tags
;
1143 var tags_str
= form
.tags_str
;
1145 var tag
= found_tags
[found_tags
.selectedIndex
].value
;
1147 if (tags_str
.value
.length
> 0 &&
1148 tags_str
.value
.lastIndexOf(", ") != tags_str
.value
.length
- 2) {
1150 tags_str
.value
= tags_str
.value
+ ", ";
1153 tags_str
.value
= tags_str
.value
+ tag
+ ", ";
1155 found_tags
.selectedIndex
= 0;
1158 exception_error("editTagsInsert", e
);
1162 function cdmScrollToArticleId(id
) {
1164 var ctr
= $("headlines-frame");
1165 var e
= $("RROW-" + id
);
1167 if (!e
|| !ctr
) return;
1169 ctr
.scrollTop
= e
.offsetTop
;
1172 exception_error("cdmScrollToArticleId", e
);
1176 function cdmWatchdog() {
1180 var ctr
= $("headlines-frame");
1184 var ids
= new Array();
1186 var e
= ctr
.firstChild
;
1189 if (e
.className
&& e
.hasClassName("Unread") && e
.id
&&
1190 e
.id
.match("RROW-")) {
1192 // article fits in viewport OR article is longer than viewport and
1193 // its bottom is visible
1195 if (ctr
.scrollTop
<= e
.offsetTop
&& e
.offsetTop
+ e
.offsetHeight
<=
1196 ctr
.scrollTop
+ ctr
.offsetHeight
) {
1198 // console.log(e.id + " is visible " + e.offsetTop + "." +
1199 // (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1200 // (ctr.scrollTop + ctr.offsetHeight));
1202 ids
.push(e
.id
.replace("RROW-", ""));
1204 } else if (e
.offsetHeight
> ctr
.offsetHeight
&&
1205 e
.offsetTop
+ e
.offsetHeight
>= ctr
.scrollTop
&&
1206 e
.offsetTop
+ e
.offsetHeight
<= ctr
.scrollTop
+ ctr
.offsetHeight
) {
1208 ids
.push(e
.id
.replace("RROW-", ""));
1212 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1214 /* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1215 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1217 ids.push(e.id.replace("RROW-", ""));
1226 console
.log("cdmWatchdog, ids= " + ids
.toString());
1228 if (ids
.length
> 0) {
1230 for (var i
= 0; i
< ids
.length
; i
++) {
1231 var e
= $("RROW-" + ids
[i
]);
1233 e
.removeClassName("Unread");
1237 var query
= "?op=rpc&subop=catchupSelected" +
1238 "&cmode=0" + "&ids=" + param_escape(ids
.toString());
1240 new Ajax
.Request("backend.php", {
1242 onComplete: function(transport
) {
1243 handle_rpc_reply(transport
);
1248 _cdm_wd_timeout
= window
.setTimeout("cdmWatchdog()", 4000);
1251 exception_error("cdmWatchdog", e
);
1257 function cache_inject(id
, article
, param
) {
1260 if (!cache_check_param(id
, param
)) {
1261 //console.log("cache_article: miss: " + id + " [p=" + param + "]");
1263 var date
= new Date();
1264 var ts
= Math
.round(date
.getTime() / 1000);
1268 cache_obj
["id"] = id
;
1269 cache_obj
["data"] = article
;
1270 cache_obj
["param"] = param
;
1272 if (param
) id
= id
+ ":" + param
;
1274 cache_added
["TS:" + id
] = ts
;
1276 if (has_local_storage())
1277 sessionStorage
.setItem(id
, JSON
.stringify(cache_obj
));
1279 article_cache
.push(cache_obj
);
1282 //console.log("cache_article: hit: " + id + " [p=" + param + "]");
1285 exception_error("cache_inject", e
);
1289 function cache_find(id
) {
1291 if (has_local_storage()) {
1292 var cache_obj
= sessionStorage
.getItem(id
);
1295 cache_obj
= JSON
.parse(cache_obj
);
1298 return cache_obj
['data'];
1302 for (var i
= 0; i
< article_cache
.length
; i
++) {
1303 if (article_cache
[i
]["id"] == id
) {
1304 return article_cache
[i
]["data"];
1311 function cache_find_param(id
, param
) {
1313 if (has_local_storage()) {
1315 if (param
) id
= id
+ ":" + param
;
1317 var cache_obj
= sessionStorage
.getItem(id
);
1320 cache_obj
= JSON
.parse(cache_obj
);
1323 return cache_obj
['data'];
1327 for (var i
= 0; i
< article_cache
.length
; i
++) {
1328 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1329 return article_cache
[i
]["data"];
1337 function cache_check(id
) {
1338 if (has_local_storage()) {
1339 if (sessionStorage
.getItem(id
))
1342 for (var i
= 0; i
< article_cache
.length
; i
++) {
1343 if (article_cache
[i
]["id"] == id
) {
1351 function cache_check_param(id
, param
) {
1352 if (has_local_storage()) {
1354 if (param
) id
= id
+ ":" + param
;
1356 if (sessionStorage
.getItem(id
))
1360 for (var i
= 0; i
< article_cache
.length
; i
++) {
1361 if (article_cache
[i
]["id"] == id
&& article_cache
[i
]["param"] == param
) {
1369 function cache_expire() {
1370 if (has_local_storage()) {
1372 var date
= new Date();
1373 var timestamp
= Math
.round(date
.getTime() / 1000);
1375 for (var i
= 0; i
< sessionStorage
.length
; i
++) {
1377 var id
= sessionStorage
.key(i
);
1379 if (timestamp
- cache_added
["TS:" + id
] > 180) {
1380 sessionStorage
.removeItem(id
);
1385 while (article_cache
.length
> 25) {
1386 article_cache
.shift();
1391 function cache_flush() {
1392 if (has_local_storage()) {
1393 sessionStorage
.clear();
1395 article_cache
= new Array();
1399 function cache_invalidate(id
) {
1401 if (has_local_storage()) {
1405 for (var i
= 0; i
< sessionStorage
.length
; i
++) {
1406 var key
= sessionStorage
.key(i
);
1408 // console.warn("cache_invalidate: " + key_id + " cmp " + id);
1410 if (key
== id
|| key
.indexOf(id
+ ":") == 0) {
1411 sessionStorage
.removeItem(key
);
1422 while (i
< article_cache
.length
) {
1423 if (article_cache
[i
]["id"] == id
) {
1424 //console.log("cache_invalidate: removed id " + id);
1425 article_cache
.splice(i
, 1);
1432 //console.log("cache_invalidate: id not found: " + id);
1435 exception_error("cache_invalidate", e
);
1439 function getActiveArticleId() {
1440 return active_post_id
;
1443 function preloadBatchedArticles() {
1446 var query
= "?op=rpc&subop=getArticles&ids=" +
1447 preload_id_batch
.toString();
1449 new Ajax
.Request("backend.php", {
1451 onComplete: function(transport
) {
1453 preload_id_batch
= [];
1455 var articles
= transport
.responseXML
.getElementsByTagName("article");
1457 for (var i
= 0; i
< articles
.length
; i
++) {
1458 var id
= articles
[i
].getAttribute("id");
1459 if (!cache_check(id
)) {
1460 cache_inject(id
, articles
[i
].firstChild
.nodeValue
);
1461 console
.log("preloaded article: " + id
);
1467 exception_error("preloadBatchedArticles", e
);
1471 function preloadArticleUnderPointer(id
) {
1473 if (getInitParam("bw_limit") == "1") return;
1475 if (post_under_pointer
== id
&& !cache_check(id
)) {
1477 console
.log("trying to preload article " + id
);
1479 var neighbor_ids
= getRelativePostIds(id
, 1);
1481 /* only request uncached articles */
1483 if (preload_id_batch
.indexOf(id
) == -1) {
1484 for (var i
= 0; i
< neighbor_ids
.length
; i
++) {
1485 if (!cache_check(neighbor_ids
[i
])) {
1486 preload_id_batch
.push(neighbor_ids
[i
]);
1491 if (preload_id_batch
.indexOf(id
) == -1)
1492 preload_id_batch
.push(id
);
1494 //console.log("preload ids batch: " + preload_id_batch.toString());
1496 window
.clearTimeout(preload_timeout_id
);
1497 preload_batch_timeout_id
= window
.setTimeout('preloadBatchedArticles()', 1000);
1501 exception_error("preloadArticleUnderPointer", e
);
1505 function postMouseIn(id
) {
1507 if (post_under_pointer
!= id
) {
1508 post_under_pointer
= id
;
1510 window
.setTimeout("preloadArticleUnderPointer(" + id
+ ")", 250);
1515 exception_error("postMouseIn", e
);
1519 function postMouseOut(id
) {
1521 post_under_pointer
= false;
1523 exception_error("postMouseOut", e
);
1527 function headlines_scroll_handler(e
) {
1530 if (e
.scrollTop
+ e
.offsetHeight
> e
.scrollHeight
- 100) {
1531 if (!_infscroll_disable
) {
1537 exception_error("headlines_scroll_handler", e
);
1541 function catchupRelativeToArticle(below
) {
1546 if (!getActiveArticleId()) {
1547 alert(__("No article is selected."));
1551 var visible_ids
= getVisibleArticleIds();
1553 var ids_to_mark
= new Array();
1556 for (var i
= 0; i
< visible_ids
.length
; i
++) {
1557 if (visible_ids
[i
] != getActiveArticleId()) {
1558 var e
= $("RROW-" + visible_ids
[i
]);
1560 if (e
&& e
.hasClassName("Unread")) {
1561 ids_to_mark
.push(visible_ids
[i
]);
1568 for (var i
= visible_ids
.length
-1; i
>= 0; i
--) {
1569 if (visible_ids
[i
] != getActiveArticleId()) {
1570 var e
= $("RROW-" + visible_ids
[i
]);
1572 if (e
&& e
.hasClassName("Unread")) {
1573 ids_to_mark
.push(visible_ids
[i
]);
1581 if (ids_to_mark
.length
== 0) {
1582 alert(__("No articles found to mark"));
1584 var msg
= __("Mark %d article(s) as read?").replace("%d", ids_to_mark
.length
);
1586 if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg
)) {
1588 for (var i
= 0; i
< ids_to_mark
.length
; i
++) {
1589 var e
= $("RROW-" + ids_to_mark
[i
]);
1590 e
.removeClassName("Unread");
1593 var query
= "?op=rpc&subop=catchupSelected" +
1594 "&cmode=0" + "&ids=" + param_escape(ids_to_mark
.toString());
1596 new Ajax
.Request("backend.php", {
1598 onComplete: function(transport
) {
1599 catchup_callback2(transport
);
1606 exception_error("catchupRelativeToArticle", e
);
1610 function cdmExpandArticle(id
) {
1615 var elem
= $("CICD-" + active_post_id
);
1617 var upd_img_pic
= $("FUPDPIC-" + id
);
1619 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
1620 upd_img_pic
.src
.match("fresh_sign.png"))) {
1622 upd_img_pic
.src
= "images/blank_icon.gif";
1625 if (id
== active_post_id
&& Element
.visible(elem
))
1628 selectArticles("none");
1630 var old_offset
= $("RROW-" + id
).offsetTop
;
1632 if (active_post_id
&& elem
&& !getInitParam("cdm_expanded")) {
1634 Element
.show("CEXC-" + active_post_id
);
1637 active_post_id
= id
;
1639 elem
= $("CICD-" + id
);
1641 if (!Element
.visible(elem
)) {
1643 Element
.hide("CEXC-" + id
);
1645 if ($("CWRAP-" + id
).innerHTML
== "") {
1647 $("FUPDPIC-" + id
).src
= "images/indicator_tiny.gif";
1649 $("CWRAP-" + id
).innerHTML
= "<div class=\"insensitive\">" +
1650 __("Loading, please wait...") + "</div>";
1652 var query
= "?op=rpc&subop=cdmGetArticle&id=" + param_escape(id
);
1654 //console.log(query);
1656 new Ajax
.Request("backend.php", {
1658 onComplete: function(transport
) {
1659 $("FUPDPIC-" + id
).src
= 'images/blank_icon.gif';
1661 if (transport
.responseXML
) {
1662 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1663 var recv_id
= article
.getAttribute("id");
1666 $("CWRAP-" + id
).innerHTML
= article
.firstChild
.nodeValue
;
1669 $("CWRAP-" + id
).innerHTML
= __("Unable to load article.");
1677 var new_offset
= $("RROW-" + id
).offsetTop
;
1679 $("headlines-frame").scrollTop
+= (new_offset
-old_offset
);
1681 if ($("RROW-" + id
).offsetTop
!= old_offset
)
1682 $("headlines-frame").scrollTop
= new_offset
;
1684 toggleUnread(id
, 0, true);
1688 exception_error("cdmExpandArticle", e
);
1694 function fixHeadlinesOrder(ids
) {
1696 for (var i
= 0; i
< ids
.length
; i
++) {
1697 var e
= $("RROW-" + ids
[i
]);
1701 e
.removeClassName("even");
1702 e
.addClassName("odd");
1704 e
.removeClassName("odd");
1705 e
.addClassName("even");
1710 exception_error("fixHeadlinesOrder", e
);
1714 function getArticleUnderPointer() {
1715 return post_under_pointer
;
1718 function zoomToArticle(event
, id
) {
1720 var cached_article
= cache_find(id
);
1722 if (dijit
.byId("ATAB-" + id
))
1723 if (!event
|| !event
.shiftKey
)
1724 return dijit
.byId("content-tabs").selectChild(dijit
.byId("ATAB-" + id
));
1726 if (cached_article
) {
1727 //closeArticlePanel();
1729 var article_pane
= new dijit
.layout
.ContentPane({
1730 title
: __("Loading...") , content
: cached_article
,
1731 style
: 'padding : 0px;',
1735 dijit
.byId("content-tabs").addChild(article_pane
);
1737 $$("#ATAB-"+id
+" a.twitter-share-button").each(
1738 function(btn
) { var tbtn
= new twttr
.TweetButton(btn
); tbtn
.render(); });
1740 if (!event
|| !event
.shiftKey
)
1741 dijit
.byId("content-tabs").selectChild(article_pane
);
1743 if ($("PTITLE-" + id
))
1744 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1748 var query
= "?op=rpc&subop=getArticles&ids=" + param_escape(id
);
1750 notify_progress("Loading, please wait...", true);
1752 new Ajax
.Request("backend.php", {
1754 onComplete: function(transport
) {
1757 if (transport
.responseXML
) {
1758 //closeArticlePanel();
1760 var article
= transport
.responseXML
.getElementsByTagName("article")[0];
1761 var content
= article
.firstChild
.nodeValue
;
1763 var article_pane
= new dijit
.layout
.ContentPane({
1764 title
: "article-" + id
, content
: content
,
1765 style
: 'padding : 0px;',
1769 dijit
.byId("content-tabs").addChild(article_pane
);
1771 $$("#ATAB-"+id
+" a.twitter-share-button").each(
1772 function(btn
) { var tbtn
= new twttr
.TweetButton(btn
);
1775 if (!event
|| !event
.shiftKey
)
1776 dijit
.byId("content-tabs").selectChild(article_pane
);
1778 if ($("PTITLE-" + id
))
1779 article_pane
.attr('title', $("PTITLE-" + id
).innerHTML
);
1786 exception_error("zoomToArticle", e
);
1790 function scrollArticle(offset
) {
1793 var ci
= $("content-insert");
1795 ci
.scrollTop
+= offset
;
1798 var hi
= $("headlines-frame");
1800 hi
.scrollTop
+= offset
;
1805 exception_error("scrollArticle", e
);
1809 function show_labels_in_headlines(transport
) {
1811 if (transport
.responseXML
) {
1812 var info
= transport
.responseXML
.getElementsByTagName("info-for-headlines")[0];
1814 var elems
= info
.getElementsByTagName("entry");
1816 for (var l
= 0; l
< elems
.length
; l
++) {
1817 var e_id
= elems
[l
].getAttribute("id");
1821 var ctr
= $("HLLCTR-" + e_id
);
1824 ctr
.innerHTML
= elems
[l
].firstChild
.nodeValue
;
1832 exception_error("show_labels_in_headlines", e
);
1837 function toggleHeadlineActions() {
1839 var e
= $("headlineActionsBody");
1840 var p
= $("headlineActionsDrop");
1842 if (!Element
.visible(e
)) {
1849 e
.style
.left
= (p
.offsetLeft
+ 1) + "px";
1850 e
.style
.top
= (p
.offsetTop
+ p
.offsetHeight
+ 2) + "px";
1853 exception_error("toggleHeadlineActions", e
);
1857 function publishWithNote(id
, def_note
) {
1859 if (!def_note
) def_note
= '';
1861 var note
= prompt(__("Please enter a note for this article:"), def_note
);
1863 if (note
!= undefined) {
1864 togglePub(id
, false, false, note
);
1868 exception_error("publishWithNote", e
);
1872 function emailArticle(id
) {
1875 var ids
= getSelectedArticleIds2();
1877 if (ids
.length
== 0) {
1878 alert(__("No articles are selected."));
1882 id
= ids
.toString();
1885 if (dijit
.byId("emailArticleDlg"))
1886 dijit
.byId("emailArticleDlg").destroyRecursive();
1888 var query
= "backend.php?op=dlg&id=emailArticle¶m=" + param_escape(id
);
1890 dialog
= new dijit
.Dialog({
1891 id
: "emailArticleDlg",
1892 title
: __("Forward article by email"),
1893 style
: "width: 600px",
1894 execute: function() {
1895 if (this.validate()) {
1897 new Ajax
.Request("backend.php", {
1898 parameters
: dojo
.objectToQuery(this.attr('value')),
1899 onComplete: function(transport
) {
1901 var error
= transport
.responseXML
.getElementsByTagName('error')[0];
1904 alert(__('Error sending email:') + ' ' + error
.firstChild
.nodeValue
);
1906 notify_info('Your message has been sent.');
1915 var tmph
= dojo
.connect(dialog
, 'onLoad', function() {
1916 dojo
.disconnect(tmph
);
1918 new Ajax
.Autocompleter('emailArticleDlg_destination', 'emailArticleDlg_dst_choices',
1919 "backend.php?op=rpc&subop=completeEmails",
1920 { tokens
: '', paramName
: "search" });
1925 /* displayDlg('emailArticle', id,
1927 document.forms['article_email_form'].destination.focus();
1929 new Ajax.Autocompleter('destination', 'destination_choices',
1930 "backend.php?op=rpc&subop=completeEmails",
1931 { tokens: '', paramName: "search" });
1936 exception_error("emailArticle", e
);
1940 function dismissArticle(id
) {
1942 var elem
= $("RROW-" + id
);
1944 toggleUnread(id
, 0, true);
1946 new Effect
.Fade(elem
, {duration
: 0.5});
1948 active_post_id
= false;
1951 exception_error("dismissArticle", e
);
1955 function dismissSelectedArticles() {
1958 var ids
= getVisibleArticleIds();
1962 for (var i
= 0; i
< ids
.length
; i
++) {
1963 var elem
= $("RROW-" + ids
[i
]);
1965 if (elem
.className
&& elem
.hasClassName("Selected") &&
1966 ids
[i
] != active_post_id
) {
1967 new Effect
.Fade(elem
, {duration
: 0.5});
1975 selectionToggleUnread(false);
1977 fixHeadlinesOrder(tmp
);
1980 exception_error("dismissSelectedArticles", e
);
1984 function dismissReadArticles() {
1987 var ids
= getVisibleArticleIds();
1990 for (var i
= 0; i
< ids
.length
; i
++) {
1991 var elem
= $("RROW-" + ids
[i
]);
1993 if (elem
.className
&& !elem
.hasClassName("Unread") &&
1994 !elem
.hasClassName("Selected")) {
1996 new Effect
.Fade(elem
, {duration
: 0.5});
2002 fixHeadlinesOrder(tmp
);
2005 exception_error("dismissSelectedArticles", e
);
2009 function getVisibleArticleIds() {
2014 getLoadedArticleIds().each(function(id
) {
2015 var elem
= $("RROW-" + id
);
2016 if (elem
&& Element
.visible(elem
))
2021 exception_error("getVisibleArticleIds", e
);
2027 function cdmClicked(event
, id
) {
2029 var shift_key
= event
.shiftKey
;
2033 if (!event
.ctrlKey
) {
2035 if (!getInitParam("cdm_expanded")) {
2036 return cdmExpandArticle(id
);
2039 selectArticles("none");
2042 var elem
= $("RROW-" + id
);
2045 elem
.removeClassName("Unread");
2047 var upd_img_pic
= $("FUPDPIC-" + id
);
2049 if (upd_img_pic
&& (upd_img_pic
.src
.match("updated.png") ||
2050 upd_img_pic
.src
.match("fresh_sign.png"))) {
2052 upd_img_pic
.src
= "images/blank_icon.gif";
2055 active_post_id
= id
;
2057 var query
= "?op=rpc&subop=catchupSelected" +
2058 "&cmode=0&ids=" + param_escape(id
);
2060 new Ajax
.Request("backend.php", {
2062 onComplete: function(transport
) {
2063 handle_rpc_reply(transport
);
2068 toggleSelected(id
, true);
2069 toggleUnread(id
, 0, false);
2070 zoomToArticle(event
, id
);
2074 exception_error("cdmClicked");
2080 function postClicked(event
, id
) {
2083 if (!event
.ctrlKey
) {
2086 postOpenInNewTab(event
, id
);
2091 exception_error("postClicked");
2095 function hlOpenInNewTab(event
, id
) {
2096 toggleUnread(id
, 0, false);
2097 zoomToArticle(event
, id
);
2100 function postOpenInNewTab(event
, id
) {
2101 closeArticlePanel(id
);
2102 zoomToArticle(event
, id
);
2105 function hlClicked(event
, id
) {
2108 openArticleInNewWindow(id
);
2109 } else if (!event
.ctrlKey
) {
2114 toggleUnread(id
, 0, false);
2115 zoomToArticle(event
, id
);
2120 exception_error("hlClicked");
2124 function getFirstVisibleHeadlineId() {
2125 var rows
= getVisibleArticleIds();
2130 function getLastVisibleHeadlineId() {
2131 var rows
= getVisibleArticleIds();
2132 return rows
[rows
.length
-1];
2135 function openArticleInNewWindow(id
) {
2136 toggleUnread(id
, 0, false);
2137 window
.open("backend.php?op=la&id=" + id
);
2140 function isCdmMode() {
2141 return getInitParam("combined_display_mode");
2144 function markHeadline(id
) {
2145 var row
= $("RROW-" + id
);
2147 var check
= $("RCHK-" + id
);
2150 check
.checked
= true;
2153 row
.addClassName("Selected");
2157 function getRelativePostIds(id
, limit
) {
2163 if (!limit
) limit
= 3;
2165 var ids
= getVisibleArticleIds();
2167 for (var i
= 0; i
< ids
.length
; i
++) {
2169 for (var k
= 1; k
<= limit
; k
++) {
2170 if (i
> k
-1) tmp
.push(ids
[i
-k
]);
2171 if (i
< ids
.length
-k
) tmp
.push(ids
[i
+k
]);
2178 exception_error("getRelativePostIds", e
);
2184 function correctHeadlinesOffset(id
) {
2188 var container
= $("headlines-frame");
2189 var row
= $("RROW-" + id
);
2191 var viewport
= container
.offsetHeight
;
2193 var rel_offset_top
= row
.offsetTop
- container
.scrollTop
;
2194 var rel_offset_bottom
= row
.offsetTop
+ row
.offsetHeight
- container
.scrollTop
;
2196 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
2197 //console.log("Vport: " + viewport);
2199 if (rel_offset_top
<= 0 || rel_offset_top
> viewport
) {
2200 container
.scrollTop
= row
.offsetTop
;
2201 } else if (rel_offset_bottom
> viewport
) {
2203 /* doesn't properly work with Opera in some cases because
2204 Opera fucks up element scrolling */
2206 container
.scrollTop
= row
.offsetTop
+ row
.offsetHeight
- viewport
;
2210 exception_error("correctHeadlinesOffset", e
);
2215 function headlineActionsChange(elem
) {
2218 elem
.attr('value', 'false');
2220 exception_error("headlineActionsChange", e
);
2224 function closeArticlePanel() {
2226 var tabs
= dijit
.byId("content-tabs");
2227 var child
= tabs
.selectedChildWidget
;
2229 if (child
&& tabs
.getIndexOfChild(child
) > 0) {
2230 tabs
.removeChild(child
);
2233 if (dijit
.byId("content-insert"))
2234 dijit
.byId("headlines-wrap-inner").removeChild(
2235 dijit
.byId("content-insert"));
2239 function initHeadlinesMenu() {
2241 if (dijit
.byId("headlinesMenu"))
2242 dijit
.byId("headlinesMenu").destroyRecursive();
2247 nodes
= $$("#headlines-frame > div[id*=RROW]");
2249 nodes
= $$("#headlines-frame span[id*=RTITLE]");
2252 nodes
.each(function(node
) {
2256 var menu
= new dijit
.Menu({
2257 id
: "headlinesMenu",
2261 var tmph
= dojo
.connect(menu
, '_openMyself', function (event
) {
2262 var callerNode
= event
.target
, match
= null, tries
= 0;
2264 while (match
== null && callerNode
&& tries
<= 3) {
2265 match
= callerNode
.id
.match("^[A-Z]+[-]([0-9]+)$");
2266 callerNode
= callerNode
.parentNode
;
2270 if (match
) this.callerRowId
= parseInt(match
[1]);
2275 menu
.addChild(new dijit
.MenuItem({
2276 label
: __("View article"),
2277 onClick: function(event
) {
2278 view(this.getParent().callerRowId
);
2281 menu
.addChild(new dijit
.MenuItem({
2282 label
: __("View in a new tab"),
2283 onClick: function(event
) {
2284 hlOpenInNewTab(event
, this.getParent().callerRowId
);
2287 menu
.addChild(new dijit
.MenuSeparator());
2289 menu
.addChild(new dijit
.MenuItem({
2290 label
: __("Open original article"),
2291 onClick: function(event
) {
2292 openArticleInNewWindow(this.getParent().callerRowId
);
2295 var labels
= dijit
.byId("feedTree").model
.getItemsInCategory(-2);
2299 menu
.addChild(new dijit
.MenuSeparator());
2301 var labelsMenu
= new dijit
.Menu({ownerMenu
: menu
});
2303 labels
.each(function(label
) {
2304 var id
= label
.id
[0];
2305 var bare_id
= id
.substr(id
.indexOf(":")+1);
2306 var name
= label
.name
[0];
2308 bare_id
= -11-bare_id
;
2310 labelsMenu
.addChild(new dijit
.MenuItem({
2313 onClick: function(event
) {
2314 //console.log(this.labelId);
2315 //console.log(this.getParent().ownerMenu.callerRowId);
2316 selectionAssignLabel(this.labelId
,
2317 [this.getParent().ownerMenu
.callerRowId
]);
2321 menu
.addChild(new dijit
.PopupMenuItem({
2322 label
: __("Labels"),
2330 exception_error("initHeadlinesMenu", e
);