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