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