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