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