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