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