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