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