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