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