viewfeed.js 47 KB

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