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