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