]>
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_timeout_id = false; | |
12 | ||
13 | var cids_requested = []; | |
14 | var loaded_article_ids = []; | |
15 | var _last_headlines_update = 0; | |
16 | ||
17 | var has_storage = 'sessionStorage' in window && window['sessionStorage'] !== null; | |
18 | ||
19 | function headlines_callback2(transport, offset, background, infscroll_req) { | |
20 | try { | |
21 | handle_rpc_json(transport); | |
22 | ||
23 | console.log("headlines_callback2 [offset=" + offset + "] B:" + background + " I:" + infscroll_req); | |
24 | ||
25 | var is_cat = false; | |
26 | var feed_id = false; | |
27 | ||
28 | var reply = false; | |
29 | ||
30 | try { | |
31 | reply = JSON.parse(transport.responseText); | |
32 | } catch (e) { | |
33 | console.error(e); | |
34 | } | |
35 | ||
36 | if (reply) { | |
37 | ||
38 | is_cat = reply['headlines']['is_cat']; | |
39 | feed_id = reply['headlines']['id']; | |
40 | ||
41 | if (background) { | |
42 | var content = reply['headlines']['content']; | |
43 | ||
44 | content = content + "<div id='headlines-spacer'></div>"; | |
45 | return; | |
46 | } | |
47 | ||
48 | if (feed_id != getActiveFeedId() || is_cat != activeFeedIsCat()) | |
49 | return; | |
50 | ||
51 | /* dijit.getEnclosingWidget( | |
52 | document.forms["main_toolbar_form"].update).attr('disabled', | |
53 | is_cat || feed_id <= 0); */ | |
54 | ||
55 | try { | |
56 | if (infscroll_req == false) { | |
57 | $("headlines-frame").scrollTop = 0; | |
58 | ||
59 | Element.hide("floatingTitle"); | |
60 | $("floatingTitle").setAttribute("rowid", 0); | |
61 | $("floatingTitle").innerHTML = ""; | |
62 | } | |
63 | } catch (e) { }; | |
64 | ||
65 | $("headlines-frame").removeClassName("cdm"); | |
66 | $("headlines-frame").removeClassName("normal"); | |
67 | ||
68 | $("headlines-frame").addClassName(isCdmMode() ? "cdm" : "normal"); | |
69 | ||
70 | var headlines_count = reply['headlines-info']['count']; | |
71 | ||
72 | vgroup_last_feed = reply['headlines-info']['vgroup_last_feed']; | |
73 | ||
74 | if (parseInt(headlines_count) < 30) { | |
75 | _infscroll_disable = 1; | |
76 | } else { | |
77 | _infscroll_disable = 0; | |
78 | } | |
79 | ||
80 | var counters = reply['counters']; | |
81 | var articles = reply['articles']; | |
82 | //var runtime_info = reply['runtime-info']; | |
83 | ||
84 | if (infscroll_req == false) { | |
85 | loaded_article_ids = []; | |
86 | ||
87 | dijit.byId("headlines-frame").attr('content', | |
88 | reply['headlines']['content']); | |
89 | ||
90 | //dijit.byId("headlines-toolbar").attr('content', | |
91 | // reply['headlines']['toolbar']); | |
92 | ||
93 | dojo.html.set($("headlines-toolbar"), | |
94 | reply['headlines']['toolbar'], | |
95 | {parseContent: true}); | |
96 | ||
97 | $$("#headlines-frame > div[id*=RROW]").each(function(row) { | |
98 | if (loaded_article_ids.indexOf(row.id) != -1) { | |
99 | row.parentNode.removeChild(row); | |
100 | } else { | |
101 | loaded_article_ids.push(row.id); | |
102 | } | |
103 | }); | |
104 | ||
105 | var hsp = $("headlines-spacer"); | |
106 | if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); | |
107 | dijit.byId('headlines-frame').domNode.appendChild(hsp); | |
108 | ||
109 | initHeadlinesMenu(); | |
110 | ||
111 | if (_search_query) { | |
112 | $("feed_title").innerHTML += "<span id='cancel_search'>" + | |
113 | " (<a href='#' onclick='cancelSearch()'>" + __("Cancel search") + "</a>)" + | |
114 | "</span>"; | |
115 | } | |
116 | ||
117 | } else { | |
118 | ||
119 | if (headlines_count > 0 && feed_id == getActiveFeedId() && is_cat == activeFeedIsCat()) { | |
120 | console.log("adding some more headlines: " + headlines_count); | |
121 | ||
122 | var c = dijit.byId("headlines-frame"); | |
123 | var ids = getSelectedArticleIds2(); | |
124 | var new_elems = []; | |
125 | ||
126 | $("headlines-tmp").innerHTML = reply['headlines']['content']; | |
127 | ||
128 | var hsp = $("headlines-spacer"); | |
129 | ||
130 | if (hsp) | |
131 | c.domNode.removeChild(hsp); | |
132 | ||
133 | $$("#headlines-tmp > div").each(function(row) { | |
134 | if (row.className == 'cdmFeedTitle') { | |
135 | row.style.display = 'none'; | |
136 | c.domNode.appendChild(row); | |
137 | new_elems.push(row); | |
138 | } else if (loaded_article_ids.indexOf(row.id) == -1) { | |
139 | row.style.display = 'none'; | |
140 | c.domNode.appendChild(row); | |
141 | new_elems.push(row); | |
142 | loaded_article_ids.push(row.id); | |
143 | } else { | |
144 | row.parentNode.removeChild(row); | |
145 | } | |
146 | }); | |
147 | ||
148 | if (!hsp) hsp = new Element("DIV", {"id": "headlines-spacer"}); | |
149 | ||
150 | if (getInitParam("cdm_auto_catchup") == 1) { | |
151 | c.domNode.appendChild(hsp); | |
152 | } | |
153 | ||
154 | console.log("added " + new_elems.size() + " headlines"); | |
155 | ||
156 | if (new_elems.size() == 0) | |
157 | _infscroll_disable = true; | |
158 | ||
159 | console.log("restore selected ids: " + ids); | |
160 | ||
161 | for (var i = 0; i < ids.length; i++) { | |
162 | markHeadline(ids[i]); | |
163 | } | |
164 | ||
165 | initHeadlinesMenu(); | |
166 | ||
167 | new_elems.each(function(child) { | |
168 | dojo.parser.parse(child); | |
169 | ||
170 | if (!Element.visible(child)) | |
171 | new Effect.Appear(child, { duration : 0.5 }); | |
172 | }); | |
173 | ||
174 | } else { | |
175 | console.log("no new headlines received"); | |
176 | ||
177 | var hsp = $("headlines-spacer"); | |
178 | ||
179 | if (hsp) hsp.innerHTML = ""; | |
180 | } | |
181 | } | |
182 | ||
183 | if (articles) { | |
184 | for (var i = 0; i < articles.length; i++) { | |
185 | var a_id = articles[i]['id']; | |
186 | cache_set("article:" + a_id, articles[i]['content']); | |
187 | } | |
188 | } else { | |
189 | console.log("no cached articles received"); | |
190 | } | |
191 | ||
192 | if (counters) | |
193 | parse_counters(counters); | |
194 | else | |
195 | request_counters(true); | |
196 | ||
197 | } else { | |
198 | console.error("Invalid object received: " + transport.responseText); | |
199 | dijit.byId("headlines-frame").attr('content', "<div class='whiteBox'>" + | |
200 | __('Could not update headlines (invalid object received - see error console for details)') + | |
201 | "</div>"); | |
202 | } | |
203 | ||
204 | _infscroll_request_sent = 0; | |
205 | _last_headlines_update = new Date().getTime(); | |
206 | ||
207 | unpackVisibleHeadlines(); | |
208 | ||
209 | // if we have some more space in the buffer, why not try to fill it | |
210 | ||
211 | if (!_infscroll_disable && $("headlines-spacer") && | |
212 | $("headlines-spacer").offsetTop < $("headlines-frame").offsetHeight) { | |
213 | ||
214 | window.setTimeout(function() { | |
215 | loadMoreHeadlines(); | |
216 | }, 250); | |
217 | } | |
218 | ||
219 | notify(""); | |
220 | ||
221 | } catch (e) { | |
222 | exception_error("headlines_callback2", e, transport); | |
223 | } | |
224 | } | |
225 | ||
226 | function render_article(article) { | |
227 | try { | |
228 | dijit.byId("headlines-wrap-inner").addChild( | |
229 | dijit.byId("content-insert")); | |
230 | ||
231 | var c = dijit.byId("content-insert"); | |
232 | ||
233 | try { | |
234 | c.domNode.scrollTop = 0; | |
235 | } catch (e) { }; | |
236 | ||
237 | PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED, article); | |
238 | ||
239 | c.attr('content', article); | |
240 | ||
241 | correctHeadlinesOffset(getActiveArticleId()); | |
242 | ||
243 | try { | |
244 | c.focus(); | |
245 | } catch (e) { }; | |
246 | ||
247 | } catch (e) { | |
248 | exception_error("render_article", e); | |
249 | } | |
250 | } | |
251 | ||
252 | function showArticleInHeadlines(id, noexpand) { | |
253 | ||
254 | try { | |
255 | selectArticles("none"); | |
256 | ||
257 | var crow = $("RROW-" + id); | |
258 | ||
259 | if (!crow) return; | |
260 | ||
261 | var article_is_unread = crow.hasClassName("Unread"); | |
262 | ||
263 | if (!noexpand) | |
264 | crow.removeClassName("Unread"); | |
265 | crow.addClassName("active"); | |
266 | ||
267 | selectArticles('none'); | |
268 | ||
269 | var view_mode = false; | |
270 | ||
271 | try { | |
272 | view_mode = document.forms['main_toolbar_form'].view_mode; | |
273 | view_mode = view_mode[view_mode.selectedIndex].value; | |
274 | } catch (e) { | |
275 | // | |
276 | } | |
277 | ||
278 | markHeadline(id); | |
279 | ||
280 | if (article_is_unread && !noexpand) | |
281 | _force_scheduled_update = true; | |
282 | ||
283 | } catch (e) { | |
284 | exception_error("showArticleInHeadlines", e); | |
285 | } | |
286 | } | |
287 | ||
288 | function article_callback2(transport, id) { | |
289 | try { | |
290 | console.log("article_callback2 " + id); | |
291 | ||
292 | handle_rpc_json(transport); | |
293 | ||
294 | var reply = false; | |
295 | ||
296 | try { | |
297 | reply = JSON.parse(transport.responseText); | |
298 | } catch (e) { | |
299 | console.error(e); | |
300 | } | |
301 | ||
302 | if (reply) { | |
303 | ||
304 | reply.each(function(article) { | |
305 | if (getActiveArticleId() == article['id']) { | |
306 | render_article(article['content']); | |
307 | } | |
308 | cids_requested.remove(article['id']); | |
309 | ||
310 | cache_set("article:" + article['id'], article['content']); | |
311 | }); | |
312 | ||
313 | // if (id != last_requested_article) { | |
314 | // console.log("requested article id is out of sequence, aborting"); | |
315 | // return; | |
316 | // } | |
317 | ||
318 | } else { | |
319 | console.error("Invalid object received: " + transport.responseText); | |
320 | ||
321 | render_article("<div class='whiteBox'>" + | |
322 | __('Could not display article (invalid object received - see error console for details)') + "</div>"); | |
323 | } | |
324 | ||
325 | var unread_in_buffer = $$("#headlines-frame > div[id*=RROW][class*=Unread]").length | |
326 | request_counters(unread_in_buffer == 0); | |
327 | ||
328 | //headlines_scroll_handler($("headlines-frame")); | |
329 | ||
330 | /* try { | |
331 | if (!_infscroll_disable && | |
332 | $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) { | |
333 | ||
334 | loadMoreHeadlines(); | |
335 | } | |
336 | } catch (e) { | |
337 | console.warn(e); | |
338 | } */ | |
339 | ||
340 | notify(""); | |
341 | } catch (e) { | |
342 | exception_error("article_callback2", e, transport); | |
343 | } | |
344 | } | |
345 | ||
346 | function view(id, activefeed, noexpand) { | |
347 | try { | |
348 | var oldrow = $("RROW-" + getActiveArticleId()); | |
349 | if (oldrow) oldrow.removeClassName("active"); | |
350 | ||
351 | var crow = $("RROW-" + id); | |
352 | ||
353 | if (!crow) return; | |
354 | if (noexpand) { | |
355 | setActiveArticleId(id); | |
356 | showArticleInHeadlines(id, noexpand); | |
357 | return; | |
358 | } | |
359 | ||
360 | console.log("loading article: " + id); | |
361 | ||
362 | var cached_article = cache_get("article:" + id); | |
363 | ||
364 | console.log("cache check result: " + (cached_article != false)); | |
365 | ||
366 | var query = "?op=article&method=view&id=" + param_escape(id); | |
367 | ||
368 | var neighbor_ids = getRelativePostIds(id); | |
369 | ||
370 | /* only request uncached articles */ | |
371 | ||
372 | var cids_to_request = []; | |
373 | ||
374 | for (var i = 0; i < neighbor_ids.length; i++) { | |
375 | if (cids_requested.indexOf(neighbor_ids[i]) == -1) | |
376 | if (!cache_get("article:" + neighbor_ids[i])) { | |
377 | cids_to_request.push(neighbor_ids[i]); | |
378 | cids_requested.push(neighbor_ids[i]); | |
379 | } | |
380 | } | |
381 | ||
382 | console.log("additional ids: " + cids_to_request.toString()); | |
383 | ||
384 | query = query + "&cids=" + cids_to_request.toString(); | |
385 | ||
386 | var article_is_unread = crow.hasClassName("Unread"); | |
387 | ||
388 | setActiveArticleId(id); | |
389 | showArticleInHeadlines(id); | |
390 | ||
391 | if (cached_article && article_is_unread) { | |
392 | ||
393 | query = query + "&mode=prefetch"; | |
394 | ||
395 | render_article(cached_article); | |
396 | ||
397 | } else if (cached_article) { | |
398 | ||
399 | query = query + "&mode=prefetch_old"; | |
400 | render_article(cached_article); | |
401 | ||
402 | // if we don't need to request any relative ids, we might as well skip | |
403 | // the server roundtrip altogether | |
404 | if (cids_to_request.length == 0) { | |
405 | ||
406 | /* try { | |
407 | if (!_infscroll_disable && | |
408 | $$("#headlines-frame > div[id*=RROW]").last().hasClassName("Selected")) { | |
409 | ||
410 | loadMoreHeadlines(); | |
411 | } | |
412 | } catch (e) { | |
413 | console.warn(e); | |
414 | } */ | |
415 | ||
416 | //headlines_scroll_handler($("headlines-frame")); | |
417 | ||
418 | return; | |
419 | } | |
420 | } | |
421 | ||
422 | last_requested_article = id; | |
423 | ||
424 | console.log(query); | |
425 | ||
426 | if (article_is_unread) { | |
427 | decrementFeedCounter(getActiveFeedId(), activeFeedIsCat()); | |
428 | } | |
429 | ||
430 | new Ajax.Request("backend.php", { | |
431 | parameters: query, | |
432 | onComplete: function(transport) { | |
433 | article_callback2(transport, id); | |
434 | } }); | |
435 | ||
436 | return false; | |
437 | ||
438 | } catch (e) { | |
439 | exception_error("view", e); | |
440 | } | |
441 | } | |
442 | ||
443 | function toggleMark(id, client_only) { | |
444 | try { | |
445 | var query = "?op=rpc&id=" + id + "&method=mark"; | |
446 | ||
447 | var row = $("RROW-" + id); | |
448 | if (!row) return; | |
449 | ||
450 | var imgs = []; | |
451 | ||
452 | var row_imgs = row.getElementsByClassName("markedPic"); | |
453 | ||
454 | for (var i = 0; i < row_imgs.length; i++) | |
455 | imgs.push(row_imgs[i]); | |
456 | ||
457 | var ft = $("floatingTitle"); | |
458 | ||
459 | if (ft && ft.getAttribute("rowid") == "RROW-" + id) { | |
460 | var fte = ft.getElementsByClassName("markedPic"); | |
461 | ||
462 | for (var i = 0; i < fte.length; i++) | |
463 | imgs.push(fte[i]); | |
464 | } | |
465 | ||
466 | for (i = 0; i < imgs.length; i++) { | |
467 | var img = imgs[i]; | |
468 | ||
469 | if (!row.hasClassName("marked")) { | |
470 | img.src = img.src.replace("mark_unset", "mark_set"); | |
471 | img.alt = __("Unstar article"); | |
472 | query = query + "&mark=1"; | |
473 | } else { | |
474 | img.src = img.src.replace("mark_set", "mark_unset"); | |
475 | img.alt = __("Star article"); | |
476 | query = query + "&mark=0"; | |
477 | } | |
478 | } | |
479 | ||
480 | row.toggleClassName("marked"); | |
481 | ||
482 | if (!client_only) { | |
483 | new Ajax.Request("backend.php", { | |
484 | parameters: query, | |
485 | onComplete: function(transport) { | |
486 | handle_rpc_json(transport); | |
487 | } }); | |
488 | } | |
489 | ||
490 | } catch (e) { | |
491 | exception_error("toggleMark", e); | |
492 | } | |
493 | } | |
494 | ||
495 | function togglePub(id, client_only, no_effects, note) { | |
496 | try { | |
497 | var query = "?op=rpc&id=" + id + "&method=publ"; | |
498 | ||
499 | if (note != undefined) { | |
500 | query = query + "¬e=" + param_escape(note); | |
501 | } else { | |
502 | query = query + "¬e=undefined"; | |
503 | } | |
504 | ||
505 | var row = $("RROW-" + id); | |
506 | if (!row) return; | |
507 | ||
508 | var imgs = []; | |
509 | ||
510 | var row_imgs = row.getElementsByClassName("pubPic"); | |
511 | ||
512 | for (var i = 0; i < row_imgs.length; i++) | |
513 | imgs.push(row_imgs[i]); | |
514 | ||
515 | var ft = $("floatingTitle"); | |
516 | ||
517 | if (ft && ft.getAttribute("rowid") == "RROW-" + id) { | |
518 | var fte = ft.getElementsByClassName("pubPic"); | |
519 | ||
520 | for (var i = 0; i < fte.length; i++) | |
521 | imgs.push(fte[i]); | |
522 | } | |
523 | ||
524 | for (i = 0; i < imgs.length; i++) { | |
525 | var img = imgs[i]; | |
526 | ||
527 | if (!row.hasClassName("published") || note != undefined) { | |
528 | img.src = img.src.replace("pub_unset", "pub_set"); | |
529 | img.alt = __("Unpublish article"); | |
530 | query = query + "&pub=1"; | |
531 | } else { | |
532 | img.src = img.src.replace("pub_set", "pub_unset"); | |
533 | img.alt = __("Publish article"); | |
534 | query = query + "&pub=0"; | |
535 | } | |
536 | } | |
537 | ||
538 | if (note != undefined) | |
539 | row.addClassName("published"); | |
540 | else | |
541 | row.toggleClassName("published"); | |
542 | ||
543 | if (!client_only) { | |
544 | new Ajax.Request("backend.php", { | |
545 | parameters: query, | |
546 | onComplete: function(transport) { | |
547 | handle_rpc_json(transport); | |
548 | } }); | |
549 | } | |
550 | ||
551 | } catch (e) { | |
552 | exception_error("togglePub", e); | |
553 | } | |
554 | } | |
555 | ||
556 | function moveToPost(mode, noscroll, noexpand) { | |
557 | ||
558 | try { | |
559 | ||
560 | var rows = getVisibleArticleIds(); | |
561 | ||
562 | var prev_id = false; | |
563 | var next_id = false; | |
564 | ||
565 | if (!$('RROW-' + getActiveArticleId())) { | |
566 | setActiveArticleId(0); | |
567 | } | |
568 | ||
569 | if (!getActiveArticleId()) { | |
570 | next_id = rows[0]; | |
571 | prev_id = rows[rows.length-1] | |
572 | } else { | |
573 | for (var i = 0; i < rows.length; i++) { | |
574 | if (rows[i] == getActiveArticleId()) { | |
575 | ||
576 | // Account for adjacent identical article ids. | |
577 | if (i > 0) prev_id = rows[i-1]; | |
578 | ||
579 | for (var j = i+1; j < rows.length; j++) { | |
580 | if (rows[j] != getActiveArticleId()) { | |
581 | next_id = rows[j]; | |
582 | break; | |
583 | } | |
584 | } | |
585 | break; | |
586 | } | |
587 | } | |
588 | } | |
589 | ||
590 | if (mode == "next") { | |
591 | if (next_id || getActiveArticleId()) { | |
592 | if (isCdmMode()) { | |
593 | ||
594 | var article = $("RROW-" + getActiveArticleId()); | |
595 | var ctr = $("headlines-frame"); | |
596 | ||
597 | if (!noscroll && article && article.offsetTop + article.offsetHeight > | |
598 | ctr.scrollTop + ctr.offsetHeight) { | |
599 | ||
600 | scrollArticle(ctr.offsetHeight/4); | |
601 | ||
602 | } else if (next_id) { | |
603 | cdmExpandArticle(next_id, noexpand); | |
604 | cdmScrollToArticleId(next_id, true); | |
605 | } | |
606 | ||
607 | } else if (next_id) { | |
608 | correctHeadlinesOffset(next_id); | |
609 | view(next_id, getActiveFeedId(), noexpand); | |
610 | } | |
611 | } | |
612 | } | |
613 | ||
614 | if (mode == "prev") { | |
615 | if (prev_id || getActiveArticleId()) { | |
616 | if (isCdmMode()) { | |
617 | ||
618 | var article = $("RROW-" + getActiveArticleId()); | |
619 | var prev_article = $("RROW-" + prev_id); | |
620 | var ctr = $("headlines-frame"); | |
621 | ||
622 | if (!getInitParam("cdm_expanded")) { | |
623 | ||
624 | if (!noscroll && article && article.offsetTop < ctr.scrollTop) { | |
625 | scrollArticle(-ctr.offsetHeight/4); | |
626 | } else { | |
627 | cdmExpandArticle(prev_id, noexpand); | |
628 | cdmScrollToArticleId(prev_id, true); | |
629 | } | |
630 | } else { | |
631 | ||
632 | if (!noscroll && article && article.offsetTop < ctr.scrollTop) { | |
633 | scrollArticle(-ctr.offsetHeight/3); | |
634 | } else if (!noscroll && prev_article && | |
635 | prev_article.offsetTop < ctr.scrollTop) { | |
636 | cdmExpandArticle(prev_id, noexpand); | |
637 | scrollArticle(-ctr.offsetHeight/4); | |
638 | } else if (prev_id) { | |
639 | cdmExpandArticle(prev_id, noexpand); | |
640 | cdmScrollToArticleId(prev_id, noscroll); | |
641 | } | |
642 | } | |
643 | ||
644 | } else if (prev_id) { | |
645 | correctHeadlinesOffset(prev_id); | |
646 | view(prev_id, getActiveFeedId(), noexpand); | |
647 | } | |
648 | } | |
649 | } | |
650 | ||
651 | } catch (e) { | |
652 | exception_error("moveToPost", e); | |
653 | } | |
654 | } | |
655 | ||
656 | function toggleSelected(id, force_on) { | |
657 | try { | |
658 | var row = $("RROW-" + id); | |
659 | ||
660 | if (row) { | |
661 | var cb = dijit.getEnclosingWidget( | |
662 | row.getElementsByClassName("rchk")[0]); | |
663 | ||
664 | if (row.hasClassName('Selected') && !force_on) { | |
665 | row.removeClassName('Selected'); | |
666 | if (cb) cb.attr("checked", false); | |
667 | } else { | |
668 | row.addClassName('Selected'); | |
669 | if (cb) cb.attr("checked", true); | |
670 | } | |
671 | } | |
672 | ||
673 | updateSelectedPrompt(); | |
674 | } catch (e) { | |
675 | exception_error("toggleSelected", e); | |
676 | } | |
677 | } | |
678 | ||
679 | function updateSelectedPrompt() { | |
680 | try { | |
681 | var count = getSelectedArticleIds2().size(); | |
682 | var elem = $("selected_prompt"); | |
683 | ||
684 | if (elem) { | |
685 | elem.innerHTML = ngettext("%d article selected", | |
686 | "%d articles selected", count).replace("%d", count); | |
687 | ||
688 | if (count > 0) | |
689 | Element.show(elem); | |
690 | else | |
691 | Element.hide(elem); | |
692 | } | |
693 | ||
694 | } catch (e) { | |
695 | exception_error("updateSelectedPrompt", e); | |
696 | } | |
697 | } | |
698 | ||
699 | function toggleUnread_afh(effect) { | |
700 | try { | |
701 | ||
702 | var elem = effect.element; | |
703 | elem.style.backgroundColor = ""; | |
704 | ||
705 | } catch (e) { | |
706 | exception_error("toggleUnread_afh", e); | |
707 | } | |
708 | } | |
709 | ||
710 | function toggleUnread(id, cmode, effect) { | |
711 | try { | |
712 | ||
713 | var row = $("RROW-" + id); | |
714 | if (row) { | |
715 | if (cmode == undefined || cmode == 2) { | |
716 | if (row.hasClassName("Unread")) { | |
717 | row.removeClassName("Unread"); | |
718 | ||
719 | } else { | |
720 | row.addClassName("Unread"); | |
721 | } | |
722 | ||
723 | } else if (cmode == 0) { | |
724 | ||
725 | row.removeClassName("Unread"); | |
726 | ||
727 | } else if (cmode == 1) { | |
728 | row.addClassName("Unread"); | |
729 | } | |
730 | ||
731 | if (cmode == undefined) cmode = 2; | |
732 | ||
733 | var query = "?op=rpc&method=catchupSelected" + | |
734 | "&cmode=" + param_escape(cmode) + "&ids=" + param_escape(id); | |
735 | ||
736 | // notify_progress("Loading, please wait..."); | |
737 | ||
738 | new Ajax.Request("backend.php", { | |
739 | parameters: query, | |
740 | onComplete: function(transport) { | |
741 | handle_rpc_json(transport); | |
742 | } }); | |
743 | ||
744 | } | |
745 | ||
746 | } catch (e) { | |
747 | exception_error("toggleUnread", e); | |
748 | } | |
749 | } | |
750 | ||
751 | function selectionRemoveLabel(id, ids) { | |
752 | try { | |
753 | ||
754 | if (!ids) ids = getSelectedArticleIds2(); | |
755 | ||
756 | if (ids.length == 0) { | |
757 | alert(__("No articles are selected.")); | |
758 | return; | |
759 | } | |
760 | ||
761 | var query = "?op=article&method=removeFromLabel&ids=" + | |
762 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
763 | ||
764 | console.log(query); | |
765 | ||
766 | new Ajax.Request("backend.php", { | |
767 | parameters: query, | |
768 | onComplete: function(transport) { | |
769 | handle_rpc_json(transport); | |
770 | show_labels_in_headlines(transport); | |
771 | } }); | |
772 | ||
773 | } catch (e) { | |
774 | exception_error("selectionAssignLabel", e); | |
775 | ||
776 | } | |
777 | } | |
778 | ||
779 | function selectionAssignLabel(id, ids) { | |
780 | try { | |
781 | ||
782 | if (!ids) ids = getSelectedArticleIds2(); | |
783 | ||
784 | if (ids.length == 0) { | |
785 | alert(__("No articles are selected.")); | |
786 | return; | |
787 | } | |
788 | ||
789 | var query = "?op=article&method=assignToLabel&ids=" + | |
790 | param_escape(ids.toString()) + "&lid=" + param_escape(id); | |
791 | ||
792 | console.log(query); | |
793 | ||
794 | new Ajax.Request("backend.php", { | |
795 | parameters: query, | |
796 | onComplete: function(transport) { | |
797 | handle_rpc_json(transport); | |
798 | show_labels_in_headlines(transport); | |
799 | } }); | |
800 | ||
801 | } catch (e) { | |
802 | exception_error("selectionAssignLabel", e); | |
803 | ||
804 | } | |
805 | } | |
806 | ||
807 | function selectionToggleUnread(set_state, callback, no_error, ids) { | |
808 | try { | |
809 | var rows = ids ? ids : getSelectedArticleIds2(); | |
810 | ||
811 | if (rows.length == 0 && !no_error) { | |
812 | alert(__("No articles are selected.")); | |
813 | return; | |
814 | } | |
815 | ||
816 | for (var i = 0; i < rows.length; i++) { | |
817 | var row = $("RROW-" + rows[i]); | |
818 | if (row) { | |
819 | if (set_state == undefined) { | |
820 | if (row.hasClassName("Unread")) { | |
821 | row.removeClassName("Unread"); | |
822 | } else { | |
823 | row.addClassName("Unread"); | |
824 | } | |
825 | } | |
826 | ||
827 | if (set_state == false) { | |
828 | row.removeClassName("Unread"); | |
829 | } | |
830 | ||
831 | if (set_state == true) { | |
832 | row.addClassName("Unread"); | |
833 | } | |
834 | } | |
835 | } | |
836 | ||
837 | updateFloatingTitle(true); | |
838 | ||
839 | if (rows.length > 0) { | |
840 | ||
841 | var cmode = ""; | |
842 | ||
843 | if (set_state == undefined) { | |
844 | cmode = "2"; | |
845 | } else if (set_state == true) { | |
846 | cmode = "1"; | |
847 | } else if (set_state == false) { | |
848 | cmode = "0"; | |
849 | } | |
850 | ||
851 | var query = "?op=rpc&method=catchupSelected" + | |
852 | "&cmode=" + cmode + "&ids=" + param_escape(rows.toString()); | |
853 | ||
854 | notify_progress("Loading, please wait..."); | |
855 | ||
856 | new Ajax.Request("backend.php", { | |
857 | parameters: query, | |
858 | onComplete: function(transport) { | |
859 | handle_rpc_json(transport); | |
860 | if (callback) callback(transport); | |
861 | } }); | |
862 | ||
863 | } | |
864 | ||
865 | } catch (e) { | |
866 | exception_error("selectionToggleUnread", e); | |
867 | } | |
868 | } | |
869 | ||
870 | // sel_state ignored | |
871 | function selectionToggleMarked(sel_state, callback, no_error, ids) { | |
872 | try { | |
873 | ||
874 | var rows = ids ? ids : getSelectedArticleIds2(); | |
875 | ||
876 | if (rows.length == 0 && !no_error) { | |
877 | alert(__("No articles are selected.")); | |
878 | return; | |
879 | } | |
880 | ||
881 | for (var i = 0; i < rows.length; i++) { | |
882 | toggleMark(rows[i], true, true); | |
883 | } | |
884 | ||
885 | if (rows.length > 0) { | |
886 | ||
887 | var query = "?op=rpc&method=markSelected&ids=" + | |
888 | param_escape(rows.toString()) + "&cmode=2"; | |
889 | ||
890 | new Ajax.Request("backend.php", { | |
891 | parameters: query, | |
892 | onComplete: function(transport) { | |
893 | handle_rpc_json(transport); | |
894 | if (callback) callback(transport); | |
895 | } }); | |
896 | ||
897 | } | |
898 | ||
899 | } catch (e) { | |
900 | exception_error("selectionToggleMarked", e); | |
901 | } | |
902 | } | |
903 | ||
904 | // sel_state ignored | |
905 | function selectionTogglePublished(sel_state, callback, no_error, ids) { | |
906 | try { | |
907 | ||
908 | var rows = ids ? ids : getSelectedArticleIds2(); | |
909 | ||
910 | if (rows.length == 0 && !no_error) { | |
911 | alert(__("No articles are selected.")); | |
912 | return; | |
913 | } | |
914 | ||
915 | for (var i = 0; i < rows.length; i++) { | |
916 | togglePub(rows[i], true, true); | |
917 | } | |
918 | ||
919 | if (rows.length > 0) { | |
920 | ||
921 | var query = "?op=rpc&method=publishSelected&ids=" + | |
922 | param_escape(rows.toString()) + "&cmode=2"; | |
923 | ||
924 | new Ajax.Request("backend.php", { | |
925 | parameters: query, | |
926 | onComplete: function(transport) { | |
927 | handle_rpc_json(transport); | |
928 | } }); | |
929 | ||
930 | } | |
931 | ||
932 | } catch (e) { | |
933 | exception_error("selectionToggleMarked", e); | |
934 | } | |
935 | } | |
936 | ||
937 | function getSelectedArticleIds2() { | |
938 | ||
939 | var rv = []; | |
940 | ||
941 | $$("#headlines-frame > div[id*=RROW][class*=Selected]").each( | |
942 | function(child) { | |
943 | rv.push(child.id.replace("RROW-", "")); | |
944 | }); | |
945 | ||
946 | return rv; | |
947 | } | |
948 | ||
949 | function getLoadedArticleIds() { | |
950 | var rv = []; | |
951 | ||
952 | var children = $$("#headlines-frame > div[id*=RROW-]"); | |
953 | ||
954 | children.each(function(child) { | |
955 | rv.push(child.id.replace("RROW-", "")); | |
956 | }); | |
957 | ||
958 | return rv; | |
959 | ||
960 | } | |
961 | ||
962 | // mode = all,none,unread,invert,marked,published | |
963 | function selectArticles(mode, query) { | |
964 | try { | |
965 | ||
966 | if (!query) query = "#headlines-frame > div[id*=RROW]"; | |
967 | ||
968 | var children = $$(query); | |
969 | ||
970 | children.each(function(child) { | |
971 | var id = child.id.replace("RROW-", ""); | |
972 | ||
973 | var cb = dijit.getEnclosingWidget( | |
974 | child.getElementsByClassName("rchk")[0]); | |
975 | ||
976 | if (mode == "all") { | |
977 | child.addClassName("Selected"); | |
978 | if (cb) cb.attr("checked", true); | |
979 | } else if (mode == "unread") { | |
980 | if (child.hasClassName("Unread")) { | |
981 | child.addClassName("Selected"); | |
982 | if (cb) cb.attr("checked", true); | |
983 | } else { | |
984 | child.removeClassName("Selected"); | |
985 | if (cb) cb.attr("checked", false); | |
986 | } | |
987 | } else if (mode == "marked") { | |
988 | if (child.hasClassName("marked")) { | |
989 | child.addClassName("Selected"); | |
990 | if (cb) cb.attr("checked", true); | |
991 | } else { | |
992 | child.removeClassName("Selected"); | |
993 | if (cb) cb.attr("checked", false); | |
994 | } | |
995 | } else if (mode == "published") { | |
996 | if (child.hasClassName("published")) { | |
997 | child.addClassName("Selected"); | |
998 | if (cb) cb.attr("checked", true); | |
999 | } else { | |
1000 | child.removeClassName("Selected"); | |
1001 | if (cb) cb.attr("checked", false); | |
1002 | } | |
1003 | ||
1004 | } else if (mode == "invert") { | |
1005 | if (child.hasClassName("Selected")) { | |
1006 | child.removeClassName("Selected"); | |
1007 | if (cb) cb.attr("checked", false); | |
1008 | } else { | |
1009 | child.addClassName("Selected"); | |
1010 | if (cb) cb.attr("checked", true); | |
1011 | } | |
1012 | ||
1013 | } else { | |
1014 | child.removeClassName("Selected"); | |
1015 | if (cb) cb.attr("checked", false); | |
1016 | } | |
1017 | }); | |
1018 | ||
1019 | updateSelectedPrompt(); | |
1020 | ||
1021 | } catch (e) { | |
1022 | exception_error("selectArticles", e); | |
1023 | } | |
1024 | } | |
1025 | ||
1026 | function deleteSelection() { | |
1027 | ||
1028 | try { | |
1029 | ||
1030 | var rows = getSelectedArticleIds2(); | |
1031 | ||
1032 | if (rows.length == 0) { | |
1033 | alert(__("No articles are selected.")); | |
1034 | return; | |
1035 | } | |
1036 | ||
1037 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1038 | var str; | |
1039 | ||
1040 | if (getActiveFeedId() != 0) { | |
1041 | str = ngettext("Delete %d selected article in %s?", "Delete %d selected articles in %s?" , rows.length); | |
1042 | } else { | |
1043 | str = ngettext("Delete %d selected article?", "Delete %d selected articles?", rows.length); | |
1044 | } | |
1045 | ||
1046 | str = str.replace("%d", rows.length); | |
1047 | str = str.replace("%s", fn); | |
1048 | ||
1049 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1050 | return; | |
1051 | } | |
1052 | ||
1053 | query = "?op=rpc&method=delete&ids=" + param_escape(rows); | |
1054 | ||
1055 | console.log(query); | |
1056 | ||
1057 | new Ajax.Request("backend.php", { | |
1058 | parameters: query, | |
1059 | onComplete: function(transport) { | |
1060 | handle_rpc_json(transport); | |
1061 | viewCurrentFeed(); | |
1062 | } }); | |
1063 | ||
1064 | } catch (e) { | |
1065 | exception_error("deleteSelection", e); | |
1066 | } | |
1067 | } | |
1068 | ||
1069 | function archiveSelection() { | |
1070 | ||
1071 | try { | |
1072 | ||
1073 | var rows = getSelectedArticleIds2(); | |
1074 | ||
1075 | if (rows.length == 0) { | |
1076 | alert(__("No articles are selected.")); | |
1077 | return; | |
1078 | } | |
1079 | ||
1080 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1081 | var str; | |
1082 | var op; | |
1083 | ||
1084 | if (getActiveFeedId() != 0) { | |
1085 | str = ngettext("Archive %d selected article in %s?", "Archive %d selected articles in %s?", rows.length); | |
1086 | op = "archive"; | |
1087 | } else { | |
1088 | str = ngettext("Move %d archived article back?", "Move %d archived articles back?", rows.length); | |
1089 | ||
1090 | str += " " + __("Please note that unstarred articles might get purged on next feed update."); | |
1091 | ||
1092 | op = "unarchive"; | |
1093 | } | |
1094 | ||
1095 | str = str.replace("%d", rows.length); | |
1096 | str = str.replace("%s", fn); | |
1097 | ||
1098 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1099 | return; | |
1100 | } | |
1101 | ||
1102 | query = "?op=rpc&method="+op+"&ids=" + param_escape(rows); | |
1103 | ||
1104 | console.log(query); | |
1105 | ||
1106 | for (var i = 0; i < rows.length; i++) { | |
1107 | cache_delete("article:" + rows[i]); | |
1108 | } | |
1109 | ||
1110 | new Ajax.Request("backend.php", { | |
1111 | parameters: query, | |
1112 | onComplete: function(transport) { | |
1113 | handle_rpc_json(transport); | |
1114 | viewCurrentFeed(); | |
1115 | } }); | |
1116 | ||
1117 | } catch (e) { | |
1118 | exception_error("archiveSelection", e); | |
1119 | } | |
1120 | } | |
1121 | ||
1122 | function catchupSelection() { | |
1123 | ||
1124 | try { | |
1125 | ||
1126 | var rows = getSelectedArticleIds2(); | |
1127 | ||
1128 | if (rows.length == 0) { | |
1129 | alert(__("No articles are selected.")); | |
1130 | return; | |
1131 | } | |
1132 | ||
1133 | var fn = getFeedName(getActiveFeedId(), activeFeedIsCat()); | |
1134 | ||
1135 | var str = ngettext("Mark %d selected article in %s as read?", "Mark %d selected articles in %s as read?", rows.length); | |
1136 | ||
1137 | str = str.replace("%d", rows.length); | |
1138 | str = str.replace("%s", fn); | |
1139 | ||
1140 | if (getInitParam("confirm_feed_catchup") == 1 && !confirm(str)) { | |
1141 | return; | |
1142 | } | |
1143 | ||
1144 | selectionToggleUnread(false, 'viewCurrentFeed()', true); | |
1145 | ||
1146 | } catch (e) { | |
1147 | exception_error("catchupSelection", e); | |
1148 | } | |
1149 | } | |
1150 | ||
1151 | function editArticleTags(id) { | |
1152 | var query = "backend.php?op=article&method=editArticleTags¶m=" + param_escape(id); | |
1153 | ||
1154 | if (dijit.byId("editTagsDlg")) | |
1155 | dijit.byId("editTagsDlg").destroyRecursive(); | |
1156 | ||
1157 | dialog = new dijit.Dialog({ | |
1158 | id: "editTagsDlg", | |
1159 | title: __("Edit article Tags"), | |
1160 | style: "width: 600px", | |
1161 | execute: function() { | |
1162 | if (this.validate()) { | |
1163 | var query = dojo.objectToQuery(this.attr('value')); | |
1164 | ||
1165 | notify_progress("Saving article tags...", true); | |
1166 | ||
1167 | new Ajax.Request("backend.php", { | |
1168 | parameters: query, | |
1169 | onComplete: function(transport) { | |
1170 | try { | |
1171 | notify(''); | |
1172 | dialog.hide(); | |
1173 | ||
1174 | var data = JSON.parse(transport.responseText); | |
1175 | ||
1176 | if (data) { | |
1177 | var id = data.id; | |
1178 | ||
1179 | console.log(id); | |
1180 | ||
1181 | var tags = $("ATSTR-" + id); | |
1182 | var tooltip = dijit.byId("ATSTRTIP-" + id); | |
1183 | ||
1184 | if (tags) tags.innerHTML = data.content; | |
1185 | if (tooltip) tooltip.attr('label', data.content_full); | |
1186 | } | |
1187 | } catch (e) { | |
1188 | exception_error("editArticleTags/inner", e); | |
1189 | } | |
1190 | ||
1191 | }}); | |
1192 | } | |
1193 | }, | |
1194 | href: query, | |
1195 | }); | |
1196 | ||
1197 | var tmph = dojo.connect(dialog, 'onLoad', function() { | |
1198 | dojo.disconnect(tmph); | |
1199 | ||
1200 | new Ajax.Autocompleter('tags_str', 'tags_choices', | |
1201 | "backend.php?op=article&method=completeTags", | |
1202 | { tokens: ',', paramName: "search" }); | |
1203 | }); | |
1204 | ||
1205 | dialog.show(); | |
1206 | ||
1207 | } | |
1208 | ||
1209 | function cdmScrollToArticleId(id, force) { | |
1210 | try { | |
1211 | var ctr = $("headlines-frame"); | |
1212 | var e = $("RROW-" + id); | |
1213 | ||
1214 | if (!e || !ctr) return; | |
1215 | ||
1216 | if (force || e.offsetTop+e.offsetHeight > (ctr.scrollTop+ctr.offsetHeight) || | |
1217 | e.offsetTop < ctr.scrollTop) { | |
1218 | ||
1219 | // expanded cdm has a 4px margin now | |
1220 | ctr.scrollTop = parseInt(e.offsetTop) - 4; | |
1221 | } | |
1222 | ||
1223 | } catch (e) { | |
1224 | exception_error("cdmScrollToArticleId", e); | |
1225 | } | |
1226 | } | |
1227 | ||
1228 | function setActiveArticleId(id) { | |
1229 | _active_article_id = id; | |
1230 | PluginHost.run(PluginHost.HOOK_ARTICLE_SET_ACTIVE, _active_article_id); | |
1231 | } | |
1232 | ||
1233 | function getActiveArticleId() { | |
1234 | return _active_article_id; | |
1235 | } | |
1236 | ||
1237 | function postMouseIn(e, id) { | |
1238 | post_under_pointer = id; | |
1239 | } | |
1240 | ||
1241 | function postMouseOut(id) { | |
1242 | post_under_pointer = false; | |
1243 | } | |
1244 | ||
1245 | function unpackVisibleHeadlines() { | |
1246 | try { | |
1247 | if (!isCdmMode() || !getInitParam("cdm_expanded")) return; | |
1248 | ||
1249 | $$("#headlines-frame > div[id*=RROW]").each( | |
1250 | function(child) { | |
1251 | if (child.offsetTop <= $("headlines-frame").scrollTop + | |
1252 | $("headlines-frame").offsetHeight) { | |
1253 | ||
1254 | var cencw = $("CENCW-" + child.id.replace("RROW-", "")); | |
1255 | ||
1256 | if (cencw) { | |
1257 | PluginHost.run(PluginHost.HOOK_ARTICLE_RENDERED_CDM, child); | |
1258 | ||
1259 | cencw.innerHTML = htmlspecialchars_decode(cencw.innerHTML); | |
1260 | cencw.setAttribute('id', ''); | |
1261 | Element.show(cencw); | |
1262 | } | |
1263 | } | |
1264 | } | |
1265 | ); | |
1266 | ||
1267 | } catch (e) { | |
1268 | exception_error("unpackVisibleHeadlines", e); | |
1269 | } | |
1270 | } | |
1271 | ||
1272 | function headlines_scroll_handler(e) { | |
1273 | try { | |
1274 | var hsp = $("headlines-spacer"); | |
1275 | ||
1276 | unpackVisibleHeadlines(); | |
1277 | ||
1278 | // set topmost child in the buffer as active | |
1279 | if (isCdmMode() && getInitParam("cdm_auto_catchup") == 1 && | |
1280 | getSelectedArticleIds2().length <= 1 && | |
1281 | getInitParam("cdm_expanded")) { | |
1282 | var rows = $$("#headlines-frame > div[id*=RROW]"); | |
1283 | ||
1284 | for (var i = 0; i < rows.length; i++) { | |
1285 | var child = rows[i]; | |
1286 | ||
1287 | if ($("headlines-frame").scrollTop <= child.offsetTop && | |
1288 | child.offsetTop - $("headlines-frame").scrollTop < 100 && | |
1289 | child.id.replace("RROW-", "") != _active_article_id) { | |
1290 | ||
1291 | if (_active_article_id) { | |
1292 | var row = $("RROW-" + _active_article_id); | |
1293 | if (row) row.removeClassName("active"); | |
1294 | } | |
1295 | ||
1296 | _active_article_id = child.id.replace("RROW-", ""); | |
1297 | showArticleInHeadlines(_active_article_id, true); | |
1298 | updateSelectedPrompt(); | |
1299 | break; | |
1300 | } | |
1301 | } | |
1302 | } | |
1303 | ||
1304 | if (!_infscroll_disable) { | |
1305 | if ((hsp && e.scrollTop + e.offsetHeight >= hsp.offsetTop - hsp.offsetHeight) || | |
1306 | (e.scrollHeight != 0 && | |
1307 | ((e.scrollTop + e.offsetHeight) / e.scrollHeight >= 0.7))) { | |
1308 | ||
1309 | if (hsp) | |
1310 | hsp.innerHTML = "<img src='images/indicator_tiny.gif'> " + | |
1311 | __("Loading, please wait..."); | |
1312 | ||
1313 | loadMoreHeadlines(); | |
1314 | return; | |
1315 | ||
1316 | } | |
1317 | } else { | |
1318 | if (hsp) hsp.innerHTML = ""; | |
1319 | } | |
1320 | ||
1321 | if (isCdmMode()) { | |
1322 | updateFloatingTitle(); | |
1323 | } | |
1324 | ||
1325 | if (getInitParam("cdm_auto_catchup") == 1) { | |
1326 | ||
1327 | // let's get DOM some time to settle down | |
1328 | var ts = new Date().getTime(); | |
1329 | if (ts - _last_headlines_update < 100) return; | |
1330 | ||
1331 | $$("#headlines-frame > div[id*=RROW][class*=Unread]").each( | |
1332 | function(child) { | |
1333 | if (child.hasClassName("Unread") && $("headlines-frame").scrollTop > | |
1334 | (child.offsetTop + child.offsetHeight/2)) { | |
1335 | ||
1336 | var id = child.id.replace("RROW-", ""); | |
1337 | ||
1338 | if (catchup_id_batch.indexOf(id) == -1) | |
1339 | catchup_id_batch.push(id); | |
1340 | ||
1341 | //console.log("auto_catchup_batch: " + catchup_id_batch.toString()); | |
1342 | } | |
1343 | ||
1344 | }); | |
1345 | ||
1346 | if (catchup_id_batch.length > 0) { | |
1347 | window.clearTimeout(catchup_timeout_id); | |
1348 | ||
1349 | if (!_infscroll_request_sent) { | |
1350 | catchup_timeout_id = window.setTimeout('catchupBatchedArticles()', | |
1351 | 500); | |
1352 | } | |
1353 | } | |
1354 | ||
1355 | if (_infscroll_disable) { | |
1356 | var child = $$("#headlines-frame div[id*=RROW]").last(); | |
1357 | ||
1358 | if (child && $("headlines-frame").scrollTop > | |
1359 | (child.offsetTop + child.offsetHeight/2)) { | |
1360 | ||
1361 | console.log("we seem to be at an end"); | |
1362 | ||
1363 | if (getInitParam("on_catchup_show_next_feed") == "1") { | |
1364 | var is_cat = activeFeedIsCat(); | |
1365 | var nuf = getNextUnreadFeed(getActiveFeedId(), is_cat); | |
1366 | ||
1367 | if (nuf) viewfeed(nuf, '', is_cat); | |
1368 | } | |
1369 | } | |
1370 | } | |
1371 | } | |
1372 | ||
1373 | } catch (e) { | |
1374 | console.warn("headlines_scroll_handler: " + e); | |
1375 | } | |
1376 | } | |
1377 | ||
1378 | function catchupBatchedArticles() { | |
1379 | try { | |
1380 | if (catchup_id_batch.length > 0 && !_infscroll_request_sent) { | |
1381 | ||
1382 | // make a copy of the array | |
1383 | var batch = catchup_id_batch.slice(); | |
1384 | var query = "?op=rpc&method=catchupSelected" + | |
1385 | "&cmode=0&ids=" + param_escape(batch.toString()); | |
1386 | ||
1387 | console.log(query); | |
1388 | ||
1389 | new Ajax.Request("backend.php", { | |
1390 | parameters: query, | |
1391 | onComplete: function(transport) { | |
1392 | handle_rpc_json(transport); | |
1393 | ||
1394 | reply = JSON.parse(transport.responseText); | |
1395 | var batch = reply.ids; | |
1396 | ||
1397 | batch.each(function(id) { | |
1398 | console.log(id); | |
1399 | var elem = $("RROW-" + id); | |
1400 | if (elem) elem.removeClassName("Unread"); | |
1401 | catchup_id_batch.remove(id); | |
1402 | }); | |
1403 | ||
1404 | updateFloatingTitle(true); | |
1405 | ||
1406 | } }); | |
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 | } |