viewfeed.js 53 KB

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