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