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