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