]> git.wh0rd.org Git - tt-rss.git/blob - js/viewfeed.js
Merge pull request #468 from GregThib/patch-1
[tt-rss.git] / js / viewfeed.js
1 var article_cache = new Array();
2
3 var _active_article_id = 0;
4
5 var vgroup_last_feed = false;
6 var post_under_pointer = false;
7
8 var last_requested_article = false;
9
10 var catchup_id_batch = [];
11 var catchup_timeout_id = false;
12
13 var cids_requested = [];
14 var loaded_article_ids = [];
15 var _last_headlines_update = 0;
16 var current_first_id = 0;
17
18 var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null;
19
20 function headlines_callback2(transport, offset, background, infscroll_req) {
21         try {
22                 handle_rpc_json(transport);
23
24                 console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req);
25
26                 var is_cat = false;
27                 var feed_id = false;
28
29                 var reply = false;
30
31                 try {
32                         reply = JSON.parse(transport.responseText);
33                 } catch (e) {
34                         console.error(e);
35                 }
36
37                 if (reply) {
38
39                         is_cat = reply['headlines']['is_cat'];
40                         feed_id = reply['headlines']['id'];
41
42                         if (background) {
43                                 var content = reply['headlines']['content'];
44
45                                 content = content + "<div id='headlines-spacer'></div>";
46                                 return;
47                         }
48
49                         if (feed_id != -7 && (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat()))
50                                 return;
51
52                         /* dijit.getEnclosingWidget(
53                                 document.forms["main_toolbar_form"].update).attr('disabled',
54                                         is_cat || feed_id <= 0); */
55
56                         try {
57                                 if (infscroll_req == false) {
58                                         $("headlines-frame").scrollTop = 0;
59
60                                         $("floatingTitle").style.visibility = "hidden";
61                                         $("floatingTitle").setAttribute("rowid", 0);
62                                         $("floatingTitle").innerHTML = "";
63                                 }
64                         } catch (e) { };
65
66                         $("headlines-frame").removeClassName("cdm");
67                         $("headlines-frame").removeClassName("normal");
68
69                         $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal");
70
71                         var headlines_count = reply['headlines-info']['count'];
72
73                         vgroup_last_feed = reply['headlines-info']['vgroup_last_feed'];
74
75                         if (parseInt(headlines_count) < 30) {
76                                 _infscroll_disable = 1;
77                         } else {
78                                 _infscroll_disable = 0;
79                         }
80
81                         current_first_id = reply['headlines']['first_id'];
82                         var counters = reply['counters'];
83                         var articles = reply['articles'];
84                         //var runtime_info = reply['runtime-info'];
85
86                         if (infscroll_req == false) {
87                                 loaded_article_ids = [];
88
89                                 dojo.html.set($("headlines-toolbar"),
90                                                 reply['headlines']['toolbar'],
91                                                 {parseContent: true});
92
93                                 dojo.html.set($("headlines-frame"),
94                                         reply['headlines']['content'],
95                                         {parseContent: true});
96
97                                 $$("#headlines-frame div[id*='RROW']").each(function(row) {
98                                         loaded_article_ids.push(row.id);
99                                 });
100
101                                 var hsp = $("headlines-spacer");
102                                 if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
103                                 dijit.byId('headlines-frame').domNode.appendChild(hsp);
104
105                                 initHeadlinesMenu();
106
107                                 if (_infscroll_disable)
108                                         hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
109                                                 __("Click to open next unread feed.") + "</a>";
110
111                                 if (_search_query) {
112                                         $("feed_title").innerHTML += "<span id='cancel_search'>" +
113                                                 " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" +
114                                                 "</span>";
115                                 }
116
117                         } else {
118
119                                 if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) {
120                                         console.log("adding some more headlines: " + headlines_count);
121
122                                         var c = dijit.byId("headlines-frame");
123                                         var ids = getSelectedArticleIds2();
124
125                                         var hsp = $("headlines-spacer");
126
127                                         if (hsp)
128                                                 c.domNode.removeChild(hsp);
129
130                                         var tmp = new Element("div");
131                                         tmp.innerHTML = reply['headlines']['content'];
132                                         dojo.parser.parse(tmp);
133
134                                         while (tmp.hasChildNodes()) {
135                                                 var row = tmp.removeChild(tmp.firstChild);
136
137                                                 if (loaded_article_ids.indexOf(row.id) == -1 || row.hasClassName("cdmFeedTitle")) {
138                                                         dijit.byId("headlines-frame").domNode.appendChild(row);
139                                                         Element.hide(row);
140                                                         new Effect.Appear(row, {duration:0.5});
141                                                         loaded_article_ids.push(row.id);
142                                                 }
143                                         }
144
145                                         if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"});
146                                         c.domNode.appendChild(hsp);
147
148                                         if (headlines_count < 30) _infscroll_disable = true;
149
150                                         console.log("restore selected ids: " + ids);
151
152                                         for (var i = 0; i < ids.length; i++) {
153                                                 markHeadline(ids[i]);
154                                         }
155
156                                         initHeadlinesMenu();
157
158                                         if (_infscroll_disable) {
159                                                 hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
160                                                 __("Click to open next unread feed.") + "</a>";
161                                         }
162
163                                 } else {
164                                         console.log("no new headlines received");
165
166                                         var first_id_changed = reply['headlines']['first_id_changed'];
167                                         console.log("first id changed:" + first_id_changed);
168
169                                         var hsp = $("headlines-spacer");
170
171                                         if (hsp) {
172                                                 if (first_id_changed) {
173                                                         hsp.innerHTML = "<a href='#' onclick='viewCurrentFeed()'>" +
174                                                         __("New articles found, reload feed to continue.") + "</a>";
175                                                 } else {
176                                                         hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
177                                                         __("Click to open next unread feed.") + "</a>";
178                                                 }
179
180                                         }
181
182                                 }
183                         }
184
185                         if (articles) {
186                                 for (var i = 0; i < articles.length; i++) {
187                                         var a_id = articles[i]['id'];
188                                         cache_set("article:" + a_id, articles[i]['content']);
189                                 }
190                         } else {
191                                 console.log("no cached articles received");
192                         }
193
194                         if (counters)
195                                 parse_counters(counters);
196                         else
197                                 request_counters(true);
198
199                 } else {
200                         console.error("Invalid object received: " + transport.responseText);
201                         dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" +
202                                         __('Could not update headlines (invalid object received - see error console for details)') +
203                                         "</div>");
204                 }
205
206                 _infscroll_request_sent = 0;
207                 _last_headlines_update = new Date().getTime();
208
209                 unpackVisibleHeadlines();
210
211                 // if we have some more space in the buffer, why not try to fill it
212
213                 if (!_infscroll_disable && $("headlines-spacer") &&
214                                 $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) {
215
216                         window.setTimeout(function() {
217                                 loadMoreHeadlines();
218                         }, 250);
219                 }
220
221                 notify("");
222
223         } catch (e) {
224                 exception_error("headlines_callback2", e, transport);
225         }
226 }
227
228 function render_article(article) {
229         try {
230                 dijit.byId("headlines-wrap-inner").addChild(
231                                 dijit.byId("content-insert"));
232
233                 var c = dijit.byId("content-insert");
234
235                 try {
236                         c.domNode.scrollTop = 0;
237                 } catch (e) { };
238
239                 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, article);
240
241                 c.attr('content', article);
242
243                 correctHeadlinesOffset(getActiveArticleId());
244
245                 try {
246                         c.focus();
247                 } catch (e) { };
248
249         } catch (e) {
250                 exception_error("render_article", e);
251         }
252 }
253
254 function showArticleInHeadlines(id, noexpand) {
255
256         try {
257                 selectArticles("none");
258
259                 var crow = $("RROW-" + id);
260
261                 if (!crow) return;
262
263                 var article_is_unread = crow.hasClassName("Unread");
264
265                 if (!noexpand)
266                         crow.removeClassName("Unread");
267                 crow.addClassName("active");
268
269                 selectArticles('none');
270
271                 var view_mode = false;
272
273                 try {
274                         view_mode = document.forms['main_toolbar_form'].view_mode;
275                         view_mode = view_mode[view_mode.selectedIndex].value;
276                 } catch (e) {
277                         //
278                 }
279
280                 markHeadline(id);
281
282                 if (article_is_unread && !noexpand)
283                         _force_scheduled_update = true;
284
285         } catch (e) {
286                 exception_error("showArticleInHeadlines", e);
287         }
288 }
289
290 function article_callback2(transport, id) {
291         try {
292                 console.log("article_callback2 " + id);
293
294                 handle_rpc_json(transport);
295
296                 var reply = false;
297
298                 try {
299                         reply = JSON.parse(transport.responseText);
300                 } catch (e) {
301                         console.error(e);
302                 }
303
304                 if (reply) {
305
306                         reply.each(function(article) {
307                                 if (getActiveArticleId() == article['id']) {
308                                         render_article(article['content']);
309                                 }
310                                 cids_requested.remove(article['id']);
311
312                                 cache_set("article:" + article['id'], article['content']);
313                         });
314
315 //                      if (id != last_requested_article) {
316 //                              console.log("requested article id is out of sequence, aborting");
317 //                              return;
318 //                      }
319
320                 } else {
321                         console.error("Invalid object received: " + transport.responseText);
322
323                         render_article("<div class='whiteBox'>" +
324                                         __('Could not display article (invalid object received - see error console for details)') + "</div>");
325                 }
326
327                 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
328                 request_counters(unread_in_buffer == 0);
329
330                 notify("");
331         } catch (e) {
332                 exception_error("article_callback2", e, transport);
333         }
334 }
335
336 function view(id, activefeed, noexpand) {
337         try {
338                 var oldrow = $("RROW-" + getActiveArticleId());
339                 if (oldrow) oldrow.removeClassName("active");
340
341                 var crow = $("RROW-" + id);
342
343                 if (!crow) return;
344                 if (noexpand) {
345                         setActiveArticleId(id);
346                         showArticleInHeadlines(id, noexpand);
347                         return;
348                 }
349
350                 console.log("loading article: " + id);
351
352                 var cached_article = cache_get("article:" + id);
353
354                 console.log("cache check result: " + (cached_article != false));
355
356                 var query = "?op=article&method=view&id=" + param_escape(id);
357
358                 var neighbor_ids = getRelativePostIds(id);
359
360                 /* only request uncached articles */
361
362                 var cids_to_request = [];
363
364                 for (var i = 0; i < neighbor_ids.length; i++) {
365                         if (cids_requested.indexOf(neighbor_ids[i]) == -1)
366                                 if (!cache_get("article:" + neighbor_ids[i])) {
367                                         cids_to_request.push(neighbor_ids[i]);
368                                         cids_requested.push(neighbor_ids[i]);
369                                 }
370                 }
371
372                 console.log("additional ids: " + cids_to_request.toString());
373
374                 query = query + "&cids=" + cids_to_request.toString();
375
376                 var article_is_unread = crow.hasClassName("Unread");
377
378                 setActiveArticleId(id);
379                 showArticleInHeadlines(id);
380
381                 if (cached_article && article_is_unread) {
382
383                         query = query + "&mode=prefetch";
384
385                         render_article(cached_article);
386
387                 } else if (cached_article) {
388
389                         query = query + "&mode=prefetch_old";
390                         render_article(cached_article);
391
392                         // if we don't need to request any relative ids, we might as well skip
393                         // the server roundtrip altogether
394                         if (cids_to_request.length == 0) {
395                                 return;
396                         }
397                 }
398
399                 last_requested_article = id;
400
401                 console.log(query);
402
403                 if (article_is_unread) {
404                         decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
405                 }
406
407                 new Ajax.Request("backend.php", {
408                         parameters: query,
409                         onComplete: function(transport) {
410                                 article_callback2(transport, id);
411                         } });
412
413                 return false;
414
415         } catch (e) {
416                 exception_error("view", e);
417         }
418 }
419
420 function toggleMark(id, client_only) {
421         try {
422                 var query = "?op=rpc&id=" + id + "&method=mark";
423
424                 var row = $("RROW-" + id);
425                 if (!row) return;
426
427                 var imgs = [];
428
429                 var row_imgs = row.getElementsByClassName("markedPic");
430
431                 for (var i = 0; i < row_imgs.length; i++)
432                         imgs.push(row_imgs[i]);
433
434                 var ft = $("floatingTitle");
435
436                 if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
437                         var fte = ft.getElementsByClassName("markedPic");
438
439                         for (var i = 0; i < fte.length; i++)
440                                 imgs.push(fte[i]);
441                 }
442
443                 for (i = 0; i < imgs.length; i++) {
444                         var img = imgs[i];
445
446                         if (!row.hasClassName("marked")) {
447                                 img.src = img.src.replace("mark_unset", "mark_set");
448                                 img.alt = __("Unstar article");
449                                 query = query + "&mark=1";
450                         } else {
451                                 img.src = img.src.replace("mark_set", "mark_unset");
452                                 img.alt = __("Star article");
453                                 query = query + "&mark=0";
454                         }
455                 }
456
457                 row.toggleClassName("marked");
458
459                 if (!client_only) {
460                         new Ajax.Request("backend.php", {
461                                 parameters: query,
462                                 onComplete: function(transport) {
463                                         handle_rpc_json(transport);
464                                 } });
465                 }
466
467         } catch (e) {
468                 exception_error("toggleMark", e);
469         }
470 }
471
472 function togglePub(id, client_only, no_effects, note) {
473         try {
474                 var query = "?op=rpc&id=" + id + "&method=publ";
475
476                 if (note != undefined) {
477                         query = query + "&note=" + param_escape(note);
478                 } else {
479                         query = query + "&note=undefined";
480                 }
481
482                 var row = $("RROW-" + id);
483                 if (!row) return;
484
485                 var imgs = [];
486
487                 var row_imgs = row.getElementsByClassName("pubPic");
488
489                 for (var i = 0; i < row_imgs.length; i++)
490                         imgs.push(row_imgs[i]);
491
492                 var ft = $("floatingTitle");
493
494                 if (ft && ft.getAttribute("rowid") == "RROW-" + id) {
495                         var fte = ft.getElementsByClassName("pubPic");
496
497                         for (var i = 0; i < fte.length; i++)
498                                 imgs.push(fte[i]);
499                 }
500
501                 for (i = 0; i < imgs.length; i++) {
502                         var img = imgs[i];
503
504                         if (!row.hasClassName("published") || note != undefined) {
505                                 img.src = img.src.replace("pub_unset", "pub_set");
506                                 img.alt = __("Unpublish article");
507                                 query = query + "&pub=1";
508                         } else {
509                                 img.src = img.src.replace("pub_set", "pub_unset");
510                                 img.alt = __("Publish article");
511                                 query = query + "&pub=0";
512                         }
513                 }
514
515                 if (note != undefined)
516                         row.addClassName("published");
517                 else
518                         row.toggleClassName("published");
519
520                 if (!client_only) {
521                         new Ajax.Request("backend.php", {
522                                 parameters: query,
523                                 onComplete: function(transport) {
524                                         handle_rpc_json(transport);
525                                 } });
526                 }
527
528         } catch (e) {
529                 exception_error("togglePub", e);
530         }
531 }
532
533 function moveToPost(mode, noscroll, noexpand) {
534
535         try {
536
537                 var rows = getVisibleArticleIds();
538
539                 var prev_id = false;
540                 var next_id = false;
541
542                 if (!$('RROW-' + getActiveArticleId())) {
543                         setActiveArticleId(0);
544                 }
545
546                 if (!getActiveArticleId()) {
547                         next_id = rows[0];
548                         prev_id = rows[rows.length-1]
549                 } else {
550                         for (var i = 0; i < rows.length; i++) {
551                                 if (rows[i] == getActiveArticleId()) {
552
553                                         // Account for adjacent identical article ids.
554                                         if (i > 0) prev_id = rows[i-1];
555
556                                         for (var j = i+1; j < rows.length; j++) {
557                                                 if (rows[j] != getActiveArticleId()) {
558                                                         next_id = rows[j];
559                                                         break;
560                                                 }
561                                         }
562                                         break;
563                                 }
564                         }
565                 }
566
567                 if (mode == "next") {
568                         if (next_id || getActiveArticleId()) {
569                                 if (isCdmMode()) {
570
571                                         var article = $("RROW-" + getActiveArticleId());
572                                         var ctr = $("headlines-frame");
573
574                                         if (!noscroll && article && article.offsetTop + article.offsetHeight >
575                                                         ctr.scrollTop + ctr.offsetHeight) {
576
577                                                 scrollArticle(ctr.offsetHeight/4);
578
579                                         } else if (next_id) {
580                                                 cdmExpandArticle(next_id, noexpand);
581                                                 cdmScrollToArticleId(next_id, true);
582                                         }
583
584                                 } else if (next_id) {
585                                         correctHeadlinesOffset(next_id);
586                                         view(next_id, getActiveFeedId(), noexpand);
587                                 }
588                         }
589                 }
590
591                 if (mode == "prev") {
592                         if (prev_id || getActiveArticleId()) {
593                                 if (isCdmMode()) {
594
595                                         var article = $("RROW-" + getActiveArticleId());
596                                         var prev_article = $("RROW-" + prev_id);
597                                         var ctr = $("headlines-frame");
598
599                                         if (!getInitParam("cdm_expanded")) {
600
601                                                 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
602                                                         scrollArticle(-ctr.offsetHeight/4);
603                                                 } else {
604                                                         cdmExpandArticle(prev_id, noexpand);
605                                                         cdmScrollToArticleId(prev_id, true);
606                                                 }
607                                         } else {
608
609                                                 if (!noscroll && article && article.offsetTop < ctr.scrollTop) {
610                                                         scrollArticle(-ctr.offsetHeight/3);
611                                                 } else if (!noscroll && prev_article &&
612                                                                 prev_article.offsetTop < ctr.scrollTop) {
613                                                         cdmExpandArticle(prev_id, noexpand);
614                                                         scrollArticle(-ctr.offsetHeight/4);
615                                                 } else if (prev_id) {
616                                                         cdmExpandArticle(prev_id, noexpand);
617                                                         cdmScrollToArticleId(prev_id, noscroll);
618                                                 }
619                                         }
620
621                                 } else if (prev_id) {
622                                         correctHeadlinesOffset(prev_id);
623                                         view(prev_id, getActiveFeedId(), noexpand);
624                                 }
625                         }
626                 }
627
628         } catch (e) {
629                 exception_error("moveToPost", e);
630         }
631 }
632
633 function toggleSelected(id, force_on) {
634         try {
635                 var row = $("RROW-" + id);
636
637                 if (row) {
638                         var cb = dijit.getEnclosingWidget(
639                                         row.getElementsByClassName("rchk")[0]);
640
641                         if (row.hasClassName('Selected') && !force_on) {
642                                 row.removeClassName('Selected');
643                                 if (cb) cb.attr("checked", false);
644                         } else {
645                                 row.addClassName('Selected');
646                                 if (cb) cb.attr("checked", true);
647                         }
648                 }
649
650                 updateSelectedPrompt();
651         } catch (e) {
652                 exception_error("toggleSelected", e);
653         }
654 }
655
656 function updateSelectedPrompt() {
657         try {
658                 var count = getSelectedArticleIds2().size();
659                 var elem = $("selected_prompt");
660
661                 if (elem) {
662                         elem.innerHTML = ngettext("%d article selected",
663                                         "%d articles selected", count).replace("%d", count);
664
665                         if (count > 0)
666                                 Element.show(elem);
667                         else
668                                 Element.hide(elem);
669                 }
670
671         } catch (e) {
672                 exception_error("updateSelectedPrompt", e);
673         }
674 }
675
676 function toggleUnread_afh(effect) {
677         try {
678
679                 var elem = effect.element;
680                 elem.style.backgroundColor = "";
681
682         } catch (e) {
683                 exception_error("toggleUnread_afh", e);
684         }
685 }
686
687 function toggleUnread(id, cmode, effect) {
688         try {
689
690                 var row = $("RROW-" + id);
691                 if (row) {
692                         if (cmode == undefined || cmode == 2) {
693                                 if (row.hasClassName("Unread")) {
694                                         row.removeClassName("Unread");
695
696                                 } else {
697                                         row.addClassName("Unread");
698                                 }
699
700                         } else if (cmode == 0) {
701
702                                 row.removeClassName("Unread");
703
704                         } else if (cmode == 1) {
705                                 row.addClassName("Unread");
706                         }
707
708                         if (cmode == undefined) cmode = 2;
709
710                         var query = "?op=rpc&method=catchupSelected" +
711                                 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
712
713 //                      notify_progress("Loading, please wait...");
714
715                         new Ajax.Request("backend.php", {
716                                 parameters: query,
717                                 onComplete: function(transport) {
718                                         handle_rpc_json(transport);
719                                 } });
720
721                 }
722
723         } catch (e) {
724                 exception_error("toggleUnread", e);
725         }
726 }
727
728 function selectionRemoveLabel(id, ids) {
729         try {
730
731                 if (!ids) ids = getSelectedArticleIds2();
732
733                 if (ids.length == 0) {
734                         alert(__("No articles are selected."));
735                         return;
736                 }
737
738                 var query = "?op=article&method=removeFromLabel&ids=" +
739                         param_escape(ids.toString()) + "&lid=" + param_escape(id);
740
741                 console.log(query);
742
743                 new Ajax.Request("backend.php", {
744                         parameters: query,
745                         onComplete: function(transport) {
746                                 handle_rpc_json(transport);
747                                 show_labels_in_headlines(transport);
748                         } });
749
750         } catch (e) {
751                 exception_error("selectionAssignLabel", e);
752
753         }
754 }
755
756 function selectionAssignLabel(id, ids) {
757         try {
758
759                 if (!ids) ids = getSelectedArticleIds2();
760
761                 if (ids.length == 0) {
762                         alert(__("No articles are selected."));
763                         return;
764                 }
765
766                 var query = "?op=article&method=assignToLabel&ids=" +
767                         param_escape(ids.toString()) + "&lid=" + param_escape(id);
768
769                 console.log(query);
770
771                 new Ajax.Request("backend.php", {
772                         parameters: query,
773                         onComplete: function(transport) {
774                                 handle_rpc_json(transport);
775                                 show_labels_in_headlines(transport);
776                         } });
777
778         } catch (e) {
779                 exception_error("selectionAssignLabel", e);
780
781         }
782 }
783
784 function selectionToggleUnread(set_state, callback, no_error, ids) {
785         try {
786                 var rows = ids ? ids : getSelectedArticleIds2();
787
788                 if (rows.length == 0 && !no_error) {
789                         alert(__("No articles are selected."));
790                         return;
791                 }
792
793                 for (var i = 0; i < rows.length; i++) {
794                         var row = $("RROW-" + rows[i]);
795                         if (row) {
796                                 if (set_state == undefined) {
797                                         if (row.hasClassName("Unread")) {
798                                                 row.removeClassName("Unread");
799                                         } else {
800                                                 row.addClassName("Unread");
801                                         }
802                                 }
803
804                                 if (set_state == false) {
805                                         row.removeClassName("Unread");
806                                 }
807
808                                 if (set_state == true) {
809                                         row.addClassName("Unread");
810                                 }
811                         }
812                 }
813
814                 updateFloatingTitle(true);
815
816                 if (rows.length > 0) {
817
818                         var cmode = "";
819
820                         if (set_state == undefined) {
821                                 cmode = "2";
822                         } else if (set_state == true) {
823                                 cmode = "1";
824                         } else if (set_state == false) {
825                                 cmode = "0";
826                         }
827
828                         var query = "?op=rpc&method=catchupSelected" +
829                                 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
830
831                         notify_progress("Loading, please wait...");
832
833                         new Ajax.Request("backend.php", {
834                                 parameters: query,
835                                 onComplete: function(transport) {
836                                         handle_rpc_json(transport);
837                                         if (callback) callback(transport);
838                                 } });
839
840                 }
841
842         } catch (e) {
843                 exception_error("selectionToggleUnread", e);
844         }
845 }
846
847 // sel_state ignored
848 function selectionToggleMarked(sel_state, callback, no_error, ids) {
849         try {
850
851                 var rows = ids ? ids : getSelectedArticleIds2();
852
853                 if (rows.length == 0 && !no_error) {
854                         alert(__("No articles are selected."));
855                         return;
856                 }
857
858                 for (var i = 0; i < rows.length; i++) {
859                         toggleMark(rows[i], true, true);
860                 }
861
862                 if (rows.length > 0) {
863
864                         var query = "?op=rpc&method=markSelected&ids=" +
865                                 param_escape(rows.toString()) + "&cmode=2";
866
867                         new Ajax.Request("backend.php", {
868                                 parameters: query,
869                                 onComplete: function(transport) {
870                                         handle_rpc_json(transport);
871                                         if (callback) callback(transport);
872                                 } });
873
874                 }
875
876         } catch (e) {
877                 exception_error("selectionToggleMarked", e);
878         }
879 }
880
881 // sel_state ignored
882 function selectionTogglePublished(sel_state, callback, no_error, ids) {
883         try {
884
885                 var rows = ids ? ids : getSelectedArticleIds2();
886
887                 if (rows.length == 0 && !no_error) {
888                         alert(__("No articles are selected."));
889                         return;
890                 }
891
892                 for (var i = 0; i < rows.length; i++) {
893                         togglePub(rows[i], true, true);
894                 }
895
896                 if (rows.length > 0) {
897
898                         var query = "?op=rpc&method=publishSelected&ids=" +
899                                 param_escape(rows.toString()) + "&cmode=2";
900
901                         new Ajax.Request("backend.php", {
902                                 parameters: query,
903                                 onComplete: function(transport) {
904                                         handle_rpc_json(transport);
905                                 } });
906
907                 }
908
909         } catch (e) {
910                 exception_error("selectionToggleMarked", e);
911         }
912 }
913
914 function getSelectedArticleIds2() {
915
916         var rv = [];
917
918         $$("#headlines-frame > div[id*=RROW][class*=Selected]").each(
919                 function(child) {
920                         rv.push(child.id.replace("RROW-", ""));
921                 });
922
923         return rv;
924 }
925
926 function getLoadedArticleIds() {
927         var rv = [];
928
929         var children = $$("#headlines-frame > div[id*=RROW-]");
930
931         children.each(function(child) {
932                         rv.push(child.id.replace("RROW-", ""));
933                 });
934
935         return rv;
936
937 }
938
939 // mode = all,none,unread,invert,marked,published
940 function selectArticles(mode, query) {
941         try {
942
943                 if (!query) query = "#headlines-frame > div[id*=RROW]";
944
945                 var children = $$(query);
946
947                 children.each(function(child) {
948                         var id = child.id.replace("RROW-", "");
949
950                         var cb = dijit.getEnclosingWidget(
951                                         child.getElementsByClassName("rchk")[0]);
952
953                         if (mode == "all") {
954                                 child.addClassName("Selected");
955                                 if (cb) cb.attr("checked", true);
956                         } else if (mode == "unread") {
957                                 if (child.hasClassName("Unread")) {
958                                         child.addClassName("Selected");
959                                         if (cb) cb.attr("checked", true);
960                                 } else {
961                                         child.removeClassName("Selected");
962                                         if (cb) cb.attr("checked", false);
963                                 }
964                         } else if (mode == "marked") {
965                                 if (child.hasClassName("marked")) {
966                                         child.addClassName("Selected");
967                                         if (cb) cb.attr("checked", true);
968                                 } else {
969                                         child.removeClassName("Selected");
970                                         if (cb) cb.attr("checked", false);
971                                 }
972                         } else if (mode == "published") {
973                                 if (child.hasClassName("published")) {
974                                         child.addClassName("Selected");
975                                         if (cb) cb.attr("checked", true);
976                                 } else {
977                                         child.removeClassName("Selected");
978                                         if (cb) cb.attr("checked", false);
979                                 }
980
981                         } else if (mode == "invert") {
982                                 if (child.hasClassName("Selected")) {
983                                         child.removeClassName("Selected");
984                                         if (cb) cb.attr("checked", false);
985                                 } else {
986                                         child.addClassName("Selected");
987                                         if (cb) cb.attr("checked", true);
988                                 }
989
990                         } else {
991                                 child.removeClassName("Selected");
992                                 if (cb) cb.attr("checked", false);
993                         }
994                 });
995
996                 updateSelectedPrompt();
997
998         } catch (e) {
999                 exception_error("selectArticles", e);
1000         }
1001 }
1002
1003 function deleteSelection() {
1004
1005         try {
1006
1007                 var rows = getSelectedArticleIds2();
1008
1009                 if (rows.length == 0) {
1010                         alert(__("No articles are selected."));
1011                         return;
1012                 }
1013
1014                 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1015                 var str;
1016
1017                 if (getActiveFeedId() != 0) {
1018                         str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows.length);
1019                 } else {
1020                         str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length);
1021                 }
1022
1023                 str = str.replace("%d", rows.length);
1024                 str = str.replace("%s", fn);
1025
1026                 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1027                         return;
1028                 }
1029
1030                 query = "?op=rpc&method=delete&ids=" + param_escape(rows);
1031
1032                 console.log(query);
1033
1034                 new Ajax.Request("backend.php", {
1035                         parameters: query,
1036                         onComplete: function(transport) {
1037                                         handle_rpc_json(transport);
1038                                         viewCurrentFeed();
1039                                 } });
1040
1041         } catch (e) {
1042                 exception_error("deleteSelection", e);
1043         }
1044 }
1045
1046 function archiveSelection() {
1047
1048         try {
1049
1050                 var rows = getSelectedArticleIds2();
1051
1052                 if (rows.length == 0) {
1053                         alert(__("No articles are selected."));
1054                         return;
1055                 }
1056
1057                 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1058                 var str;
1059                 var op;
1060
1061                 if (getActiveFeedId() != 0) {
1062                         str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length);
1063                         op = "archive";
1064                 } else {
1065                         str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length);
1066
1067                         str += " " + __("Please note that unstarred articles might get purged on next feed update.");
1068
1069                         op = "unarchive";
1070                 }
1071
1072                 str = str.replace("%d", rows.length);
1073                 str = str.replace("%s", fn);
1074
1075                 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1076                         return;
1077                 }
1078
1079                 query = "?op=rpc&method="+op+"&ids=" + param_escape(rows);
1080
1081                 console.log(query);
1082
1083                 for (var i = 0; i < rows.length; i++) {
1084                         cache_delete("article:" + rows[i]);
1085                 }
1086
1087                 new Ajax.Request("backend.php", {
1088                         parameters: query,
1089                         onComplete: function(transport) {
1090                                         handle_rpc_json(transport);
1091                                         viewCurrentFeed();
1092                                 } });
1093
1094         } catch (e) {
1095                 exception_error("archiveSelection", e);
1096         }
1097 }
1098
1099 function catchupSelection() {
1100
1101         try {
1102
1103                 var rows = getSelectedArticleIds2();
1104
1105                 if (rows.length == 0) {
1106                         alert(__("No articles are selected."));
1107                         return;
1108                 }
1109
1110                 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1111
1112                 var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length);
1113
1114                 str = str.replace("%d", rows.length);
1115                 str = str.replace("%s", fn);
1116
1117                 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1118                         return;
1119                 }
1120
1121                 selectionToggleUnread(false, 'viewCurrentFeed()', true);
1122
1123         } catch (e) {
1124                 exception_error("catchupSelection", e);
1125         }
1126 }
1127
1128 function editArticleTags(id) {
1129                 var query = "backend.php?op=article&method=editArticleTags&param=" + param_escape(id);
1130
1131                 if (dijit.byId("editTagsDlg"))
1132                         dijit.byId("editTagsDlg").destroyRecursive();
1133
1134                 dialog = new dijit.Dialog({
1135                         id: "editTagsDlg",
1136                         title: __("Edit article Tags"),
1137                         style: "width: 600px",
1138                         execute: function() {
1139                                 if (this.validate()) {
1140                                         var query = dojo.objectToQuery(this.attr('value'));
1141
1142                                         notify_progress("Saving article tags...", true);
1143
1144                                         new Ajax.Request("backend.php", {
1145                                         parameters: query,
1146                                         onComplete: function(transport) {
1147                                                 try {
1148                                                         notify('');
1149                                                         dialog.hide();
1150
1151                                                         var data = JSON.parse(transport.responseText);
1152
1153                                                         if (data) {
1154                                                                 var id = data.id;
1155
1156                                                                 console.log(id);
1157
1158                                                                 var tags = $("ATSTR-" + id);
1159                                                                 var tooltip = dijit.byId("ATSTRTIP-" + id);
1160
1161                                                                 if (tags) tags.innerHTML = data.content;
1162                                                                 if (tooltip) tooltip.attr('label', data.content_full);
1163                                                         }
1164                                                 } catch (e) {
1165                                                         exception_error("editArticleTags/inner", e);
1166                                                 }
1167
1168                                         }});
1169                                 }
1170                         },
1171                         href: query
1172                 });
1173
1174                 var tmph = dojo.connect(dialog, 'onLoad', function() {
1175                 dojo.disconnect(tmph);
1176
1177                         new Ajax.Autocompleter('tags_str', 'tags_choices',
1178                            "backend.php?op=article&method=completeTags",
1179                            { tokens: ',', paramName: "search" });
1180                 });
1181
1182                 dialog.show();
1183
1184 }
1185
1186 function cdmScrollToArticleId(id, force) {
1187         try {
1188                 var ctr = $("headlines-frame");
1189                 var e = $("RROW-" + id);
1190
1191                 if (!e || !ctr) return;
1192
1193                 if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) ||
1194                                 e.offsetTop < ctr.scrollTop) {
1195
1196                         // expanded cdm has a 4px margin now
1197                         ctr.scrollTop = parseInt(e.offsetTop) - 4;
1198                 }
1199
1200         } catch (e) {
1201                 exception_error("cdmScrollToArticleId", e);
1202         }
1203 }
1204
1205 function setActiveArticleId(id) {
1206         _active_article_id = id;
1207         PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id);
1208 }
1209
1210 function getActiveArticleId() {
1211         return _active_article_id;
1212 }
1213
1214 function postMouseIn(e, id) {
1215         post_under_pointer = id;
1216 }
1217
1218 function postMouseOut(id) {
1219         post_under_pointer = false;
1220 }
1221
1222 function unpackVisibleHeadlines() {
1223         try {
1224                 if (!isCdmMode() || !getInitParam("cdm_expanded")) return;
1225
1226                 $$("#headlines-frame > div[id*=RROW]").each(
1227                         function(child) {
1228                                 if (child.offsetTop <= $("headlines-frame").scrollTop +
1229                                         $("headlines-frame").offsetHeight) {
1230
1231                                         var cencw = $("CENCW-" + child.id.replace("RROW-", ""));
1232
1233                                         if (cencw) {
1234                                                 PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, child);
1235
1236                                                 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1237                                                 cencw.setAttribute('id', '');
1238                                                 Element.show(cencw);
1239                                         }
1240                                 }
1241                         }
1242                 );
1243
1244         } catch (e) {
1245                 exception_error("unpackVisibleHeadlines", e);
1246         }
1247 }
1248
1249 function headlines_scroll_handler(e) {
1250         try {
1251                 var hsp = $("headlines-spacer");
1252
1253                 unpackVisibleHeadlines();
1254
1255                 // set topmost child in the buffer as active
1256                 if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 &&
1257                                 getSelectedArticleIds2().length <= 1 &&
1258                                 getInitParam("cdm_expanded")) {
1259                         var rows = $$("#headlines-frame > div[id*=RROW]");
1260
1261                         for (var i = 0; i < rows.length; i++) {
1262                                 var child = rows[i];
1263
1264                                 if ($("headlines-frame").scrollTop <= child.offsetTop &&
1265                                         child.offsetTop - $("headlines-frame").scrollTop < 100 &&
1266                                         child.id.replace("RROW-", "") != _active_article_id) {
1267
1268                                         if (_active_article_id) {
1269                                                 var row = $("RROW-" + _active_article_id);
1270                                                 if (row) row.removeClassName("active");
1271                                         }
1272
1273                                         _active_article_id = child.id.replace("RROW-", "");
1274                                         showArticleInHeadlines(_active_article_id, true);
1275                                         updateSelectedPrompt();
1276                                         break;
1277                                 }
1278                         }
1279                 }
1280
1281                 if (!_infscroll_disable) {
1282                         if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) ||
1283                                         (e.scrollHeight != 0 &&
1284                                                 ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) {
1285
1286                                 if (hsp)
1287                                         hsp.innerHTML = "<span class='loading'><img src='images/indicator_tiny.gif'> " +
1288                                                 __("Loading, please wait...") + "</span>";
1289
1290                                 loadMoreHeadlines();
1291                                 return;
1292
1293                         }
1294                 /*} else {
1295                         if (hsp) {
1296                                 if (_infscroll_disable)
1297                                         hsp.innerHTML = "<a href='#' onclick='openNextUnreadFeed()'>" +
1298                                                 __("Click to open next unread feed.") + "</a>";
1299                                 else
1300                                         hsp.innerHTML = "";
1301                         }*/
1302                 }
1303
1304                 if (isCdmMode()) {
1305                         updateFloatingTitle();
1306                 }
1307
1308                 if (getInitParam("cdm_auto_catchup") == 1) {
1309
1310                         // let's get DOM some time to settle down
1311                         var ts = new Date().getTime();
1312                         if (ts - _last_headlines_update < 100) return;
1313
1314                         $$("#headlines-frame > div[id*=RROW][class*=Unread]").each(
1315                                 function(child) {
1316                                         if (child.hasClassName("Unread") && $("headlines-frame").scrollTop >
1317                                                         (child.offsetTop + child.offsetHeight/2)) {
1318
1319                                                 var id = child.id.replace("RROW-", "");
1320
1321                                                 if (catchup_id_batch.indexOf(id) == -1)
1322                                                         catchup_id_batch.push(id);
1323
1324                                                 //console.log("auto_catchup_batch: " + catchup_id_batch.toString());
1325                                         }
1326
1327                                 });
1328
1329                         if (catchup_id_batch.length > 0) {
1330                                 window.clearTimeout(catchup_timeout_id);
1331
1332                                 if (!_infscroll_request_sent) {
1333                                         catchup_timeout_id = window.setTimeout('catchupBatchedArticles()',
1334                                                 500);
1335                                 }
1336                         }
1337
1338                         if (_infscroll_disable) {
1339                                 var child = $$("#headlines-frame div[id*=RROW]").last();
1340
1341                                 if (child && $("headlines-frame").scrollTop >
1342                                                 (child.offsetTop + child.offsetHeight - 50)) {
1343
1344                                         console.log("we seem to be at an end");
1345
1346                                         if (getInitParam("on_catchup_show_next_feed") == "1") {
1347                                                 openNextUnreadFeed();
1348                                         }
1349                                 }
1350                         }
1351                 }
1352
1353         } catch (e) {
1354                 console.warn("headlines_scroll_handler: " + e);
1355         }
1356 }
1357
1358 function openNextUnreadFeed() {
1359         try {
1360                 var is_cat = activeFeedIsCat();
1361                 var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat);
1362                 if (nuf) viewfeed(nuf, '', is_cat);
1363         } catch (e) {
1364                 exception_error("openNextUnreadFeed", e);
1365         }
1366 }
1367
1368 function catchupBatchedArticles() {
1369         try {
1370                 if (catchup_id_batch.length > 0 && !_infscroll_request_sent) {
1371
1372                         // make a copy of the array
1373                         var batch = catchup_id_batch.slice();
1374                         var query = "?op=rpc&method=catchupSelected" +
1375                                 "&cmode=0&ids=" + param_escape(batch.toString());
1376
1377                         console.log(query);
1378
1379                         new Ajax.Request("backend.php", {
1380                                 parameters: query,
1381                                 onComplete: function(transport) {
1382                                         handle_rpc_json(transport);
1383
1384                                         reply = JSON.parse(transport.responseText);
1385                                         var batch = reply.ids;
1386
1387                                         _infscroll_tmp_disable = 1;
1388
1389                                         batch.each(function(id) {
1390                                                 console.log(id);
1391                                                 var elem = $("RROW-" + id);
1392                                                 if (elem) elem.removeClassName("Unread");
1393                                                 catchup_id_batch.remove(id);
1394                                         });
1395
1396                                         _infscroll_tmp_disable = 0;
1397
1398                                         updateFloatingTitle(true);
1399
1400                                 } });
1401                 }
1402
1403         } catch (e) {
1404                 exception_error("catchupBatchedArticles", e);
1405         }
1406 }
1407
1408 function catchupRelativeToArticle(below, id) {
1409
1410         try {
1411
1412                 if (!id) id = getActiveArticleId();
1413
1414                 if (!id) {
1415                         alert(__("No article is selected."));
1416                         return;
1417                 }
1418
1419                 var visible_ids = getVisibleArticleIds();
1420
1421                 var ids_to_mark = new Array();
1422
1423                 if (!below) {
1424                         for (var i = 0; i < visible_ids.length; i++) {
1425                                 if (visible_ids[i] != id) {
1426                                         var e = $("RROW-" + visible_ids[i]);
1427
1428                                         if (e && e.hasClassName("Unread")) {
1429                                                 ids_to_mark.push(visible_ids[i]);
1430                                         }
1431                                 } else {
1432                                         break;
1433                                 }
1434                         }
1435                 } else {
1436                         for (var i = visible_ids.length-1; i >= 0; i--) {
1437                                 if (visible_ids[i] != id) {
1438                                         var e = $("RROW-" + visible_ids[i]);
1439
1440                                         if (e && e.hasClassName("Unread")) {
1441                                                 ids_to_mark.push(visible_ids[i]);
1442                                         }
1443                                 } else {
1444                                         break;
1445                                 }
1446                         }
1447                 }
1448
1449                 if (ids_to_mark.length == 0) {
1450                         alert(__("No articles found to mark"));
1451                 } else {
1452                         var msg = ngettext("Mark %d article as read?", "Mark %d articles as read?", ids_to_mark.length).replace("%d", ids_to_mark.length);
1453
1454                         if (getInitParam("confirm_feed_catchup") != 1 || confirm(msg)) {
1455
1456                                 for (var i = 0; i < ids_to_mark.length; i++) {
1457                                         var e = $("RROW-" + ids_to_mark[i]);
1458                                         e.removeClassName("Unread");
1459                                 }
1460
1461                                 var query = "?op=rpc&method=catchupSelected" +
1462                                         "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
1463
1464                                 new Ajax.Request("backend.php", {
1465                                         parameters: query,
1466                                         onComplete: function(transport) {
1467                                                 handle_rpc_json(transport);
1468                                         } });
1469
1470                         }
1471                 }
1472
1473         } catch (e) {
1474                 exception_error("catchupRelativeToArticle", e);
1475         }
1476 }
1477
1478 function cdmCollapseArticle(event, id, unmark) {
1479         try {
1480                 if (unmark == undefined) unmark = true;
1481
1482                 var row = $("RROW-" + id);
1483                 var elem = $("CICD-" + id);
1484
1485                 if (elem && row) {
1486                         var collapse = $$("div#RROW-" + id +
1487                                 " span[class='collapseBtn']")[0];
1488
1489                         Element.hide(elem);
1490                         Element.show("CEXC-" + id);
1491                         Element.hide(collapse);
1492
1493                         if (unmark) {
1494                                 row.removeClassName("active");
1495
1496                                 markHeadline(id, false);
1497
1498                                 if (id == getActiveArticleId()) {
1499                                         setActiveArticleId(0);
1500                                 }
1501
1502                                 updateSelectedPrompt();
1503                         }
1504
1505                         if (event) Event.stop(event);
1506
1507                         PluginHost.run(PluginHost.HOOK_ARTICLE_COLLAPSED, id);
1508
1509                         if (row.offsetTop < $("headlines-frame").scrollTop)
1510                                 scrollToRowId(row.id);
1511
1512                         $("floatingTitle").style.visibility = "hidden";
1513                         $("floatingTitle").setAttribute("rowid", false);
1514                 }
1515
1516         } catch (e) {
1517                 exception_error("cdmCollapseArticle", e);
1518         }
1519 }
1520
1521 function cdmExpandArticle(id, noexpand) {
1522         try {
1523                 console.log("cdmExpandArticle " + id);
1524
1525                 if (!$("RROW-" + id)) return false;
1526
1527                 var oldrow = $("RROW-" + getActiveArticleId());
1528
1529                 var elem = $("CICD-" + getActiveArticleId());
1530
1531                 if (id == getActiveArticleId() && Element.visible(elem))
1532                         return true;
1533
1534                 selectArticles("none");
1535
1536                 var old_offset = $("RROW-" + id).offsetTop;
1537
1538                 if (getActiveArticleId() && elem && !getInitParam("cdm_expanded")) {
1539                         var collapse = $$("div#RROW-" + getActiveArticleId() +
1540                                 " span[class='collapseBtn']")[0];
1541
1542                         Element.hide(elem);
1543                         Element.show("CEXC-" + getActiveArticleId());
1544                         Element.hide(collapse);
1545                 }
1546
1547                 if (oldrow) oldrow.removeClassName("active");
1548
1549                 setActiveArticleId(id);
1550
1551                 elem = $("CICD-" + id);
1552
1553                 var collapse = $$("div#RROW-" + id +
1554                                 " span[class='collapseBtn']")[0];
1555
1556                 var cencw = $("CENCW-" + id);
1557
1558                 if (!Element.visible(elem) && !noexpand) {
1559                         if (cencw) {
1560                                 cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML);
1561                                 cencw.setAttribute('id', '');
1562                                 Element.show(cencw);
1563                         }
1564
1565                         Element.show(elem);
1566                         Element.hide("CEXC-" + id);
1567                         Element.show(collapse);
1568                 }
1569
1570                 var new_offset = $("RROW-" + id).offsetTop;
1571
1572                 if (old_offset > new_offset)
1573                         $("headlines-frame").scrollTop -= (old_offset-new_offset);
1574
1575                 if (!noexpand)
1576                         toggleUnread(id, 0, true);
1577                 toggleSelected(id);
1578                 $("RROW-" + id).addClassName("active");
1579
1580                 PluginHost.run(PluginHost.HOOK_ARTICLE_EXPANDED, id);
1581
1582         } catch (e) {
1583                 exception_error("cdmExpandArticle", e);
1584         }
1585
1586         return false;
1587 }
1588
1589 function getArticleUnderPointer() {
1590         return post_under_pointer;
1591 }
1592
1593 function scrollArticle(offset) {
1594         try {
1595                 if (!isCdmMode()) {
1596                         var ci = $("content-insert");
1597                         if (ci) {
1598                                 ci.scrollTop += offset;
1599                         }
1600                 } else {
1601                         var hi = $("headlines-frame");
1602                         if (hi) {
1603                                 hi.scrollTop += offset;
1604                         }
1605
1606                 }
1607         } catch (e) {
1608                 exception_error("scrollArticle", e);
1609         }
1610 }
1611
1612 function show_labels_in_headlines(transport) {
1613         try {
1614                 var data = JSON.parse(transport.responseText);
1615
1616                 if (data) {
1617                         data['info-for-headlines'].each(function(elem) {
1618                                 $$(".HLLCTR-" + elem.id).each(function(ctr) {
1619                                         ctr.innerHTML = elem.labels;
1620                                 });
1621                         });
1622                 }
1623         } catch (e) {
1624                 exception_error("show_labels_in_headlines", e);
1625         }
1626 }
1627
1628 function dismissArticle(id) {
1629         try {
1630                 var elem = $("RROW-" + id);
1631
1632                 if (!elem) return;
1633
1634                 toggleUnread(id, 0, true);
1635
1636                 new Effect.Fade(elem, {duration : 0.5});
1637
1638                 // Remove the content, too
1639                 var elem_content = $("CICD-" + id);
1640                 if (elem_content) {
1641                         Element.remove(elem_content);
1642                 }
1643
1644                 if (id == getActiveArticleId()) {
1645                         setActiveArticleId(0);
1646                 }
1647
1648         } catch (e) {
1649                 exception_error("dismissArticle", e);
1650         }
1651 }
1652
1653 function dismissSelectedArticles() {
1654         try {
1655
1656                 var ids = getVisibleArticleIds();
1657                 var tmp = [];
1658                 var sel = [];
1659
1660                 for (var i = 0; i < ids.length; i++) {
1661                         var elem = $("RROW-" + ids[i]);
1662
1663                         if (elem.className && elem.hasClassName("Selected") &&
1664                                         ids[i] != getActiveArticleId()) {
1665                                 new Effect.Fade(elem, {duration : 0.5});
1666                                 sel.push(ids[i]);
1667
1668                                 // Remove the content, too
1669                                 var elem_content = $("CICD-" + ids[i]);
1670                                 if (elem_content) {
1671                                         Element.remove(elem_content);
1672                                 }
1673                         } else {
1674                                 tmp.push(ids[i]);
1675                         }
1676                 }
1677
1678                 if (sel.length > 0)
1679                         selectionToggleUnread(false);
1680
1681
1682         } catch (e) {
1683                 exception_error("dismissSelectedArticles", e);
1684         }
1685 }
1686
1687 function dismissReadArticles() {
1688         try {
1689
1690                 var ids = getVisibleArticleIds();
1691                 var tmp = [];
1692
1693                 for (var i = 0; i < ids.length; i++) {
1694                         var elem = $("RROW-" + ids[i]);
1695
1696                         if (elem.className && !elem.hasClassName("Unread") &&
1697                                         !elem.hasClassName("Selected")) {
1698
1699                                 new Effect.Fade(elem, {duration : 0.5});
1700
1701                                 // Remove the content, too
1702                                 var elem_content = $("CICD-" + ids[i]);
1703                                 if (elem_content) {
1704                                         Element.remove(elem_content);
1705                                 }
1706                         } else {
1707                                 tmp.push(ids[i]);
1708                         }
1709                 }
1710
1711         } catch (e) {
1712                 exception_error("dismissReadArticles", e);
1713         }
1714 }
1715
1716 function getVisibleArticleIds() {
1717         var ids = [];
1718
1719         try {
1720
1721                 getLoadedArticleIds().each(function(id) {
1722                         var elem = $("RROW-" + id);
1723                         if (elem && Element.visible(elem))
1724                                 ids.push(id);
1725                         });
1726
1727         } catch (e) {
1728                 exception_error("getVisibleArticleIds", e);
1729         }
1730
1731         return ids;
1732 }
1733
1734 function cdmClicked(event, id) {
1735         try {
1736                 //var shift_key = event.shiftKey;
1737
1738                 if (!event.ctrlKey) {
1739
1740                         if (!getInitParam("cdm_expanded")) {
1741                                 return cdmExpandArticle(id);
1742                         } else {
1743
1744                                 var elem = $("RROW-" + getActiveArticleId());
1745
1746                                 if (elem) elem.removeClassName("active");
1747
1748                                 selectArticles("none");
1749                                 toggleSelected(id);
1750
1751                                 var elem = $("RROW-" + id);
1752                                 var article_is_unread = elem.hasClassName("Unread");
1753
1754                                 elem.removeClassName("Unread");
1755                                 elem.addClassName("active");
1756
1757                                 setActiveArticleId(id);
1758
1759                                 if (article_is_unread) {
1760                                         decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1761                                         updateFloatingTitle(true);
1762                                 }
1763
1764                                 var query = "?op=rpc&method=catchupSelected" +
1765                                         "&cmode=0&ids=" + param_escape(id);
1766
1767                                 new Ajax.Request("backend.php", {
1768                                         parameters: query,
1769                                         onComplete: function(transport) {
1770                                                 handle_rpc_json(transport);
1771                                         } });
1772
1773                                 return !event.shiftKey;
1774                         }
1775
1776                 } else if (event.target.parents(".cdmHeader").length > 0) {
1777
1778                         toggleSelected(id, true);
1779
1780                         var elem = $("RROW-" + id);
1781                         var article_is_unread = elem.hasClassName("Unread");
1782
1783                         if (article_is_unread) {
1784                                 decrementFeedCounter(getActiveFeedId(), activeFeedIsCat());
1785                         }
1786
1787                         toggleUnread(id, 0, false);
1788
1789                         openArticleInNewWindow(id);
1790                 }
1791
1792                 var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length
1793                 request_counters(unread_in_buffer == 0);
1794
1795         } catch (e) {
1796                 exception_error("cdmClicked");
1797         }
1798
1799         return false;
1800 }
1801
1802 function hlClicked(event, id) {
1803         try {
1804                 if (event.which == 2) {
1805                         view(id);
1806                         return true;
1807                 } else if (event.ctrlKey) {
1808                         toggleSelected(id, true);
1809                         toggleUnread(id, 0, false);
1810                         openArticleInNewWindow(id);
1811                         return false;
1812                 } else {
1813                         view(id);
1814                         return false;
1815                 }
1816
1817         } catch (e) {
1818                 exception_error("hlClicked");
1819         }
1820 }
1821
1822 function getFirstVisibleHeadlineId() {
1823         var rows = getVisibleArticleIds();
1824         return rows[0];
1825
1826 }
1827
1828 function getLastVisibleHeadlineId() {
1829         var rows = getVisibleArticleIds();
1830         return rows[rows.length-1];
1831 }
1832
1833 function openArticleInNewWindow(id) {
1834         toggleUnread(id, 0, false);
1835         window.open("backend.php?op=article&method=redirect&id=" + id);
1836 }
1837
1838 function isCdmMode() {
1839         return getInitParam("combined_display_mode");
1840 }
1841
1842 function markHeadline(id, marked) {
1843         if (marked == undefined) marked = true;
1844
1845         var row = $("RROW-" + id);
1846         if (row) {
1847                 var check = dijit.getEnclosingWidget(
1848                                 row.getElementsByClassName("rchk")[0]);
1849
1850                 if (check) {
1851                         check.attr("checked", marked);
1852                 }
1853
1854                 if (marked)
1855                         row.addClassName("Selected");
1856                 else
1857                         row.removeClassName("Selected");
1858         }
1859 }
1860
1861 function getRelativePostIds(id, limit) {
1862
1863         var tmp = [];
1864
1865         try {
1866
1867                 if (!limit) limit = 6; //3
1868
1869                 var ids = getVisibleArticleIds();
1870
1871                 for (var i = 0; i < ids.length; i++) {
1872                         if (ids[i] == id) {
1873                                 for (var k = 1; k <= limit; k++) {
1874                                         //if (i > k-1) tmp.push(ids[i-k]);
1875                                         if (i < ids.length-k) tmp.push(ids[i+k]);
1876                                 }
1877                                 break;
1878                         }
1879                 }
1880
1881         } catch (e) {
1882                 exception_error("getRelativePostIds", e);
1883         }
1884
1885         return tmp;
1886 }
1887
1888 function correctHeadlinesOffset(id) {
1889
1890         try {
1891
1892                 var container = $("headlines-frame");
1893                 var row = $("RROW-" + id);
1894
1895                 if (!container || !row) return;
1896
1897                 var viewport = container.offsetHeight;
1898
1899                 var rel_offset_top = row.offsetTop - container.scrollTop;
1900                 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
1901
1902                 //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
1903                 //console.log("Vport: " + viewport);
1904
1905                 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
1906                         container.scrollTop = row.offsetTop;
1907                 } else if (rel_offset_bottom > viewport) {
1908
1909                         /* doesn't properly work with Opera in some cases because
1910                                 Opera fucks up element scrolling */
1911
1912                         container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
1913                 }
1914
1915         } catch (e) {
1916                 exception_error("correctHeadlinesOffset", e);
1917         }
1918
1919 }
1920
1921 function headlineActionsChange(elem) {
1922         try {
1923                 eval(elem.value);
1924                 elem.attr('value', 'false');
1925         } catch (e) {
1926                 exception_error("headlineActionsChange", e);
1927         }
1928 }
1929
1930 function closeArticlePanel() {
1931
1932         if (dijit.byId("content-insert"))
1933                 dijit.byId("headlines-wrap-inner").removeChild(
1934                         dijit.byId("content-insert"));
1935 }
1936
1937 function initFloatingMenu() {
1938         try {
1939                 if (dijit.byId("floatingMenu"))
1940                         dijit.byId("floatingMenu").destroyRecursive();
1941
1942                         var menu = new dijit.Menu({
1943                                 id: "floatingMenu",
1944                                 targetNodeIds: ["floatingTitle"]
1945                         });
1946
1947                         var id = $("floatingTitle").getAttribute("rowid").replace("RROW-", "");
1948
1949                         headlinesMenuCommon(menu, id);
1950
1951                         menu.startup();
1952         } catch (e) {
1953                 exception_error("initFloatingMenu", e);
1954         }
1955 }
1956
1957 function headlinesMenuCommon(menu, base_id) {
1958         try {
1959
1960                 menu.addChild(new dijit.MenuItem({
1961                         label: __("Open original article"),
1962                         onClick: function(event) {
1963                                 openArticleInNewWindow(base_id ? base_id : this.getParent().callerRowId);
1964                         }}));
1965
1966                 menu.addChild(new dijit.MenuItem({
1967                         label: __("Display article URL"),
1968                         onClick: function(event) {
1969                                 displayArticleUrl(base_id ? base_id : this.getParent().callerRowId);
1970                         }}));
1971
1972                 menu.addChild(new dijit.MenuSeparator());
1973
1974                 menu.addChild(new dijit.MenuItem({
1975                         label: __("Toggle unread"),
1976                         onClick: function(event) {
1977                                 var ids = getSelectedArticleIds2();
1978                                 // cast to string
1979                                 var id = (base_id ? base_id : this.getParent().callerRowId) + "";
1980                                 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1981
1982                                 selectionToggleUnread(undefined, false, true, ids);
1983                                 }}));
1984
1985                 menu.addChild(new dijit.MenuItem({
1986                         label: __("Toggle starred"),
1987                         onClick: function(event) {
1988                                 var ids = getSelectedArticleIds2();
1989                                 // cast to string
1990                                 var id = (base_id ? base_id : this.getParent().callerRowId) + "";
1991                                 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
1992
1993                                 selectionToggleMarked(undefined, false, true, ids);
1994                                 }}));
1995
1996                 menu.addChild(new dijit.MenuItem({
1997                         label: __("Toggle published"),
1998                         onClick: function(event) {
1999                                 var ids = getSelectedArticleIds2();
2000                                 // cast to string
2001                                 var id = (base_id ? base_id : this.getParent().callerRowId) + "";
2002                                 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2003
2004                                 selectionTogglePublished(undefined, false, true, ids);
2005                                 }}));
2006
2007                 menu.addChild(new dijit.MenuSeparator());
2008
2009                 menu.addChild(new dijit.MenuItem({
2010                         label: __("Mark above as read"),
2011                         onClick: function(event) {
2012                                 catchupRelativeToArticle(0, base_id ? base_id : this.getParent().callerRowId);
2013                                 }}));
2014
2015                 menu.addChild(new dijit.MenuItem({
2016                         label: __("Mark below as read"),
2017                         onClick: function(event) {
2018                                 catchupRelativeToArticle(1, base_id ? base_id : this.getParent().callerRowId);
2019                                 }}));
2020
2021
2022                 var labels = dijit.byId("feedTree").model.getItemsInCategory(-2);
2023
2024                 if (labels) {
2025
2026                         menu.addChild(new dijit.MenuSeparator());
2027
2028                         var labelAddMenu = new dijit.Menu({ownerMenu: menu});
2029                         var labelDelMenu = new dijit.Menu({ownerMenu: menu});
2030
2031                         labels.each(function(label) {
2032                                 var id = label.id[0];
2033                                 var bare_id = id.substr(id.indexOf(":")+1);
2034                                 var name = label.name[0];
2035
2036                                 bare_id = feed_to_label_id(bare_id);
2037
2038                                 labelAddMenu.addChild(new dijit.MenuItem({
2039                                         label: name,
2040                                         labelId: bare_id,
2041                                         onClick: function(event) {
2042                                                 var ids = getSelectedArticleIds2();
2043                                                 // cast to string
2044                                                 var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + "";
2045
2046                                                 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2047
2048                                                 selectionAssignLabel(this.labelId, ids);
2049                                 }}));
2050
2051                                 labelDelMenu.addChild(new dijit.MenuItem({
2052                                         label: name,
2053                                         labelId: bare_id,
2054                                         onClick: function(event) {
2055                                                 var ids = getSelectedArticleIds2();
2056                                                 // cast to string
2057                                                 var id = (base_id ? base_id : this.getParent().ownerMenu.callerRowId) + "";
2058
2059                                                 ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
2060
2061                                                 selectionRemoveLabel(this.labelId, ids);
2062                                 }}));
2063
2064                         });
2065
2066                         menu.addChild(new dijit.PopupMenuItem({
2067                                 label: __("Assign label"),
2068                                 popup: labelAddMenu
2069                         }));
2070
2071                         menu.addChild(new dijit.PopupMenuItem({
2072                                 label: __("Remove label"),
2073                                 popup: labelDelMenu
2074                         }));
2075
2076                 }
2077
2078
2079         } catch (e) {
2080                 exception_error("headlinesMenuCommon", e);
2081         }
2082 }
2083
2084 function initHeadlinesMenu() {
2085         try {
2086                 if (dijit.byId("headlinesMenu"))
2087                         dijit.byId("headlinesMenu").destroyRecursive();
2088
2089                 var ids = [];
2090
2091                 if (!isCdmMode()) {
2092                         nodes = $$("#headlines-frame > div[id*=RROW]");
2093                 } else {
2094                         nodes = $$("#headlines-frame span[id*=RTITLE]");
2095                 }
2096
2097                 nodes.each(function(node) {
2098                         ids.push(node.id);
2099                 });
2100
2101                 var menu = new dijit.Menu({
2102                         id: "headlinesMenu",
2103                         targetNodeIds: ids
2104                 });
2105
2106                 var tmph = dojo.connect(menu, '_openMyself', function (event) {
2107                         var callerNode = event.target, match = null, tries = 0;
2108
2109                         while (match == null && callerNode && tries <= 3) {
2110                                 match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2111                                 callerNode = callerNode.parentNode;
2112                                 ++tries;
2113                         }
2114
2115                         if (match) this.callerRowId = parseInt(match[1]);
2116
2117                 });
2118
2119                 headlinesMenuCommon(menu, false);
2120
2121                 menu.startup();
2122
2123                 /* vgroup feed title menu */
2124
2125                 var nodes = $$("#headlines-frame > div[class='cdmFeedTitle']");
2126                 var ids = [];
2127
2128                 nodes.each(function(node) {
2129                         ids.push(node.id);
2130                 });
2131
2132                 if (ids.length > 0) {
2133                         if (dijit.byId("headlinesFeedTitleMenu"))
2134                                 dijit.byId("headlinesFeedTitleMenu").destroyRecursive();
2135
2136                         var menu = new dijit.Menu({
2137                                 id: "headlinesFeedTitleMenu",
2138                                 targetNodeIds: ids
2139                         });
2140
2141                         var tmph = dojo.connect(menu, '_openMyself', function (event) {
2142                                 var callerNode = event.target, match = null, tries = 0;
2143
2144                                 while (match == null && callerNode && tries <= 3) {
2145                                         console.log(callerNode.id);
2146
2147                                         match = callerNode.id.match("^[A-Z]+[-]([0-9]+)$");
2148                                         callerNode = callerNode.parentNode;
2149                                         ++tries;
2150
2151                                         console.log(match[1]);
2152                                 }
2153
2154                                 if (match) this.callerRowId = parseInt(match[1]);
2155
2156                         });
2157
2158                         menu.addChild(new dijit.MenuItem({
2159                                 label: __("Select articles in group"),
2160                                 onClick: function(event) {
2161                                         selectArticles("all",
2162                                                 "#headlines-frame > div[id*=RROW]"+
2163                                                 "[orig-feed-id='"+menu.callerRowId+"']");
2164
2165                                 }}));
2166
2167                         menu.addChild(new dijit.MenuItem({
2168                                 label: __("Mark group as read"),
2169                                 onClick: function(event) {
2170                                         selectArticles("none");
2171                                         selectArticles("all",
2172                                                 "#headlines-frame > div[id*=RROW]"+
2173                                                 "[orig-feed-id='"+menu.callerRowId+"']");
2174
2175                                         catchupSelection();
2176                                 }}));
2177
2178
2179                         menu.addChild(new dijit.MenuItem({
2180                                 label: __("Mark feed as read"),
2181                                 onClick: function(event) {
2182                                         catchupFeedInGroup(menu.callerRowId);
2183                                 }}));
2184
2185                         menu.startup();
2186
2187                 }
2188
2189         } catch (e) {
2190                 exception_error("initHeadlinesMenu", e);
2191         }
2192 }
2193
2194 function cache_set(id, obj) {
2195         //console.log("cache_set: " + id);
2196         if (has_storage)
2197                 try {
2198                         sessionStorage[id] = obj;
2199                 } catch (e) {
2200                         sessionStorage.clear();
2201                 }
2202 }
2203
2204 function cache_get(id) {
2205         if (has_storage)
2206                 return sessionStorage[id];
2207 }
2208
2209 function cache_clear() {
2210         if (has_storage)
2211                 sessionStorage.clear();
2212 }
2213
2214 function cache_delete(id) {
2215         if (has_storage)
2216                 sessionStorage.removeItem(id);
2217 }
2218
2219 function cancelSearch() {
2220         try {
2221                 _search_query = "";
2222                 viewCurrentFeed();
2223         } catch (e) {
2224                 exception_error("cancelSearch", e);
2225         }
2226 }
2227
2228 function setSelectionScore() {
2229         try {
2230                 var ids = getSelectedArticleIds2();
2231
2232                 if (ids.length > 0) {
2233                         console.log(ids);
2234
2235                         var score = prompt(__("Please enter new score for selected articles:"), score);
2236
2237                         if (score != undefined) {
2238                                 var query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
2239                                         "&score=" + param_escape(score);
2240
2241                                 new Ajax.Request("backend.php", {
2242                                         parameters: query,
2243                                         onComplete: function(transport) {
2244                                                 var reply = JSON.parse(transport.responseText);
2245                                                 if (reply) {
2246                                                         console.log(ids);
2247
2248                                                         ids.each(function(id) {
2249                                                                 var row = $("RROW-" + id);
2250
2251                                                                 if (row) {
2252                                                                         var pic = row.getElementsByClassName("hlScorePic")[0];
2253
2254                                                                         if (pic) {
2255                                                                                 pic.src = pic.src.replace(/score_.*?\.png/,
2256                                                                                         reply["score_pic"]);
2257                                                                                 pic.setAttribute("score", score);
2258                                                                         }
2259                                                                 }
2260                                                         });
2261                                                 }
2262                                         } });
2263                         }
2264
2265                 } else {
2266                         alert(__("No articles are selected."));
2267                 }
2268         } catch (e) {
2269                 exception_error("setSelectionScore", e);
2270         }
2271 }
2272
2273 function updateScore(id) {
2274         try {
2275                 var pic = $$("#RROW-" + id + " .hlScorePic")[0];
2276
2277                 if (pic) {
2278
2279                         var query = "op=article&method=getScore&id=" + param_escape(id);
2280
2281                         new Ajax.Request("backend.php", {
2282                                 parameters: query,
2283                                 onComplete: function(transport) {
2284                                         console.log(transport.responseText);
2285
2286                                         var reply = JSON.parse(transport.responseText);
2287
2288                                         if (reply) {
2289                                                 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2290                                                 pic.setAttribute("score", reply["score"]);
2291                                                 pic.setAttribute("title", reply["score"]);
2292                                         }
2293                                 } });
2294                 }
2295
2296         } catch (e) {
2297                 exception_error("updateScore", e);
2298         }
2299 }
2300
2301 function changeScore(id, pic) {
2302         try {
2303                 var score = pic.getAttribute("score");
2304
2305                 var new_score = prompt(__("Please enter new score for this article:"), score);
2306
2307                 if (new_score != undefined) {
2308
2309                         var query = "op=article&method=setScore&id=" + param_escape(id) +
2310                                 "&score=" + param_escape(new_score);
2311
2312                         new Ajax.Request("backend.php", {
2313                                 parameters: query,
2314                                 onComplete: function(transport) {
2315                                         var reply = JSON.parse(transport.responseText);
2316
2317                                         if (reply) {
2318                                                 pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
2319                                                 pic.setAttribute("score", new_score);
2320                                                 pic.setAttribute("title", new_score);
2321                                         }
2322                                 } });
2323                 }
2324         } catch (e) {
2325                 exception_error("changeScore", e);
2326         }
2327 }
2328
2329 function displayArticleUrl(id) {
2330         try {
2331                 var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
2332
2333                         new Ajax.Request("backend.php", {
2334                                 parameters: query,
2335                                 onComplete: function(transport) {
2336                                         var reply = JSON.parse(transport.responseText);
2337
2338                                         if (reply && reply.link) {
2339                                                 prompt(__("Article URL:"), reply.link);
2340                                         }
2341                                 } });
2342         } catch (e) {
2343                 exception_error("changeScore", e);
2344         }
2345 }
2346
2347 function openSelectedAttachment(elem) {
2348         try {
2349                 var url = elem[elem.selectedIndex].value;
2350
2351                 if (url) {
2352                         window.open(url);
2353                         elem.selectedIndex = 0;
2354                 }
2355
2356         } catch (e) {
2357                 exception_error("openSelectedAttachment", e);
2358         }
2359 }
2360
2361 function scrollToRowId(id) {
2362         try {
2363                 var row = $(id);
2364
2365                 if (row)
2366                         $("headlines-frame").scrollTop = row.offsetTop - 4;
2367
2368         } catch (e) {
2369                 exception_error("scrollToRowId", e);
2370         }
2371 }
2372
2373 function updateFloatingTitle(unread_only) {
2374         try {
2375                 if (!isCdmMode()) return;
2376
2377                 var hf = $("headlines-frame");
2378
2379                 var elems = $$("#headlines-frame > div[id*=RROW]");
2380
2381                 for (var i = 0; i < elems.length; i++) {
2382
2383                         var child = elems[i];
2384
2385                         if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) {
2386
2387                                 var header = child.getElementsByClassName("cdmHeader")[0];
2388
2389                                 if (unread_only || child.id != $("floatingTitle").getAttribute("rowid")) {
2390                                         if (child.id != $("floatingTitle").getAttribute("rowid")) {
2391                                                 $("floatingTitle").setAttribute("rowid", child.id);
2392                                                 $("floatingTitle").innerHTML = header.innerHTML;
2393                                                 $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('"+child.id+"')\">" + $("floatingTitle").firstChild.innerHTML;
2394
2395                                                 initFloatingMenu();
2396
2397                                                 var cb = $$("#floatingTitle .dijitCheckBox")[0];
2398
2399                                                 if (cb)
2400                                                         cb.parentNode.removeChild(cb);
2401                                         }
2402
2403                                         if (child.hasClassName("Unread"))
2404                                                 $("floatingTitle").addClassName("Unread");
2405                                         else
2406                                                 $("floatingTitle").removeClassName("Unread");
2407
2408                                         PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child);
2409                                 }
2410
2411                                 $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px";
2412                                 if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 &&
2413                                     child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5)
2414                                         $("floatingTitle").style.visibility = "visible";
2415                                 else
2416                                         $("floatingTitle").style.visibility = "hidden";
2417
2418                                 return;
2419
2420                         }
2421                 }
2422
2423         } catch (e) {
2424                 exception_error("updateFloatingTitle", e);
2425         }
2426 }
2427
2428 function cdmFooterClick(event) {
2429         event.stopPropagation();
2430 }