]> git.wh0rd.org - tt-rss.git/blame - viewfeed.js
help pic position fix for Safari
[tt-rss.git] / viewfeed.js
CommitLineData
bb7cface 1var active_post_id = false;
4b6206fa 2var last_article_view = false;
0b126ac2
AD
3var active_real_feed_id = false;
4
13f08f75 5// FIXME: kludges, needs proper implementation
0b126ac2 6var _reload_feedlist_after_view = false;
e08443c1 7
ba0978c8
AD
8var _cdm_wd_timeout = false;
9var _cdm_wd_vishist = new Array();
10
e097e8be
AD
11var article_cache = new Array();
12
081e527d 13var vgroup_last_feed = false;
314fcd2b 14var post_under_pointer = false;
081e527d 15
022d9e9e
AD
16var last_requested_article = false;
17
c7e51de1
AD
18function toggle_published_callback(transport) {
19 try {
20 if (transport.responseXML) {
21
22 all_counters_callback2(transport);
23
24 var note = transport.responseXML.getElementsByTagName("note")[0];
25
26 if (note) {
27 var note_id = note.getAttribute("id");
28 var note_size = note.getAttribute("size");
29 var note_content = note.firstChild.nodeValue;
30
31 var container = $('POSTNOTE-' + note_id);
32
33 cache_invalidate(note_id);
34
35 if (container) {
36 if (note_size == "0") {
37 Element.hide(container);
38 } else {
39 container.innerHTML = note_content;
40 Element.show(container);
41 }
42 }
43 }
44 }
45
46 } catch (e) {
47 exception_error("toggle_published_callback", e, transport);
48 }
49}
50
1341ea0d
AD
51function catchup_callback2(transport, callback) {
52 try {
53 debug("catchup_callback2 " + transport + ", " + callback);
54 notify("");
55 all_counters_callback2(transport);
56 if (callback) {
57 setTimeout(callback, 10);
58 }
59 } catch (e) {
273d1e29 60 exception_error("catchup_callback2", e, transport);
1341ea0d
AD
61 }
62}
63
e19c1824 64function clean_feed_selections() {
a49f5e05 65 try {
acac8448 66 var feeds = $("feedList").getElementsByTagName("LI");
a49f5e05 67
6c3b0198
AD
68 for (var i = 0; i < feeds.length; i++) {
69 if (feeds[i].id && feeds[i].id.match("FEEDR-")) {
70 feeds[i].className = feeds[i].className.replace("Selected", "");
71 }
5ee9816c
AD
72 if (feeds[i].id && feeds[i].id.match("FCAT-")) {
73 feeds[i].className = feeds[i].className.replace("Selected", "");
74 }
6c3b0198 75 }
e19c1824
AD
76 } catch (e) {
77 exception_error("clean_feed_selections", e);
78 }
79}
80
3d72bbdb 81function headlines_callback2(transport, feed_cur_page) {
e19c1824
AD
82 try {
83
9ca945a6
AD
84 if (!transport.responseText && db) {
85 offlineConfirmModeChange();
86 return;
87 }
88
730dbf19
AD
89 loading_set_progress(100);
90
e19c1824
AD
91 debug("headlines_callback2 [page=" + feed_cur_page + "]");
92
2184738a
AD
93 if (!transport_error_check(transport)) return;
94
e19c1824 95 clean_feed_selections();
3d72bbdb
AD
96
97 var is_cat = false;
98 var feed_id = false;
ac541432 99
3d72bbdb
AD
100 if (transport.responseXML) {
101 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
102 if (headlines) {
103 is_cat = headlines.getAttribute("is_cat");
104 feed_id = headlines.getAttribute("id");
105 setActiveFeedId(feed_id, is_cat);
106 }
6c3b0198 107 }
f46192bb 108
6e35a862
AD
109 var ll = $('FLL-' + feed_id);
110
6c3b0198 111 if (!is_cat) {
acac8448 112 var feedr = $("FEEDR-" + feed_id);
6c3b0198
AD
113 if (feedr && !feedr.className.match("Selected")) {
114 feedr.className = feedr.className + "Selected";
115 }
6e35a862 116 if (feedr && ll) feedr.removeChild(ll);
5ee9816c 117 } else {
acac8448 118 var feedr = $("FCAT-" + feed_id);
5ee9816c
AD
119 if (feedr && !feedr.className.match("Selected")) {
120 feedr.className = feedr.className + "Selected";
121 }
b7665618
AD
122
123 var fcap = $("FCAP-" + feed_id);
124 if (fcap && ll) fcap.removeChild(ll);
6e35a862 125
6c3b0198 126 }
6e35a862 127
105b61b7
AD
128 var img = $('FIMG-' + feed_id);
129
130 if (img && !is_cat) {
131 img.src = img.alt;
105b61b7
AD
132 }
133
acac8448 134 var f = $("headlines-frame");
6c3b0198
AD
135 try {
136 if (feed_cur_page == 0) {
137 debug("resetting headlines scrollTop");
138 f.scrollTop = 0;
a49f5e05 139 }
6c3b0198
AD
140 } catch (e) { };
141
142 if (transport.responseXML) {
143 var headlines = transport.responseXML.getElementsByTagName("headlines")[0];
144 var headlines_count_obj = transport.responseXML.getElementsByTagName("headlines-count")[0];
e19c1824 145 var headlines_unread_obj = transport.responseXML.getElementsByTagName("headlines-unread")[0];
52d7e7da 146 var disable_cache_obj = transport.responseXML.getElementsByTagName("disable-cache")[0];
e19c1824 147
081e527d
AD
148 var vgroup_last_feed_obj = transport.responseXML.getElementsByTagName("vgroup-last-feed")[0];
149
6c3b0198 150 var headlines_count = headlines_count_obj.getAttribute("value");
e19c1824 151 var headlines_unread = headlines_unread_obj.getAttribute("value");
52d7e7da 152 var disable_cache = disable_cache_obj.getAttribute("value") != "0";
e19c1824 153
081e527d
AD
154 vgroup_last_feed = vgroup_last_feed_obj.getAttribute("value");
155
587bef10
AD
156 if (headlines_count == 0) {
157 _infscroll_disable = 1;
158 } else {
159 _infscroll_disable = 0;
160 }
161
6c3b0198
AD
162 var counters = transport.responseXML.getElementsByTagName("counters")[0];
163 var articles = transport.responseXML.getElementsByTagName("article");
164 var runtime_info = transport.responseXML.getElementsByTagName("runtime-info");
165
166 if (feed_cur_page == 0) {
167 if (headlines) {
168 f.innerHTML = headlines.firstChild.nodeValue;
e19c1824 169
dd5865d4
AD
170 var cache_prefix = "";
171
172 if (is_cat) {
173 cache_prefix = "C:";
174 } else {
175 cache_prefix = "F:";
176 }
177
3d72bbdb 178 cache_invalidate(cache_prefix + feed_id);
7e8832b3 179
52d7e7da 180 if (!disable_cache) {
3d72bbdb 181 cache_inject(cache_prefix + feed_id,
52d7e7da
AD
182 headlines.firstChild.nodeValue, headlines_unread);
183 }
e19c1824 184
6c3b0198
AD
185 } else {
186 debug("headlines_callback: returned no data");
187 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML data)') + "</div>";
188
189 }
190 } else {
191 if (headlines) {
192 if (headlines_count > 0) {
193 debug("adding some more headlines...");
194
acac8448 195 var c = $("headlinesList");
6c3b0198
AD
196
197 if (!c) {
acac8448 198 c = $("headlinesInnerContainer");
6c3b0198 199 }
c32cd48a
AD
200
201 var ids = getSelectedArticleIds2();
6c3b0198
AD
202
203 c.innerHTML = c.innerHTML + headlines.firstChild.nodeValue;
c32cd48a
AD
204
205 debug("restore selected ids: " + ids);
206
207 for (var i = 0; i < ids.length; i++) {
208 markHeadline(ids[i]);
209 }
210
6c3b0198
AD
211 } else {
212 debug("no new headlines received");
29dfb258 213 }
29dfb258 214 } else {
6c3b0198
AD
215 debug("headlines_callback: returned no data");
216 notify_error("Error while trying to load more headlines");
217 }
730dbf19 218
6c3b0198
AD
219 }
220
221 if (articles) {
222 for (var i = 0; i < articles.length; i++) {
223 var a_id = articles[i].getAttribute("id");
224 debug("found id: " + a_id);
225 cache_inject(a_id, articles[i].firstChild.nodeValue);
ac541432 226 }
007a38d4 227 } else {
6c3b0198 228 debug("no cached articles received");
961f4c73 229 }
6c3b0198
AD
230
231 if (counters) {
232 debug("parsing piggybacked counters: " + counters);
233 parse_counters(counters, false);
234 } else {
5aaf9b34
AD
235 debug("counters container not found in reply, requesting...");
236 request_counters();
6c3b0198
AD
237 }
238
239 if (runtime_info) {
240 debug("parsing runtime info: " + runtime_info[0]);
241 parse_runtime_info(runtime_info[0]);
242 } else {
243 debug("counters container not found in reply");
03c88bdd 244 }
6c3b0198 245
3de0261a 246 } else {
6c3b0198
AD
247 debug("headlines_callback: returned no XML object");
248 f.innerHTML = "<div class='whiteBox'>" + __('Could not update headlines (missing XML object)') + "</div>";
3de0261a 249 }
6c3b0198
AD
250
251 if (typeof correctPNG != 'undefined') {
252 correctPNG();
935f235d 253 }
6c3b0198
AD
254
255 if (_cdm_wd_timeout) window.clearTimeout(_cdm_wd_timeout);
256
acac8448 257 if (!$("headlinesList") &&
a969b30b 258 getActiveFeedId() != -3 &&
6c3b0198
AD
259 getInitParam("cdm_auto_catchup") == 1) {
260 debug("starting CDM watchdog");
261 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 5000);
262 _cdm_wd_vishist = new Array();
ac7bcd71 263 } else {
6c3b0198 264 debug("not in CDM mode or watchdog disabled");
ba0978c8 265 }
6c3b0198 266
6c3b0198 267 _feed_cur_page = feed_cur_page;
82764a41
AD
268 _infscroll_request_sent = 0;
269
6c3b0198 270 notify("");
730dbf19
AD
271
272 remove_splash();
273
6c3b0198 274 } catch (e) {
273d1e29 275 exception_error("headlines_callback2", e, transport);
6b4163cb
AD
276 }
277}
278
e097e8be
AD
279function render_article(article) {
280 try {
acac8448 281 var f = $("content-frame");
44cc6f20
AD
282 try {
283 f.scrollTop = 0;
284 } catch (e) { };
e097e8be 285
acac8448 286 var fi = $("content-insert");
17042fc0 287
e5ebee09
AD
288 try {
289 fi.scrollTop = 0;
290 } catch (e) { };
95f67d2e 291
17042fc0 292 fi.innerHTML = article;
95f67d2e 293
51682b23 294// article.evalScripts();
e097e8be
AD
295
296 } catch (e) {
297 exception_error("render_article", e);
298 }
299}
300
71d277de 301function showArticleInHeadlines(id) {
e097e8be 302
868d0ed2 303 try {
e097e8be 304
868d0ed2 305 cleanSelected("headlinesList");
71d277de 306
acac8448 307 var crow = $("RROW-" + id);
76283a4c
AD
308
309 if (!crow) return;
310
868d0ed2
AD
311 var article_is_unread = crow.className.match("Unread");
312
313 crow.className = crow.className.replace("Unread", "");
fdcdf2de
AD
314
315 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
fdcdf2de 316
acac8448 317 var upd_img_pic = $("FUPDPIC-" + id);
ebda016b 318
fdcdf2de 319 var cache_prefix = "";
ebda016b 320
fdcdf2de
AD
321 if (activeFeedIsCat()) {
322 cache_prefix = "C:";
323 } else {
324 cache_prefix = "F:";
325 }
11063ec6
AD
326
327 var view_mode = false;
328
329 try {
330 view_mode = document.forms['main_toolbar_form'].view_mode;
331 view_mode = view_mode[view_mode.selectedIndex].value;
332 } catch (e) {
273d1e29 333 //
11063ec6
AD
334 }
335
784ac51f
AD
336 if (upd_img_pic && (upd_img_pic.src.match("updated.png") ||
337 upd_img_pic.src.match("fresh_sign.png"))) {
338
fdcdf2de 339 upd_img_pic.src = "images/blank_icon.gif";
ebda016b
AD
340
341 cache_invalidate(cache_prefix + getActiveFeedId());
ce411c4b
AD
342
343 cache_inject(cache_prefix + getActiveFeedId(),
acac8448 344 $("headlines-frame").innerHTML,
ce411c4b 345 get_feed_unread(getActiveFeedId()));
fdcdf2de 346
11063ec6 347 } else if (article_is_unread && view_mode == "all_articles") {
fdcdf2de
AD
348
349 cache_invalidate(cache_prefix + getActiveFeedId());
350
351 cache_inject(cache_prefix + getActiveFeedId(),
acac8448 352 $("headlines-frame").innerHTML,
fdcdf2de
AD
353 get_feed_unread(getActiveFeedId())-1);
354
3de99e6b
AD
355 } else if (article_is_unread) {
356 cache_invalidate(cache_prefix + getActiveFeedId());
868d0ed2 357 }
e097e8be 358
4c009c78
AD
359 markHeadline(id);
360
868d0ed2
AD
361 } catch (e) {
362 exception_error("showArticleInHeadlines", e);
363 }
71d277de 364}
e097e8be 365
a491a7f1 366function article_callback2(transport, id) {
71d277de
AD
367 try {
368 debug("article_callback2 " + id);
e097e8be 369
9ca945a6
AD
370 if (!transport.responseText && db) {
371 offlineConfirmModeChange();
372 return;
373 }
374
71d277de 375 if (transport.responseXML) {
e097e8be 376
2184738a
AD
377 if (!transport_error_check(transport)) return;
378
b1039124 379/* var ll = $('LL-' + id);
6e35a862
AD
380 var content = $('HLC-' + id);
381
b1039124 382 if (ll && content) content.removeChild(ll); */
6e35a862 383
b1039124
AD
384 var upic = $('FUPDPIC-' + id);
385
386 if (upic) {
387 upic.src = 'images/blank_icon.gif';
388 }
389
6e35a862
AD
390 if (id != last_requested_article) {
391 debug("requested article id is out of sequence, aborting");
392 return;
393 }
394
6e35a862
AD
395 active_post_id = id;
396
fbcabe1e 397 debug("looking for articles to cache...");
71d277de
AD
398
399 var articles = transport.responseXML.getElementsByTagName("article");
400
401 for (var i = 0; i < articles.length; i++) {
402 var a_id = articles[i].getAttribute("id");
403
404 debug("found id: " + a_id);
405
406 if (a_id == active_post_id) {
407 debug("active article, rendering...");
408 render_article(articles[i].firstChild.nodeValue);
e097e8be 409 }
71d277de
AD
410
411 cache_inject(a_id, articles[i].firstChild.nodeValue);
e097e8be 412 }
fbcabe1e 413
fbcabe1e
AD
414
415 showArticleInHeadlines(id);
416
2f71f07b
AD
417 if (db) {
418 db.execute("UPDATE articles SET unread = 0 WHERE id = ?", [id]);
419 }
420
fbcabe1e 421 var reply = transport.responseXML.firstChild.firstChild;
71d277de
AD
422
423 } else {
424 debug("article_callback: returned no XML object");
acac8448 425 //var f = $("content-frame");
17042fc0 426 //f.innerHTML = "<div class='whiteBox'>" + __('Could not display article (missing XML object)') + "</div>";
e097e8be 427 }
4b6206fa
AD
428
429 var date = new Date();
430 last_article_view = date.getTime() / 1000;
431
935f235d
AD
432 if (typeof correctPNG != 'undefined') {
433 correctPNG();
434 }
0b126ac2
AD
435
436 if (_reload_feedlist_after_view) {
437 setTimeout('updateFeedList(false, false)', 50);
438 _reload_feedlist_after_view = false;
439 } else {
d63170bf
AD
440 if (transport.responseXML) {
441 var counters = transport.responseXML.getElementsByTagName("counters")[0];
5a94a953 442
d63170bf
AD
443 if (counters) {
444 debug("parsing piggybacked counters: " + counters);
445 parse_counters(counters, false);
446 } else {
447 debug("counters container not found in reply, requesting...");
448 request_counters();
449 }
5a94a953 450 }
0b126ac2 451 }
9ec58704
AD
452
453 notify("");
71d277de 454 } catch (e) {
273d1e29 455 exception_error("article_callback2", e, transport);
6b4163cb
AD
456 }
457}
458
a491a7f1 459function view(id) {
ee1f45f4 460 try {
a491a7f1 461 debug("loading article: " + id);
12e55b90 462
a491a7f1 463 if (offline_mode) return view_offline(id);
45a6446d 464
e097e8be
AD
465 var cached_article = cache_find(id);
466
467 debug("cache check result: " + (cached_article != false));
ee1f45f4 468
ee1f45f4 469 enableHotkeys();
664306d3
AD
470 hideAuxDlg();
471
a491a7f1 472 var query = "?op=view&id=" + param_escape(id);
6b4163cb 473
4b6206fa
AD
474 var date = new Date();
475
71d277de 476 var neighbor_ids = getRelativePostIds(active_post_id);
e097e8be 477
71d277de 478 /* only request uncached articles */
e097e8be 479
71d277de 480 var cids_to_request = Array();
5a94a953 481
71d277de
AD
482 for (var i = 0; i < neighbor_ids.length; i++) {
483 if (!cache_check(neighbor_ids[i])) {
484 cids_to_request.push(neighbor_ids[i]);
5a94a953 485 }
71d277de 486 }
5a94a953 487
71d277de 488 debug("additional ids: " + cids_to_request.toString());
e097e8be 489
71d277de 490 /* additional info for piggyback counters */
e097e8be 491
71d277de
AD
492 if (tagsAreDisplayed()) {
493 query = query + "&omode=lt";
494 } else {
495 query = query + "&omode=flc";
496 }
e097e8be 497
71d277de
AD
498 var date = new Date();
499 var timestamp = Math.round(date.getTime() / 1000);
500 query = query + "&ts=" + timestamp;
e097e8be 501
71d277de 502 query = query + "&cids=" + cids_to_request.toString();
e097e8be 503
acac8448 504 var crow = $("RROW-" + id);
71d277de 505 var article_is_unread = crow.className.match("Unread");
e097e8be 506
6cc1fab3
AD
507 if (!async_counters_work) {
508 query = query + "&csync=true";
509 }
510
3f70f90f
AD
511 showArticleInHeadlines(id);
512
71d277de 513 if (!cached_article) {
e097e8be 514
6e35a862
AD
515// notify_progress("Loading, please wait...", true);
516
b1039124 517/* var content = $('HLC-' + id);
6e35a862
AD
518
519 if (content && !$('LL-' + id)) {
520 var ll = document.createElement('img');
521
522 ll.src = 'images/indicator_tiny.gif';
523 ll.className = 'hlLoading';
524 ll.id = 'LL-' + id;
525
526 content.appendChild(ll);
527
b1039124
AD
528 } */
529
530 var upic = $('FUPDPIC-' + id);
531
532 if (upic) {
533 upic.src = 'images/indicator_white.gif';
6e35a862 534 }
e097e8be 535
71d277de 536 } else if (cached_article && article_is_unread) {
addb5836 537
71d277de 538 query = query + "&mode=prefetch";
addb5836 539
71d277de 540 render_article(cached_article);
addb5836 541
71d277de 542 } else if (cached_article) {
e097e8be 543
71d277de
AD
544 query = query + "&mode=prefetch_old";
545 render_article(cached_article);
997d9d7c 546
71d277de 547 }
e097e8be 548
71d277de 549 cache_expire();
86173d9a 550
022d9e9e
AD
551 last_requested_article = id;
552
b4e75b2a
AD
553 new Ajax.Request("backend.php", {
554 parameters: query,
71d277de 555 onComplete: function(transport) {
a491a7f1 556 article_callback2(transport, id);
71d277de 557 } });
6b4163cb 558
a7764e51
AD
559 return false;
560
ee1f45f4
AD
561 } catch (e) {
562 exception_error("view", e);
563 }
f0601b87
AD
564}
565
67343d9f
AD
566function tMark(id) {
567 return toggleMark(id);
568}
569
e4f4b46f
AD
570function tPub(id) {
571 return togglePub(id);
572}
573
6b0f49f9
AD
574function tMark_afh_off(effect) {
575 try {
576 var elem = effect.effects[0].element;
577
578 debug("tMark_afh_off : " + elem.id);
579
580 if (elem) {
f5e0338d
AD
581 elem.src = elem.src.replace("mark_set", "mark_unset");
582 elem.alt = __("Star article");
6b0f49f9
AD
583 Element.show(elem);
584 }
585
586 } catch (e) {
587 exception_error("tMark_afh_off", e);
588 }
589}
590
591function tPub_afh_off(effect) {
592 try {
593 var elem = effect.effects[0].element;
594
595 debug("tPub_afh_off : " + elem.id);
596
597 if (elem) {
f5e0338d
AD
598 elem.src = elem.src.replace("pub_set", "pub_unset");
599 elem.alt = __("Publish article");
6b0f49f9
AD
600 Element.show(elem);
601 }
602
603 } catch (e) {
604 exception_error("tPub_afh_off", e);
605 }
606}
e4f4b46f 607
f5e0338d 608function toggleMark(id, client_only, no_effects) {
f0601b87 609
b685ba25 610 try {
254e0e4b 611
b4e75b2a 612 var query = "?op=rpc&id=" + id + "&subop=mark";
b685ba25
AD
613
614 query = query + "&afid=" + getActiveFeedId();
615
616 if (tagsAreDisplayed()) {
617 query = query + "&omode=tl";
618 } else {
619 query = query + "&omode=flc";
7ba176d2 620 }
b685ba25 621
acac8448 622 var mark_img = $("FMPIC-" + id);
56ff7564
AD
623
624 if (!mark_img) return;
625
acac8448
AD
626 var vfeedu = $("FEEDU--1");
627 var crow = $("RROW-" + id);
b685ba25 628
f5e0338d
AD
629 if (mark_img.src.match("mark_unset")) {
630 mark_img.src = mark_img.src.replace("mark_unset", "mark_set");
631 mark_img.alt = __("Unstar article");
b685ba25 632 query = query + "&mark=1";
ee8768db 633
2f71f07b
AD
634 if (db) {
635 db.execute("UPDATE articles SET marked = 1 WHERE id = ?", [id]);
636 }
637
b685ba25
AD
638 } else {
639 //mark_img.src = "images/mark_unset.png";
f5e0338d 640 mark_img.alt = __("Please wait...");
b685ba25
AD
641 query = query + "&mark=0";
642
acac8448 643 if ($("headlinesList") && !no_effects) {
b685ba25
AD
644 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tMark_afh_off});
645 } else {
f5e0338d
AD
646 mark_img.src = mark_img.src.replace("mark_set", "mark_unset");
647 mark_img.alt = __("Star article");
b685ba25 648 }
2f71f07b
AD
649
650 if (db) {
651 db.execute("UPDATE articles SET marked = 0 WHERE id = ?", [id]);
652 }
653
ace1a6da 654 }
772bc83b 655
46b84d29 656 if (!no_effects) update_local_feedlist_counters();
c8a9fe5b 657
f5e0338d
AD
658 if (!client_only) {
659 debug(query);
36e05046 660
b4e75b2a
AD
661 new Ajax.Request("backend.php", {
662 parameters: query,
1341ea0d
AD
663 onComplete: function(transport) {
664 all_counters_callback2(transport);
665 } });
666
f5e0338d 667 }
f0601b87 668
b685ba25
AD
669 } catch (e) {
670 exception_error("toggleMark", e);
671 }
f0601b87
AD
672}
673
c7e51de1 674function togglePub(id, client_only, no_effects, note) {
e4f4b46f 675
2bc2147f 676 try {
e4f4b46f 677
b4e75b2a 678 var query = "?op=rpc&id=" + id + "&subop=publ";
2bc2147f
AD
679
680 query = query + "&afid=" + getActiveFeedId();
c7e51de1
AD
681
682 if (note != undefined) {
683 query = query + "&note=" + param_escape(note);
684 } else {
685 query = query + "&note=undefined";
686 }
2bc2147f
AD
687
688 if (tagsAreDisplayed()) {
689 query = query + "&omode=tl";
690 } else {
691 query = query + "&omode=flc";
e4f4b46f 692 }
2bc2147f 693
acac8448 694 var mark_img = $("FPPIC-" + id);
56ff7564
AD
695
696 if (!mark_img) return;
697
acac8448
AD
698 var vfeedu = $("FEEDU--2");
699 var crow = $("RROW-" + id);
2bc2147f 700
c7e51de1 701 if (mark_img.src.match("pub_unset") || note != undefined) {
f5e0338d
AD
702 mark_img.src = mark_img.src.replace("pub_unset", "pub_set");
703 mark_img.alt = __("Unpublish article");
2bc2147f 704 query = query + "&pub=1";
ee8768db 705
e4f4b46f 706 } else {
6b0f49f9 707 //mark_img.src = "images/pub_unset.png";
f5e0338d 708 mark_img.alt = __("Please wait...");
2bc2147f
AD
709 query = query + "&pub=0";
710
acac8448 711 if ($("headlinesList") && !no_effects) {
ace1a6da
AD
712 Effect.Puff(mark_img, {duration : 0.25, afterFinish: tPub_afh_off});
713 } else {
f5e0338d
AD
714 mark_img.src = mark_img.src.replace("pub_set", "pub_unset");
715 mark_img.alt = __("Publish article");
ace1a6da 716 }
e4f4b46f 717 }
b685ba25 718
f5e0338d 719 if (!client_only) {
b4e75b2a
AD
720 new Ajax.Request("backend.php", {
721 parameters: query,
1341ea0d 722 onComplete: function(transport) {
c7e51de1 723 toggle_published_callback(transport);
1341ea0d 724 } });
f5e0338d 725 }
b685ba25 726
2bc2147f 727 } catch (e) {
e4f4b46f 728
2bc2147f
AD
729 exception_error("togglePub", e);
730 }
e4f4b46f
AD
731}
732
ac162cbe
AD
733function correctHeadlinesOffset(id) {
734
735 try {
736
acac8448
AD
737 var hlist = $("headlinesList");
738 var container = $("headlinesInnerContainer");
739 var row = $("RROW-" + id);
ac162cbe
AD
740
741 var viewport = container.offsetHeight;
742
743 var rel_offset_top = row.offsetTop - container.scrollTop;
744 var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
745
746 debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
747 debug("Vport: " + viewport);
a5e46e0f 748
ac162cbe
AD
749 if (rel_offset_top <= 0 || rel_offset_top > viewport) {
750 container.scrollTop = row.offsetTop;
751 } else if (rel_offset_bottom > viewport) {
a5e46e0f
AD
752
753 /* doesn't properly work with Opera in some cases because
754 Opera fucks up element scrolling */
755
ac162cbe
AD
756 container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
757 }
758
759 } catch (e) {
760 exception_error("correctHeadlinesOffset", e);
761 }
762
763}
764
bb7cface 765function moveToPost(mode) {
f0601b87 766
b8e6acea
AD
767 try {
768
5ad9d132
AD
769 var rows;
770
771 if (isCdmMode()) {
772 rows = cdmGetVisibleArticles();
773 } else {
774 rows = getVisibleHeadlineIds();
775 }
b8e6acea 776
5ad9d132
AD
777 var prev_id = false;
778 var next_id = false;
b8e6acea 779
acac8448 780 if (!$('RROW-' + active_post_id)) {
5ad9d132
AD
781 active_post_id = false;
782 }
b8e6acea 783
5ad9d132
AD
784 if (active_post_id == false) {
785 next_id = getFirstVisibleHeadlineId();
786 prev_id = getLastVisibleHeadlineId();
787 } else {
788 for (var i = 0; i < rows.length; i++) {
789 if (rows[i] == active_post_id) {
790 prev_id = rows[i-1];
791 next_id = rows[i+1];
b8e6acea
AD
792 }
793 }
5ad9d132 794 }
b8e6acea 795
5ad9d132
AD
796 if (mode == "next") {
797 if (next_id) {
798 if (isCdmMode()) {
799
800 if (!cdmArticleIsActuallyVisible(next_id)) {
801 cdmScrollToArticleId(next_id);
802 }
803 cdmSelectArticles("none");
804 toggleUnread(next_id, 0, true);
805 toggleSelected(next_id);
806
807 } else {
b8e6acea
AD
808 correctHeadlinesOffset(next_id);
809 view(next_id, getActiveFeedId());
810 }
811 }
5ad9d132 812 }
b8e6acea 813
5ad9d132
AD
814 if (mode == "prev") {
815 if (prev_id) {
816 if (isCdmMode()) {
817 cdmScrollToArticleId(prev_id);
818 cdmSelectArticles("none");
819 toggleUnread(prev_id, 0, true);
820 toggleSelected(prev_id);
821 } else {
b8e6acea
AD
822 correctHeadlinesOffset(prev_id);
823 view(prev_id, getActiveFeedId());
824 }
5ad9d132
AD
825 }
826 }
827
b8e6acea 828 } catch (e) {
438f2ce9 829 exception_error("moveToPost", e);
bb7cface 830 }
b8e6acea
AD
831}
832
833function toggleSelected(id) {
834 try {
835
acac8448 836 var cb = $("RCHK-" + id);
5ad9d132 837
acac8448 838 var row = $("RROW-" + id);
b8e6acea
AD
839 if (row) {
840 var nc = row.className;
841
842 if (!nc.match("Selected")) {
843 nc = nc + "Selected";
5ad9d132
AD
844 if (cb) {
845 cb.checked = true;
846 }
847
848 // In CDM basically last selected article == active article
849 if (isCdmMode()) active_post_id = id;
b8e6acea
AD
850 } else {
851 nc = nc.replace("Selected", "");
5ad9d132
AD
852 if (cb) {
853 cb.checked = false;
854 }
855
b8e6acea 856 }
bb7cface 857
b8e6acea 858 row.className = nc;
bb7cface 859 }
b8e6acea 860 } catch (e) {
438f2ce9 861 exception_error("toggleSelected", e);
b8e6acea 862 }
bb7cface
AD
863}
864
0df009c3 865function toggleUnread_afh(effect) {
b8e6acea
AD
866 try {
867
868 var elem = effect.element;
0df009c3 869 elem.style.backgroundColor = "";
b8e6acea 870
b8e6acea 871 } catch (e) {
438f2ce9 872 exception_error("toggleUnread_afh", e);
b8e6acea 873 }
0df009c3 874}
b8e6acea
AD
875
876function toggleUnread(id, cmode, effect) {
5f51022a 877 try {
5f51022a 878
acac8448 879 var row = $("RROW-" + id);
5f51022a
AD
880 if (row) {
881 var nc = row.className;
93f66472 882 var is_selected = row.className.match("Selected");
5f51022a
AD
883 nc = nc.replace("Unread", "");
884 nc = nc.replace("Selected", "");
885
b8e6acea
AD
886 // since we are removing selection from the object, uncheck
887 // corresponding checkbox
888
acac8448 889 var cb = $("RCHK-" + id);
b8e6acea
AD
890 if (cb) {
891 cb.checked = false;
892 }
893
894 // NOTE: I'm not sure that resetting selection here is a feature -fox
895
a70ab740
AD
896 if (cmode == undefined || cmode == 2) {
897 if (row.className.match("Unread")) {
898 row.className = nc;
b8e6acea 899
0df009c3 900 if (effect) {
b8e6acea
AD
901 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
902 afterFinish: toggleUnread_afh,
903 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
0df009c3 904 }
b8e6acea 905
a70ab740
AD
906 } else {
907 row.className = nc + "Unread";
908 }
1a003258
AD
909
910 if (db) {
911 db.execute("UPDATE articles SET unread = not unread "+
912 "WHERE id = ?", [id]);
913 }
914
a70ab740 915 } else if (cmode == 0) {
5f51022a 916 row.className = nc;
b8e6acea 917
54eb7d20 918 if (effect) {
b8e6acea 919 new Effect.Highlight(row, {duration: 1, startcolor: "#fff7d5",
54eb7d20 920 afterFinish: toggleUnread_afh,
b8e6acea 921 queue: { position:'end', scope: 'TMRQ-' + id, limit: 1 } } );
54eb7d20 922 }
1a003258
AD
923
924 if (db) {
925 db.execute("UPDATE articles SET unread = 0 "+
926 "WHERE id = ?", [id]);
927 }
928
a70ab740 929 } else if (cmode == 1) {
5f51022a 930 row.className = nc + "Unread";
1a003258
AD
931
932 if (db) {
933 db.execute("UPDATE articles SET unread = 1 "+
934 "WHERE id = ?", [id]);
935 }
936
5f51022a
AD
937 }
938
1a003258
AD
939 update_local_feedlist_counters();
940
93f66472
AD
941 // Disable unmarking as selected for the time being (16.05.08) -fox
942 if (is_selected) row.className = row.className + "Selected";
943
a70ab740 944 if (cmode == undefined) cmode = 2;
5f51022a 945
b4e75b2a
AD
946 var query = "?op=rpc&subop=catchupSelected" +
947 "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id);
5f51022a 948
1341ea0d 949// notify_progress("Loading, please wait...");
9ec58704 950
b4e75b2a
AD
951 new Ajax.Request("backend.php", {
952 parameters: query,
1341ea0d
AD
953 onComplete: function(transport) {
954 all_counters_callback2(transport);
955 } });
5f51022a
AD
956
957 }
958
5f51022a
AD
959 } catch (e) {
960 exception_error("toggleUnread", e);
961 }
962}
963
933ba4ee
AD
964function selectionRemoveLabel(id) {
965 try {
966
967 var ids = getSelectedArticleIds2();
968
969 if (ids.length == 0) {
970 alert(__("No articles are selected."));
971 return;
972 }
973
37843d70 974// var ok = confirm(__("Remove selected articles from label?"));
933ba4ee 975
37843d70 976// if (ok) {
933ba4ee 977
b4e75b2a 978 var query = "?op=rpc&subop=removeFromLabel&ids=" +
933ba4ee
AD
979 param_escape(ids.toString()) + "&lid=" + param_escape(id);
980
981// notify_progress("Loading, please wait...");
982
898e8562
AD
983 cache_invalidate("F:" + (-11 - id));
984
b4e75b2a
AD
985 new Ajax.Request("backend.php", {
986 parameters: query,
933ba4ee 987 onComplete: function(transport) {
1c9c6025
AD
988 show_labels_in_headlines(transport);
989 all_counters_callback2(transport);
933ba4ee
AD
990 } });
991
37843d70 992// }
933ba4ee
AD
993
994 } catch (e) {
995 exception_error("selectionAssignLabel", e);
996
997 }
998}
999
b8a637f3
AD
1000function selectionAssignLabel(id) {
1001 try {
1002
1003 var ids = getSelectedArticleIds2();
1004
1005 if (ids.length == 0) {
1006 alert(__("No articles are selected."));
1007 return;
1008 }
1009
37843d70 1010// var ok = confirm(__("Assign selected articles to label?"));
b8a637f3 1011
37843d70 1012// if (ok) {
b8a637f3 1013
898e8562
AD
1014 cache_invalidate("F:" + (-11 - id));
1015
b4e75b2a 1016 var query = "?op=rpc&subop=assignToLabel&ids=" +
b8a637f3
AD
1017 param_escape(ids.toString()) + "&lid=" + param_escape(id);
1018
1019// notify_progress("Loading, please wait...");
1020
b4e75b2a
AD
1021 new Ajax.Request("backend.php", {
1022 parameters: query,
b8a637f3 1023 onComplete: function(transport) {
f9247195
AD
1024 show_labels_in_headlines(transport);
1025 all_counters_callback2(transport);
b8a637f3
AD
1026 } });
1027
37843d70 1028// }
b8a637f3
AD
1029
1030 } catch (e) {
1031 exception_error("selectionAssignLabel", e);
1032
1033 }
1034}
1035
2228d0e4 1036function selectionToggleUnread(cdm_mode, set_state, callback_func, no_error) {
1572afe5 1037 try {
386cbf27
AD
1038 var rows;
1039
1040 if (cdm_mode) {
1041 rows = cdmGetSelectedArticles();
1042 } else {
1043 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1044 }
1572afe5 1045
2228d0e4 1046 if (rows.length == 0 && !no_error) {
9cc600d1
AD
1047 alert(__("No articles are selected."));
1048 return;
1049 }
1050
1572afe5 1051 for (i = 0; i < rows.length; i++) {
acac8448 1052 var row = $("RROW-" + rows[i]);
f1f2db64
AD
1053 if (row) {
1054 var nc = row.className;
1055 nc = nc.replace("Unread", "");
1056 nc = nc.replace("Selected", "");
1057
a5ae125a
AD
1058 if (set_state == undefined) {
1059 if (row.className.match("Unread")) {
1060 row.className = nc + "Selected";
1061 } else {
1062 row.className = nc + "UnreadSelected";
1063 }
46b84d29
AD
1064 if (db) {
1065 db.execute("UPDATE articles SET unread = NOT unread WHERE id = ?",
1066 [rows[i]]);
1067 }
a5ae125a
AD
1068 }
1069
1070 if (set_state == false) {
f1f2db64 1071 row.className = nc + "Selected";
46b84d29
AD
1072 if (db) {
1073 db.execute("UPDATE articles SET unread = 0 WHERE id = ?",
1074 [rows[i]]);
1075 }
a5ae125a
AD
1076 }
1077
1078 if (set_state == true) {
f1f2db64 1079 row.className = nc + "UnreadSelected";
46b84d29
AD
1080 if (db) {
1081 db.execute("UPDATE articles SET unread = 1 WHERE id = ?",
1082 [rows[i]]);
1083 }
f1f2db64
AD
1084 }
1085 }
1572afe5
AD
1086 }
1087
1088 if (rows.length > 0) {
1089
46b84d29
AD
1090 update_local_feedlist_counters();
1091
b47b5af7
AD
1092 var cmode = "";
1093
1094 if (set_state == undefined) {
1095 cmode = "2";
1096 } else if (set_state == true) {
1097 cmode = "1";
1098 } else if (set_state == false) {
1099 cmode = "0";
1100 }
1101
b4e75b2a
AD
1102 var query = "?op=rpc&subop=catchupSelected" +
1103 "&cmode=" + cmode + "&ids=" + param_escape(rows.toString());
1572afe5 1104
9ec58704
AD
1105 notify_progress("Loading, please wait...");
1106
b4e75b2a
AD
1107 new Ajax.Request("backend.php", {
1108 parameters: query,
1341ea0d
AD
1109 onComplete: function(transport) {
1110 catchup_callback2(transport, callback_func);
1111 } });
1572afe5
AD
1112
1113 }
1114
1115 } catch (e) {
83f043bb 1116 exception_error("selectionToggleUnread", e);
1572afe5
AD
1117 }
1118}
1119
386cbf27 1120function selectionToggleMarked(cdm_mode) {
1572afe5 1121 try {
1572afe5 1122
386cbf27
AD
1123 var rows;
1124
1125 if (cdm_mode) {
1126 rows = cdmGetSelectedArticles();
1127 } else {
1128 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1129 }
1572afe5 1130
9cc600d1
AD
1131 if (rows.length == 0) {
1132 alert(__("No articles are selected."));
1133 return;
1134 }
1135
1572afe5 1136 for (i = 0; i < rows.length; i++) {
f5e0338d 1137 toggleMark(rows[i], true, true);
1572afe5
AD
1138 }
1139
46b84d29
AD
1140 update_local_feedlist_counters();
1141
1572afe5
AD
1142 if (rows.length > 0) {
1143
b4e75b2a 1144 var query = "?op=rpc&subop=markSelected&ids=" +
1572afe5
AD
1145 param_escape(rows.toString()) + "&cmode=2";
1146
2bc2147f
AD
1147 query = query + "&afid=" + getActiveFeedId();
1148
1341ea0d 1149/* if (tagsAreDisplayed()) {
2bc2147f
AD
1150 query = query + "&omode=tl";
1151 } else {
1152 query = query + "&omode=flc";
1341ea0d
AD
1153 } */
1154
1155 query = query + "&omode=lc";
2bc2147f 1156
b4e75b2a
AD
1157 new Ajax.Request("backend.php", {
1158 parameters: query,
1341ea0d
AD
1159 onComplete: function(transport) {
1160 all_counters_callback2(transport);
1161 } });
1572afe5
AD
1162
1163 }
1164
1165 } catch (e) {
83f043bb 1166 exception_error("selectionToggleMarked", e);
1572afe5
AD
1167 }
1168}
1169
e4f4b46f
AD
1170function selectionTogglePublished(cdm_mode) {
1171 try {
e4f4b46f
AD
1172
1173 var rows;
1174
1175 if (cdm_mode) {
1176 rows = cdmGetSelectedArticles();
1177 } else {
1178 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1179 }
1180
1181 if (rows.length == 0) {
1182 alert(__("No articles are selected."));
1183 return;
1184 }
1185
1186 for (i = 0; i < rows.length; i++) {
f5e0338d 1187 togglePub(rows[i], true, true);
e4f4b46f
AD
1188 }
1189
1190 if (rows.length > 0) {
1191
b4e75b2a 1192 var query = "?op=rpc&subop=publishSelected&ids=" +
e4f4b46f
AD
1193 param_escape(rows.toString()) + "&cmode=2";
1194
2bc2147f
AD
1195 query = query + "&afid=" + getActiveFeedId();
1196
1341ea0d 1197/* if (tagsAreDisplayed()) {
2bc2147f
AD
1198 query = query + "&omode=tl";
1199 } else {
1200 query = query + "&omode=flc";
1341ea0d
AD
1201 } */
1202
1203 query = query + "&omode=lc";
2bc2147f 1204
b4e75b2a
AD
1205 new Ajax.Request("backend.php", {
1206 parameters: query,
1341ea0d
AD
1207 onComplete: function(transport) {
1208 all_counters_callback2(transport);
1209 } });
e4f4b46f
AD
1210
1211 }
1212
1213 } catch (e) {
1214 exception_error("selectionToggleMarked", e);
1215 }
1216}
1217
386cbf27
AD
1218function cdmGetSelectedArticles() {
1219 var sel_articles = new Array();
acac8448 1220 var container = $("headlinesInnerContainer");
386cbf27
AD
1221
1222 for (i = 0; i < container.childNodes.length; i++) {
1223 var child = container.childNodes[i];
1224
02895941 1225 if (child.id && child.id.match("RROW-") && child.className.match("Selected")) {
386cbf27
AD
1226 var c_id = child.id.replace("RROW-", "");
1227 sel_articles.push(c_id);
1228 }
1229 }
1230
1231 return sel_articles;
1232}
1233
8be83f42
AD
1234function cdmGetVisibleArticles() {
1235 var sel_articles = new Array();
acac8448 1236 var container = $("headlinesInnerContainer");
8be83f42 1237
3a40e8a2
AD
1238 if (!container) return sel_articles;
1239
8be83f42
AD
1240 for (i = 0; i < container.childNodes.length; i++) {
1241 var child = container.childNodes[i];
1242
02895941 1243 if (child.id && child.id.match("RROW-")) {
8be83f42
AD
1244 var c_id = child.id.replace("RROW-", "");
1245 sel_articles.push(c_id);
1246 }
1247 }
1248
1249 return sel_articles;
1250}
1251
1252function cdmGetUnreadArticles() {
1253 var sel_articles = new Array();
acac8448 1254 var container = $("headlinesInnerContainer");
8be83f42
AD
1255
1256 for (i = 0; i < container.childNodes.length; i++) {
1257 var child = container.childNodes[i];
1258
02895941 1259 if (child.id && child.id.match("RROW-") && child.className.match("Unread")) {
8be83f42
AD
1260 var c_id = child.id.replace("RROW-", "");
1261 sel_articles.push(c_id);
1262 }
1263 }
1264
1265 return sel_articles;
1266}
1267
1268
386cbf27
AD
1269// mode = all,none,unread
1270function cdmSelectArticles(mode) {
acac8448 1271 var container = $("headlinesInnerContainer");
386cbf27
AD
1272
1273 for (i = 0; i < container.childNodes.length; i++) {
1274 var child = container.childNodes[i];
1275
02895941 1276 if (child.id && child.id.match("RROW-")) {
06d1a1c1
AD
1277 var aid = child.id.replace("RROW-", "");
1278
acac8448 1279 var cb = $("RCHK-" + aid);
06d1a1c1 1280
386cbf27
AD
1281 if (mode == "all") {
1282 if (!child.className.match("Selected")) {
1283 child.className = child.className + "Selected";
06d1a1c1 1284 cb.checked = true;
386cbf27
AD
1285 }
1286 } else if (mode == "unread") {
1287 if (child.className.match("Unread") && !child.className.match("Selected")) {
1288 child.className = child.className + "Selected";
06d1a1c1 1289 cb.checked = true;
386cbf27
AD
1290 }
1291 } else {
1292 child.className = child.className.replace("Selected", "");
06d1a1c1 1293 cb.checked = false;
386cbf27
AD
1294 }
1295 }
1296 }
1297}
1298
98bea1b1 1299function catchupPage() {
b47b5af7 1300
3d72bbdb 1301 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
8a5b4579 1302
a5ae125a
AD
1303 var str = __("Mark all visible articles in %s as read?");
1304
1305 str = str.replace("%s", fn);
8a5b4579
AD
1306
1307 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1308 return;
1309 }
1310
acac8448 1311 if ($("headlinesList")) {
b47b5af7 1312 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', true, 'Unread', true);
2228d0e4 1313 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
b47b5af7
AD
1314 selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1315 } else {
1316 cdmSelectArticles('all');
2228d0e4 1317 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
b47b5af7
AD
1318 cdmSelectArticles('none');
1319 }
98bea1b1
AD
1320}
1321
e04c18a2
AD
1322function deleteSelection() {
1323
1324 try {
1325
1326 var rows;
1327
1328 if ($("headlinesList")) {
1329 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1330 } else {
1331 rows = cdmGetSelectedArticles();
1332 }
1333
1334 if (rows.length == 0) {
1335 alert(__("No articles are selected."));
1336 return;
1337 }
1338
1339
1340 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1341 var str;
1342 var op;
1343
1344 if (getActiveFeedId() != 0) {
1345 str = __("Delete %d selected articles in %s?");
1346 } else {
1347 str = __("Delete %d selected articles?");
1348 }
1349
1350 str = str.replace("%d", rows.length);
1351 str = str.replace("%s", fn);
1352
1353 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1354 return;
1355 }
1356
b4e75b2a 1357 query = "?op=rpc&subop=delete&ids=" + param_escape(rows);
e04c18a2
AD
1358
1359 debug(query);
1360
b4e75b2a
AD
1361 new Ajax.Request("backend.php", {
1362 parameters: query,
e04c18a2
AD
1363 onComplete: function(transport) {
1364 viewCurrentFeed();
1365 } });
1366
1367 } catch (e) {
a12eb9c3 1368 exception_error("deleteSelection", e);
e04c18a2
AD
1369 }
1370}
1371
1372function archiveSelection() {
1373
1374 try {
1375
1376 var rows;
1377
1378 if ($("headlinesList")) {
1379 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1380 } else {
1381 rows = cdmGetSelectedArticles();
1382 }
1383
1384 if (rows.length == 0) {
1385 alert(__("No articles are selected."));
1386 return;
1387 }
1388
1389
1390 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
1391 var str;
1392 var op;
1393
1394 if (getActiveFeedId() != 0) {
1395 str = __("Archive %d selected articles in %s?");
1396 op = "archive";
1397 } else {
1398 str = __("Move %d archived articles back?");
1399 op = "unarchive";
1400 }
1401
1402 str = str.replace("%d", rows.length);
1403 str = str.replace("%s", fn);
1404
1405 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1406 return;
1407 }
1408
b4e75b2a 1409 query = "?op=rpc&subop="+op+"&ids=" + param_escape(rows);
e04c18a2
AD
1410
1411 debug(query);
1412
a12eb9c3
AD
1413 for (var i = 0; i < rows.length; i++) {
1414 cache_invalidate(rows[i]);
1415 }
1416
b4e75b2a
AD
1417 new Ajax.Request("backend.php", {
1418 parameters: query,
e04c18a2
AD
1419 onComplete: function(transport) {
1420 viewCurrentFeed();
1421 } });
1422
1423 } catch (e) {
1424 exception_error("archiveSelection", e);
1425 }
1426}
1427
a5ae125a
AD
1428function catchupSelection() {
1429
1430 try {
1431
1432 var rows;
1433
acac8448 1434 if ($("headlinesList")) {
a5ae125a
AD
1435 rows = getSelectedTableRowIds("headlinesList", "RROW", "RCHK");
1436 } else {
1437 rows = cdmGetSelectedArticles();
1438 }
1439
1440 if (rows.length == 0) {
1441 alert(__("No articles are selected."));
1442 return;
1443 }
1444
1445
3d72bbdb 1446 var fn = getFeedName(getActiveFeedId(), activeFeedIsCat());
a5ae125a 1447
ba5fac1b 1448 var str = __("Mark %d selected articles in %s as read?");
a5ae125a 1449
ba5fac1b 1450 str = str.replace("%d", rows.length);
a5ae125a
AD
1451 str = str.replace("%s", fn);
1452
1453 if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) {
1454 return;
1455 }
1456
acac8448 1457 if ($("headlinesList")) {
a5ae125a
AD
1458 selectionToggleUnread(false, false, 'viewCurrentFeed()', true);
1459 // selectTableRowsByIdPrefix('headlinesList', 'RROW-', 'RCHK-', false);
1460 } else {
1461 selectionToggleUnread(true, false, 'viewCurrentFeed()', true)
1462 // cdmSelectArticles('none');
1463 }
1464
1465 } catch (e) {
1466 exception_error("catchupSelection", e);
1467 }
1468}
1469
13f08f75 1470function editArticleTags(id, feed_id, cdm_enabled) {
0b126ac2
AD
1471 displayDlg('editArticleTags', id);
1472}
1473
1474
2ef1af84
AD
1475function tag_saved_callback(transport) {
1476 try {
1477 debug("in tag_saved_callback");
0b126ac2 1478
2ef1af84
AD
1479 closeInfoBox();
1480 notify("");
0b126ac2 1481
2ef1af84
AD
1482 if (tagsAreDisplayed()) {
1483 _reload_feedlist_after_view = true;
1484 }
0b126ac2 1485
307d187c
AD
1486
1487 if (transport.responseXML) {
1488 var tags_str = transport.responseXML.getElementsByTagName("tags-str")[0];
1489
1490 if (tags_str) {
1491 var id = tags_str.getAttribute("id");
1492
1493 if (id) {
acac8448 1494 var tags = $("ATSTR-" + id);
307d187c
AD
1495 if (tags) {
1496 tags.innerHTML = tags_str.firstChild.nodeValue;
1497 }
1498 }
13f08f75 1499 }
0b126ac2 1500 }
2ef1af84
AD
1501
1502 } catch (e) {
307d187c 1503 exception_error("tag_saved_callback", e);
0b126ac2
AD
1504 }
1505}
1506
1507function editTagsSave() {
1508
42c32916 1509 notify_progress("Saving article tags...");
88040f57 1510
0b126ac2
AD
1511 var form = document.forms["tag_edit_form"];
1512
1513 var query = Form.serialize("tag_edit_form");
1514
b4e75b2a 1515 query = "?op=rpc&subop=setArticleTags&" + query;
14b6c54b
AD
1516
1517 debug(query);
1518
b4e75b2a
AD
1519 new Ajax.Request("backend.php", {
1520 parameters: query,
2ef1af84
AD
1521 onComplete: function(transport) {
1522 tag_saved_callback(transport);
1523 } });
0b126ac2
AD
1524
1525}
d62a3b63
AD
1526
1527function editTagsInsert() {
1528 try {
1529
1530 var form = document.forms["tag_edit_form"];
1531
1532 var found_tags = form.found_tags;
1533 var tags_str = form.tags_str;
1534
1535 var tag = found_tags[found_tags.selectedIndex].value;
1536
1537 if (tags_str.value.length > 0 &&
1538 tags_str.value.lastIndexOf(", ") != tags_str.value.length - 2) {
1539
1540 tags_str.value = tags_str.value + ", ";
1541 }
1542
1543 tags_str.value = tags_str.value + tag + ", ";
1544
1545 found_tags.selectedIndex = 0;
1546
1547 } catch (e) {
438f2ce9 1548 exception_error("editTagsInsert", e);
d62a3b63
AD
1549 }
1550}
ba0978c8 1551
587bef10
AD
1552function cdmScrollViewport(where) {
1553 debug("cdmScrollViewport: " + where);
1554
acac8448 1555 var ctr = $("headlinesInnerContainer");
587bef10
AD
1556
1557 if (!ctr) return;
1558
1559 if (where == "bottom") {
1560 ctr.scrollTop = ctr.scrollHeight;
1561 } else {
1562 ctr.scrollTop = where;
1563 }
1564}
1565
b8e6acea
AD
1566function cdmArticleIsBelowViewport(id) {
1567 try {
acac8448
AD
1568 var ctr = $("headlinesInnerContainer");
1569 var e = $("RROW-" + id);
b8e6acea
AD
1570
1571 if (!e || !ctr) return;
1572
1573 // article starts below viewport
1574
1575 if (ctr.scrollTop < e.offsetTop) {
1576 return true;
1577 } else {
1578 return false;
1579 }
1580
1581 } catch (e) {
438f2ce9 1582 exception_error("cdmArticleIsVisible", e);
b8e6acea
AD
1583 }
1584}
1585
1586function cdmArticleIsAboveViewport(id) {
1587 try {
acac8448
AD
1588 var ctr = $("headlinesInnerContainer");
1589 var e = $("RROW-" + id);
b8e6acea
AD
1590
1591 if (!e || !ctr) return;
1592
1593 // article starts above viewport
1594
1595 if (ctr.scrollTop > e.offsetTop + e.offsetHeight) {
1596 return true;
1597 } else {
1598 return false;
1599 }
1600
1601 } catch (e) {
438f2ce9 1602 exception_error("cdmArticleIsVisible", e);
b8e6acea
AD
1603 }
1604}
1605
1606function cdmScrollToArticleId(id) {
1607 try {
acac8448
AD
1608 var ctr = $("headlinesInnerContainer");
1609 var e = $("RROW-" + id);
b8e6acea
AD
1610
1611 if (!e || !ctr) return;
1612
1613 ctr.scrollTop = e.offsetTop;
1614
1615 } catch (e) {
438f2ce9 1616 exception_error("cdmScrollToArticleId", e);
b8e6acea
AD
1617 }
1618}
1619
1620function cdmArticleIsActuallyVisible(id) {
1621 try {
acac8448
AD
1622 var ctr = $("headlinesInnerContainer");
1623 var e = $("RROW-" + id);
b8e6acea
AD
1624
1625 if (!e || !ctr) return;
1626
1627 // article fits in viewport OR article is longer than viewport and
1628 // its bottom is visible
1629
1630 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1631 ctr.scrollTop + ctr.offsetHeight) {
1632
1633 return true;
1634
1635 } else if (e.offsetHeight > ctr.offsetHeight &&
1636 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1637 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1638
1639 return true;
1640
1641 }
1642
1643 return false;
1644
1645 } catch (e) {
438f2ce9 1646 exception_error("cdmArticleIsVisible", e);
b8e6acea
AD
1647 }
1648}
1649
ba0978c8
AD
1650function cdmWatchdog() {
1651
1652 try {
1653
acac8448 1654 var ctr = $("headlinesInnerContainer");
ba0978c8 1655
9acd22e8
AD
1656 if (!ctr) return;
1657
ba0978c8
AD
1658 var ids = new Array();
1659
1660 var e = ctr.firstChild;
1661
1662 while (e) {
1663 if (e.className && e.className == "cdmArticleUnread" && e.id &&
1664 e.id.match("RROW-")) {
1665
1666 // article fits in viewport OR article is longer than viewport and
1667 // its bottom is visible
1668
1669 if (ctr.scrollTop <= e.offsetTop && e.offsetTop + e.offsetHeight <=
1670 ctr.scrollTop + ctr.offsetHeight) {
1671
1672// debug(e.id + " is visible " + e.offsetTop + "." +
1673// (e.offsetTop + e.offsetHeight) + " vs " + ctr.scrollTop + "." +
1674// (ctr.scrollTop + ctr.offsetHeight));
1675
1676 ids.push(e.id.replace("RROW-", ""));
1677
1678 } else if (e.offsetHeight > ctr.offsetHeight &&
1679 e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1680 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight) {
1681
1682 ids.push(e.id.replace("RROW-", ""));
1683
1684 }
1685
c50e2b30
AD
1686 // method 2: article bottom is visible and is in upper 1/2 of the viewport
1687
1688/* if (e.offsetTop + e.offsetHeight >= ctr.scrollTop &&
1689 e.offsetTop + e.offsetHeight <= ctr.scrollTop + ctr.offsetHeight/2) {
1690
1691 ids.push(e.id.replace("RROW-", ""));
1692
1693 } */
1694
ba0978c8
AD
1695 }
1696
1697 e = e.nextSibling;
1698 }
1699
1700 debug("cdmWatchdog, ids= " + ids.toString());
1701
1341ea0d 1702 if (ids.length > 0) {
ba0978c8
AD
1703
1704 for (var i = 0; i < ids.length; i++) {
acac8448 1705 var e = $("RROW-" + ids[i]);
ba0978c8
AD
1706 if (e) {
1707 e.className = e.className.replace("Unread", "");
1708 }
1709 }
1710
b4e75b2a
AD
1711 var query = "?op=rpc&subop=catchupSelected" +
1712 "&cmode=0" + "&ids=" + param_escape(ids.toString());
ba0978c8 1713
b4e75b2a
AD
1714 new Ajax.Request("backend.php", {
1715 parameters: query,
1341ea0d
AD
1716 onComplete: function(transport) {
1717 all_counters_callback2(transport);
1718 } });
ba0978c8
AD
1719
1720 }
1721
c50e2b30 1722 _cdm_wd_timeout = window.setTimeout("cdmWatchdog()", 4000);
ba0978c8
AD
1723
1724 } catch (e) {
438f2ce9 1725 exception_error("cdmWatchdog", e);
ba0978c8
AD
1726 }
1727
1728}
e097e8be
AD
1729
1730
e19c1824 1731function cache_inject(id, article, param) {
fb456d28
AD
1732 try {
1733 if (!cache_check_param(id, param)) {
1734 debug("cache_article: miss: " + id + " [p=" + param + "]");
1735
1736
1737 if (db) {
e097e8be 1738
fb456d28
AD
1739 var date = new Date();
1740 var ts = Math.round(date.getTime() / 1000);
e097e8be 1741
fb456d28
AD
1742 db.execute("INSERT INTO cache (id, article, param, added) VALUES (?, ?, ?, ?)",
1743 [id, article, param, ts]);
1744 } else {
1745
1746 var cache_obj = new Array();
1747
1748 cache_obj["id"] = id;
1749 cache_obj["data"] = article;
1750 cache_obj["param"] = param;
1751
1752 article_cache.push(cache_obj);
1753 }
1754
1755 } else {
1756 debug("cache_article: hit: " + id + " [p=" + param + "]");
1757 }
1758 } catch (e) {
1759 exception_error("cache_inject", e);
e097e8be
AD
1760 }
1761}
1762
1763function cache_find(id) {
fb456d28
AD
1764
1765 if (db) {
31234407 1766 var rs = db.execute("SELECT article FROM cache WHERE id = ?", [id]);
03c96380 1767 var a = false;
31234407
AD
1768
1769 if (rs.isValidRow()) {
03c96380 1770 var a = rs.field(0);
31234407 1771 }
fb456d28 1772
03c96380
AD
1773 rs.close();
1774
1775 return a;
1776
fb456d28
AD
1777 } else {
1778 for (var i = 0; i < article_cache.length; i++) {
1779 if (article_cache[i]["id"] == id) {
1780 return article_cache[i]["data"];
1781 }
fed4387d 1782 }
e097e8be 1783 }
fed4387d 1784 return false;
e097e8be
AD
1785}
1786
5d17ead9 1787function cache_find_param(id, param) {
fb456d28
AD
1788
1789 if (db) {
1790 var rs = db.execute("SELECT article FROM cache WHERE id = ? AND param = ?",
1791 [id, param]);
03c96380 1792 var a = false;
fb456d28
AD
1793
1794 if (rs.isValidRow()) {
03c96380 1795 a = rs.field(0);
fb456d28
AD
1796 }
1797
03c96380
AD
1798 rs.close();
1799
1800 return a;
1801
fb456d28
AD
1802 } else {
1803 for (var i = 0; i < article_cache.length; i++) {
1804 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1805 return article_cache[i]["data"];
1806 }
e19c1824
AD
1807 }
1808 }
1809 return false;
1810}
1811
e097e8be 1812function cache_check(id) {
fb456d28
AD
1813
1814 if (db) {
1815 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ?",
1816 [id]);
03c96380 1817 var a = false;
fb456d28
AD
1818
1819 if (rs.isValidRow()) {
03c96380 1820 a = rs.field(0) != "0";
fb456d28
AD
1821 }
1822
03c96380
AD
1823 rs.close();
1824
1825 return a;
1826
fb456d28
AD
1827 } else {
1828 for (var i = 0; i < article_cache.length; i++) {
1829 if (article_cache[i]["id"] == id) {
1830 return true;
1831 }
fed4387d
AD
1832 }
1833 }
1834 return false;
e097e8be
AD
1835}
1836
e19c1824 1837function cache_check_param(id, param) {
5d17ead9 1838
fb456d28
AD
1839 if (db) {
1840 var rs = db.execute("SELECT COUNT(*) AS c FROM cache WHERE id = ? AND param = ?",
1841 [id, param]);
03c96380 1842 var a = false;
5d17ead9 1843
fb456d28 1844 if (rs.isValidRow()) {
03c96380 1845 a = rs.field(0) != "0";
fb456d28
AD
1846 }
1847
03c96380
AD
1848 rs.close();
1849
1850 return a;
1851
fb456d28
AD
1852 } else {
1853 for (var i = 0; i < article_cache.length; i++) {
1854 if (article_cache[i]["id"] == id && article_cache[i]["param"] == param) {
1855 return true;
1856 }
e19c1824
AD
1857 }
1858 }
1859 return false;
1860}
1861
e097e8be 1862function cache_expire() {
31234407
AD
1863 if (db) {
1864 var date = new Date();
1865 var ts = Math.round(date.getTime() / 1000);
1866
e0999d95
AD
1867 db.execute("DELETE FROM cache WHERE added < ? - 1800 AND id LIKE 'FEEDLIST'", [ts]);
1868 db.execute("DELETE FROM cache WHERE added < ? - 600 AND (id LIKE 'F:%' OR id LIKE 'C:%')", [ts]);
1869 db.execute("DELETE FROM cache WHERE added < ? - 86400", [ts]);
1870
31234407
AD
1871
1872 } else {
fb456d28
AD
1873 while (article_cache.length > 25) {
1874 article_cache.shift();
1875 }
fed4387d 1876 }
e097e8be 1877}
b07b61da 1878
3c2d7945
AD
1879function cache_empty() {
1880 article_cache = new Array();
1881}
1882
b07b61da 1883function cache_invalidate(id) {
c1b18749
AD
1884 try {
1885
fb456d28
AD
1886 if (db) {
1887 rs = db.execute("DELETE FROM cache WHERE id = ?", [id]);
1888 return rs.rowsAffected != 0;
1889 } else {
1890
1891 var i = 0
1892
1893 while (i < article_cache.length) {
1894 if (article_cache[i]["id"] == id) {
1895 debug("cache_invalidate: removed id " + id);
1896 article_cache.splice(i, 1);
1897 return true;
1898 }
1899 i++;
c1b18749 1900 }
b07b61da 1901 }
fb456d28 1902
c1b18749
AD
1903 debug("cache_invalidate: id not found: " + id);
1904 return false;
1905 } catch (e) {
1906 exception_error("cache_invalidate", e);
b07b61da 1907 }
b07b61da 1908}
298f3f78
AD
1909
1910function getActiveArticleId() {
1911 return active_post_id;
1912}
e4914b62 1913
3cd4239a 1914function cdmClicked(id) {
e4914b62 1915 try {
acac8448 1916 var elem = $("RROW-" + id);
3cd4239a
AD
1917
1918 if (elem) {
e4914b62
AD
1919 var id = elem.id.replace("RROW-", "");
1920 active_post_id = id;
5ad9d132 1921
96f8322d 1922// cdmSelectArticles("none");
b61cf20c 1923 toggleUnread(id, 0, true);
96f8322d 1924// toggleSelected(id);
5ad9d132 1925
e4914b62
AD
1926 }
1927 } catch (e) {
ee8768db 1928 exception_error("cdmClicked", e);
5ad9d132
AD
1929 }
1930}
e4914b62 1931
aa0fa9df
AD
1932function preload_article_callback(transport) {
1933 try {
1934 if (transport.responseXML) {
1935 var articles = transport.responseXML.getElementsByTagName("article");
1936
1937 for (var i = 0; i < articles.length; i++) {
1938 var id = articles[i].getAttribute("id");
b2bb787c 1939 if (!cache_check(id)) {
aa0fa9df
AD
1940 cache_inject(id, articles[i].firstChild.nodeValue);
1941 debug("preloaded article: " + id);
1942 }
1943 }
1944 }
1945 } catch (e) {
1946 exception_error("preload_article_callback", e);
1947 }
1948}
1949
1950function preloadArticleUnderPointer(id) {
1951 try {
a598370d
AD
1952 if (getInitParam("bw_limit") == "1") return;
1953
b2bb787c 1954 if (post_under_pointer == id && !cache_check(id)) {
aa0fa9df
AD
1955
1956 debug("trying to preload article " + id);
1957
1958 var neighbor_ids = getRelativePostIds(id, 1);
1959
1960 /* only request uncached articles */
1961
1962 var cids_to_request = Array();
1963
1964 for (var i = 0; i < neighbor_ids.length; i++) {
1965 if (!cache_check(neighbor_ids[i])) {
1966 cids_to_request.push(neighbor_ids[i]);
1967 }
1968 }
1969 debug("additional ids: " + cids_to_request.toString());
1970
1971 cids_to_request.push(id);
1972
b4e75b2a 1973 var query = "?op=rpc&subop=getArticles&ids=" +
aa0fa9df 1974 cids_to_request.toString();
b4e75b2a
AD
1975
1976 new Ajax.Request("backend.php", {
1977 parameters: query,
aa0fa9df
AD
1978 onComplete: function(transport) {
1979 preload_article_callback(transport);
1980 } });
1981 }
1982 } catch (e) {
1983 exception_error("preloadArticleUnderPointer", e);
1984 }
1985}
1986
314fcd2b
AD
1987function postMouseIn(id) {
1988 try {
aa0fa9df
AD
1989 if (post_under_pointer != id) {
1990 post_under_pointer = id;
1991 if (!isCdmMode()) {
1992 window.setTimeout("preloadArticleUnderPointer(" + id + ")", 250);
1993 }
1994 }
1995
314fcd2b
AD
1996 } catch (e) {
1997 exception_error("postMouseIn", e);
1998 }
1999}
2000
2001function postMouseOut(id) {
2002 try {
2003 post_under_pointer = false;
2004 } catch (e) {
2005 exception_error("postMouseOut", e);
2006 }
2007}
2008
ac541432
AD
2009function headlines_scroll_handler() {
2010 try {
2011
acac8448 2012 var e = $("headlinesInnerContainer");
ac541432 2013
4764c27e
AD
2014 var toolbar_form = document.forms["main_toolbar_form"];
2015
6f068202
AD
2016 debug((e.scrollTop + e.offsetHeight) + " vs " + e.scrollHeight + " dis? " +
2017 _infscroll_disable);
587bef10 2018
6f068202
AD
2019 if (e.scrollTop + e.offsetHeight > e.scrollHeight - 100) {
2020 if (!_infscroll_disable) {
2021 debug("more cowbell!");
2022 viewNextFeedPage();
29dfb258 2023 }
ac541432
AD
2024 }
2025
2026 } catch (e) {
2027 exception_error("headlines_scroll_handler", e);
2028 }
2029}
8be83f42
AD
2030
2031function catchupRelativeToArticle(below) {
2032
2033 try {
2034
49fd1e94 2035
8be83f42
AD
2036 if (!getActiveArticleId()) {
2037 alert(__("No article is selected."));
2038 return;
2039 }
2040
2041 var visible_ids;
2042
acac8448 2043 if ($("headlinesList")) {
8be83f42
AD
2044 visible_ids = getVisibleHeadlineIds();
2045 } else {
2046 visible_ids = cdmGetVisibleArticles();
2047 }
2048
2049 var ids_to_mark = new Array();
2050
2051 if (!below) {
2052 for (var i = 0; i < visible_ids.length; i++) {
2053 if (visible_ids[i] != getActiveArticleId()) {
acac8448 2054 var e = $("RROW-" + visible_ids[i]);
8be83f42
AD
2055
2056 if (e && e.className.match("Unread")) {
2057 ids_to_mark.push(visible_ids[i]);
2058 }
2059 } else {
2060 break;
2061 }
2062 }
2063 } else {
2064 for (var i = visible_ids.length-1; i >= 0; i--) {
2065 if (visible_ids[i] != getActiveArticleId()) {
acac8448 2066 var e = $("RROW-" + visible_ids[i]);
8be83f42
AD
2067
2068 if (e && e.className.match("Unread")) {
2069 ids_to_mark.push(visible_ids[i]);
2070 }
2071 } else {
2072 break;
2073 }
2074 }
2075 }
2076
2077 if (ids_to_mark.length == 0) {
2078 alert(__("No articles found to mark"));
2079 } else {
2080 var msg = __("Mark %d article(s) as read?").replace("%d", ids_to_mark.length);
2081
2082 if (confirm(msg)) {
2083
2084 for (var i = 0; i < ids_to_mark.length; i++) {
acac8448 2085 var e = $("RROW-" + ids_to_mark[i]);
8be83f42
AD
2086 e.className = e.className.replace("Unread", "");
2087 }
2088
b4e75b2a
AD
2089 var query = "?op=rpc&subop=catchupSelected" +
2090 "&cmode=0" + "&ids=" + param_escape(ids_to_mark.toString());
8be83f42 2091
b4e75b2a
AD
2092 new Ajax.Request("backend.php", {
2093 parameters: query,
5fe7767c
AD
2094 onComplete: function(transport) {
2095 catchup_callback2(transport);
2096 } });
2097
8be83f42
AD
2098 }
2099 }
2100
2101 } catch (e) {
2102 exception_error("catchupRelativeToArticle", e);
2103 }
2104}
a04c8e8d
AD
2105
2106function cdmExpandArticle(a_id) {
2107 try {
2108 var id = 'CICD-' + a_id;
2109
3cd4239a
AD
2110 try {
2111 Element.hide("CEXC-" + a_id);
2112 } catch (e) { }
2113
a04c8e8d
AD
2114 Effect.Appear(id, {duration : 0.5,
2115 beforeStart: function(effect) {
2116 var h_id = 'CICH-' + a_id;
acac8448 2117 var h_elem = $(h_id);
a04c8e8d
AD
2118 if (h_elem) { h_elem.style.display = "none"; }
2119
2120 toggleUnread(a_id, 0);
2121 }});
2122
2123
2124 } catch (e) {
2125 exception_error("appearBlockElementF", e);
2126 }
2127
2128}
2129
3818a89b
AD
2130function fixHeadlinesOrder(ids) {
2131 try {
2132 for (var i = 0; i < ids.length; i++) {
acac8448 2133 var e = $("RROW-" + ids[i]);
3818a89b
AD
2134
2135 if (e) {
2136 if (i % 2 == 0) {
2137 e.className = e.className.replace("even", "odd");
2138 } else {
2139 e.className = e.className.replace("odd", "even");
2140 }
2141 }
2142 }
2143 } catch (e) {
2144 exception_error("fixHeadlinesOrder", e);
2145 }
2146}
2147
df485d4f
AD
2148function hideReadHeadlines() {
2149 try {
2150
2151 var ids = false;
2152 var vis_ids = new Array();
2153
acac8448 2154 if ($("headlinesList")) {
df485d4f
AD
2155 ids = getVisibleHeadlineIds();
2156 } else {
2157 ids = cdmGetVisibleArticles();
2158 }
2159
004523dd
AD
2160 var read_headlines_visible = true;
2161
df485d4f 2162 for (var i = 0; i < ids.length; i++) {
acac8448 2163 var row = $("RROW-" + ids[i]);
df485d4f
AD
2164
2165 if (row && row.className) {
2166 if (read_headlines_visible) {
2167 if (row.className.match("Unread") || row.className.match("Selected")) {
2168 Element.show(row);
2169 vis_ids.push(ids[i]);
2170 } else {
2171 //Effect.Fade(row, {duration : 0.3});
2172 Element.hide(row);
2173 }
2174 } else {
2175 Element.show(row);
2176 vis_ids.push(ids[i]);
2177 }
2178 }
2179 }
2180
2181 fixHeadlinesOrder(vis_ids);
2182
2183 read_headlines_visible = !read_headlines_visible;
2184
2185 } catch (e) {
2186 exception_error("hideReadHeadlines", e);
2187 }
2188}
2189
e75d70b5
AD
2190function invertHeadlineSelection() {
2191 try {
2192 var rows = new Array();
2193 var r = false;
2194
2195 if (!isCdmMode()) {
2196 r = document.getElementsByTagName("TR");
2197 } else {
2198 r = document.getElementsByTagName("DIV");
2199 }
2200
2201 for (var i = 0; i < r.length; i++) {
2202 if (r[i].id && r[i].id.match("RROW-")) {
2203 rows.push(r[i]);
2204 }
2205 }
2206
2207 for (var i = 0; i < rows.length; i++) {
2208 var nc = rows[i].className;
2209 var id = rows[i].id.replace("RROW-", "");
acac8448 2210 var cb = $("RCHK-" + id);
e75d70b5
AD
2211
2212 if (!rows[i].className.match("Selected")) {
2213 nc = nc + "Selected";
2214 cb.checked = true;
2215 } else {
2216 nc = nc.replace("Selected", "");
2217 cb.checked = false;
2218 }
2219
2220 rows[i].className = nc;
2221
2222 }
2223
2224 } catch (e) {
2225 exception_error("invertHeadlineSelection", e);
2226 }
2227}
2228
314fcd2b
AD
2229function getArticleUnderPointer() {
2230 return post_under_pointer;
7a822893 2231}
eedfb635
AD
2232
2233function zoomToArticle(id) {
2234 try {
2235 var w = window.open("backend.php?op=view&mode=zoom&id=" + param_escape(id),
2236 "ttrss_zoom_" + id,
2237 "status=0,toolbar=0,location=0,width=450,height=300,scrollbars=1,menubar=0");
2238
2239 } catch (e) {
2240 exception_error("zoomToArticle", e);
2241 }
2242}
a411875b 2243
4710e3dc
AD
2244function showOriginalArticleInline(id) {
2245 try {
2246
b4e75b2a 2247 var query = "?op=rpc&subop=getArticleLink&id=" + id;
4710e3dc
AD
2248
2249 notify_progress("Loading, please wait...", true);
2250
b4e75b2a
AD
2251 new Ajax.Request("backend.php", {
2252 parameters: query,
4710e3dc
AD
2253 onComplete: function(transport) {
2254
2255 if (transport.responseXML) {
2256
2257 var link = transport.responseXML.getElementsByTagName("link")[0];
2258 var id = transport.responseXML.getElementsByTagName("id")[0];
2259
2260 notify("");
2261
2262 if (link && id) {
2263 link = link.firstChild.nodeValue;
2264
acac8448 2265 var ci = $("content-insert");
4710e3dc
AD
2266
2267 var tmp = "<iframe id=\"inline_orig_article\" width=\""+ci.offsetWidth+"\" height=\""+ci.offsetHeight+"\" style=\"border-width : 0px;\" src=\""+link+"\"></iframe>";
2268
2269 render_article(tmp);
2270
2271 }
2272 }
2273 } });
2274
2275 } catch (e) {
2276 exception_error("showOriginalArticleInline", e);
2277 }
2278}
2279
2280
a411875b
AD
2281function scrollArticle(offset) {
2282 try {
2283 if (!isCdmMode()) {
acac8448 2284 var ci = $("content-insert");
a411875b
AD
2285 if (ci) {
2286 ci.scrollTop += offset;
2287 }
2288 } else {
acac8448 2289 var hi = $("headlinesInnerContainer");
a411875b
AD
2290 if (hi) {
2291 hi.scrollTop += offset;
2292 }
2293
2294 }
2295 } catch (e) {
2296 exception_error("scrollArticle", e);
2297 }
2298}
f9247195
AD
2299
2300function show_labels_in_headlines(transport) {
2301 try {
2302 if (transport.responseXML) {
2303 var info = transport.responseXML.getElementsByTagName("info-for-headlines")[0];
2304
2305 var elems = info.getElementsByTagName("entry");
2306
2307 for (var l = 0; l < elems.length; l++) {
2308 var e_id = elems[l].getAttribute("id");
2309
2310 if (e_id) {
2311
acac8448 2312 var ctr = $("HLLCTR-" + e_id);
f9247195
AD
2313
2314 if (ctr) {
2315 ctr.innerHTML = elems[l].firstChild.nodeValue;
2316 }
2317 }
2318
2319 }
2320
2321 }
2322 } catch (e) {
2323 exception_error("show_labels_in_headlines", e);
2324
2325 }
2326}
bf3c9838
AD
2327
2328function toggleHeadlineActions() {
2329 try {
acac8448
AD
2330 var e = $("headlineActionsBody");
2331 var p = $("headlineActionsDrop");
bf3c9838
AD
2332
2333 if (!Element.visible(e)) {
2334 Element.show(e);
2335 } else {
2336 Element.hide(e);
2337 }
2338
b62f6ff4 2339 e.scrollTop = 0;
bf3c9838 2340 e.style.left = (p.offsetLeft + 1) + "px";
b4dc02e2 2341 e.style.top = (p.offsetTop + p.offsetHeight + 2) + "px";
bf3c9838
AD
2342
2343 } catch (e) {
2344 exception_error("toggleHeadlineActions", e);
2345 }
2346}
c7e51de1
AD
2347
2348function publishWithNote(id, def_note) {
2349 try {
2350 if (!def_note) def_note = '';
2351
2352 var note = prompt(__("Please enter a note for this article:"), def_note);
2353
2354 if (note != undefined) {
2355 togglePub(id, false, false, note);
2356 }
2357
2358 } catch (e) {
2359 exception_error("publishWithNote", e);
2360 }
2361}