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