viewfeed.js 47 KB

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