viewfeed.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063
  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. openArticleInNewWindow(id);
  1132. return false;
  1133. } else {
  1134. view(id);
  1135. return false;
  1136. }
  1137. }
  1138. function openArticleInNewWindow(id) {
  1139. toggleUnread(id, 0, false);
  1140. var w = window.open("");
  1141. w.opener = null;
  1142. w.location = "backend.php?op=article&method=redirect&id=" + id;
  1143. }
  1144. function isCdmMode() {
  1145. return getInitParam("combined_display_mode");
  1146. }
  1147. function markHeadline(id, marked) {
  1148. if (marked == undefined) marked = true;
  1149. var row = $("RROW-" + id);
  1150. if (row) {
  1151. var check = dijit.getEnclosingWidget(
  1152. row.getElementsByClassName("rchk")[0]);
  1153. if (check) {
  1154. check.attr("checked", marked);
  1155. }
  1156. if (marked)
  1157. row.addClassName("Selected");
  1158. else
  1159. row.removeClassName("Selected");
  1160. }
  1161. }
  1162. function getRelativePostIds(id, limit) {
  1163. var tmp = [];
  1164. if (!limit) limit = 6; //3
  1165. var ids = getLoadedArticleIds();
  1166. for (var i = 0; i < ids.length; i++) {
  1167. if (ids[i] == id) {
  1168. for (var k = 1; k <= limit; k++) {
  1169. //if (i > k-1) tmp.push(ids[i-k]);
  1170. if (i < ids.length - k) tmp.push(ids[i + k]);
  1171. }
  1172. break;
  1173. }
  1174. }
  1175. return tmp;
  1176. }
  1177. function correctHeadlinesOffset(id) {
  1178. var container = $("headlines-frame");
  1179. var row = $("RROW-" + id);
  1180. if (!container || !row) return;
  1181. var viewport = container.offsetHeight;
  1182. var rel_offset_top = row.offsetTop - container.scrollTop;
  1183. var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop;
  1184. //console.log("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom);
  1185. //console.log("Vport: " + viewport);
  1186. if (rel_offset_top <= 0 || rel_offset_top > viewport) {
  1187. container.scrollTop = row.offsetTop;
  1188. } else if (rel_offset_bottom > viewport) {
  1189. /* doesn't properly work with Opera in some cases because
  1190. Opera fucks up element scrolling */
  1191. container.scrollTop = row.offsetTop + row.offsetHeight - viewport;
  1192. }
  1193. }
  1194. function headlineActionsChange(elem) {
  1195. eval(elem.value);
  1196. elem.attr('value', 'false');
  1197. }
  1198. function closeArticlePanel() {
  1199. if (dijit.byId("content-insert"))
  1200. dijit.byId("headlines-wrap-inner").removeChild(
  1201. dijit.byId("content-insert"));
  1202. }
  1203. function initFloatingMenu() {
  1204. if (!dijit.byId("floatingMenu")) {
  1205. var menu = new dijit.Menu({
  1206. id: "floatingMenu",
  1207. targetNodeIds: ["floatingTitle"]
  1208. });
  1209. headlinesMenuCommon(menu);
  1210. menu.startup();
  1211. }
  1212. }
  1213. function headlinesMenuCommon(menu) {
  1214. menu.addChild(new dijit.MenuItem({
  1215. label: __("Open original article"),
  1216. onClick: function (event) {
  1217. openArticleInNewWindow(this.getParent().currentTarget.getAttribute("data-article-id"));
  1218. }
  1219. }));
  1220. menu.addChild(new dijit.MenuItem({
  1221. label: __("Display article URL"),
  1222. onClick: function (event) {
  1223. displayArticleUrl(this.getParent().currentTarget.getAttribute("data-article-id"));
  1224. }
  1225. }));
  1226. menu.addChild(new dijit.MenuSeparator());
  1227. menu.addChild(new dijit.MenuItem({
  1228. label: __("Toggle unread"),
  1229. onClick: function (event) {
  1230. var ids = getSelectedArticleIds2();
  1231. // cast to string
  1232. var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
  1233. ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
  1234. selectionToggleUnread(undefined, false, true, ids);
  1235. }
  1236. }));
  1237. menu.addChild(new dijit.MenuItem({
  1238. label: __("Toggle starred"),
  1239. onClick: function (event) {
  1240. var ids = getSelectedArticleIds2();
  1241. // cast to string
  1242. var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
  1243. ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
  1244. selectionToggleMarked(undefined, false, true, ids);
  1245. }
  1246. }));
  1247. menu.addChild(new dijit.MenuItem({
  1248. label: __("Toggle published"),
  1249. onClick: function (event) {
  1250. var ids = getSelectedArticleIds2();
  1251. // cast to string
  1252. var id = (this.getParent().currentTarget.getAttribute("data-article-id")) + "";
  1253. ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
  1254. selectionTogglePublished(undefined, false, true, ids);
  1255. }
  1256. }));
  1257. menu.addChild(new dijit.MenuSeparator());
  1258. menu.addChild(new dijit.MenuItem({
  1259. label: __("Mark above as read"),
  1260. onClick: function (event) {
  1261. catchupRelativeToArticle(0, this.getParent().currentTarget.getAttribute("data-article-id"));
  1262. }
  1263. }));
  1264. menu.addChild(new dijit.MenuItem({
  1265. label: __("Mark below as read"),
  1266. onClick: function (event) {
  1267. catchupRelativeToArticle(1, this.getParent().currentTarget.getAttribute("data-article-id"));
  1268. }
  1269. }));
  1270. var labels = getInitParam("labels");
  1271. if (labels && labels.length) {
  1272. menu.addChild(new dijit.MenuSeparator());
  1273. var labelAddMenu = new dijit.Menu({ownerMenu: menu});
  1274. var labelDelMenu = new dijit.Menu({ownerMenu: menu});
  1275. labels.each(function (label) {
  1276. var bare_id = label.id;
  1277. var name = label.caption;
  1278. labelAddMenu.addChild(new dijit.MenuItem({
  1279. label: name,
  1280. labelId: bare_id,
  1281. onClick: function (event) {
  1282. var ids = getSelectedArticleIds2();
  1283. // cast to string
  1284. var id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
  1285. ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
  1286. selectionAssignLabel(this.labelId, ids);
  1287. }
  1288. }));
  1289. labelDelMenu.addChild(new dijit.MenuItem({
  1290. label: name,
  1291. labelId: bare_id,
  1292. onClick: function (event) {
  1293. var ids = getSelectedArticleIds2();
  1294. // cast to string
  1295. var id = (this.getParent().ownerMenu.currentTarget.getAttribute("data-article-id")) + "";
  1296. ids = ids.size() != 0 && ids.indexOf(id) != -1 ? ids : [id];
  1297. selectionRemoveLabel(this.labelId, ids);
  1298. }
  1299. }));
  1300. });
  1301. menu.addChild(new dijit.PopupMenuItem({
  1302. label: __("Assign label"),
  1303. popup: labelAddMenu
  1304. }));
  1305. menu.addChild(new dijit.PopupMenuItem({
  1306. label: __("Remove label"),
  1307. popup: labelDelMenu
  1308. }));
  1309. }
  1310. }
  1311. function initHeadlinesMenu() {
  1312. if (!dijit.byId("headlinesMenu")) {
  1313. var menu = new dijit.Menu({
  1314. id: "headlinesMenu",
  1315. targetNodeIds: ["headlines-frame"],
  1316. selector: ".hlMenuAttach"
  1317. });
  1318. headlinesMenuCommon(menu);
  1319. menu.startup();
  1320. }
  1321. /* vgroup feed title menu */
  1322. if (!dijit.byId("headlinesFeedTitleMenu")) {
  1323. var menu = new dijit.Menu({
  1324. id: "headlinesFeedTitleMenu",
  1325. targetNodeIds: ["headlines-frame"],
  1326. selector: "div.cdmFeedTitle"
  1327. });
  1328. menu.addChild(new dijit.MenuItem({
  1329. label: __("Select articles in group"),
  1330. onClick: function (event) {
  1331. selectArticles("all",
  1332. "#headlines-frame > div[id*=RROW]" +
  1333. "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']");
  1334. }
  1335. }));
  1336. menu.addChild(new dijit.MenuItem({
  1337. label: __("Mark group as read"),
  1338. onClick: function (event) {
  1339. selectArticles("none");
  1340. selectArticles("all",
  1341. "#headlines-frame > div[id*=RROW]" +
  1342. "[data-orig-feed-id='" + this.getParent().currentTarget.getAttribute("data-feed-id") + "']");
  1343. catchupSelection();
  1344. }
  1345. }));
  1346. menu.addChild(new dijit.MenuItem({
  1347. label: __("Mark feed as read"),
  1348. onClick: function (event) {
  1349. catchupFeedInGroup(this.getParent().currentTarget.getAttribute("data-feed-id"));
  1350. }
  1351. }));
  1352. menu.addChild(new dijit.MenuItem({
  1353. label: __("Edit feed"),
  1354. onClick: function (event) {
  1355. editFeed(this.getParent().currentTarget.getAttribute("data-feed-id"));
  1356. }
  1357. }));
  1358. menu.startup();
  1359. }
  1360. }
  1361. function cache_set(id, obj) {
  1362. //console.log("cache_set: " + id);
  1363. if (has_storage)
  1364. try {
  1365. sessionStorage[id] = obj;
  1366. } catch (e) {
  1367. sessionStorage.clear();
  1368. }
  1369. }
  1370. function cache_get(id) {
  1371. if (has_storage)
  1372. return sessionStorage[id];
  1373. }
  1374. function cache_clear() {
  1375. if (has_storage)
  1376. sessionStorage.clear();
  1377. }
  1378. function cache_delete(id) {
  1379. if (has_storage)
  1380. sessionStorage.removeItem(id);
  1381. }
  1382. function cancelSearch() {
  1383. _search_query = "";
  1384. viewCurrentFeed();
  1385. }
  1386. function setSelectionScore() {
  1387. var ids = getSelectedArticleIds2();
  1388. if (ids.length > 0) {
  1389. console.log(ids);
  1390. var score = prompt(__("Please enter new score for selected articles:"), score);
  1391. if (score != undefined) {
  1392. var query = "op=article&method=setScore&id=" + param_escape(ids.toString()) +
  1393. "&score=" + param_escape(score);
  1394. new Ajax.Request("backend.php", {
  1395. parameters: query,
  1396. onComplete: function (transport) {
  1397. var reply = JSON.parse(transport.responseText);
  1398. if (reply) {
  1399. console.log(ids);
  1400. ids.each(function (id) {
  1401. var row = $("RROW-" + id);
  1402. if (row) {
  1403. var pic = row.getElementsByClassName("hlScorePic")[0];
  1404. if (pic) {
  1405. pic.src = pic.src.replace(/score_.*?\.png/,
  1406. reply["score_pic"]);
  1407. pic.setAttribute("score", score);
  1408. }
  1409. }
  1410. });
  1411. }
  1412. }
  1413. });
  1414. }
  1415. } else {
  1416. alert(__("No articles are selected."));
  1417. }
  1418. }
  1419. function updateScore(id) {
  1420. var pic = $$("#RROW-" + id + " .hlScorePic")[0];
  1421. if (pic) {
  1422. var query = "op=article&method=getScore&id=" + param_escape(id);
  1423. new Ajax.Request("backend.php", {
  1424. parameters: query,
  1425. onComplete: function (transport) {
  1426. console.log(transport.responseText);
  1427. var reply = JSON.parse(transport.responseText);
  1428. if (reply) {
  1429. pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
  1430. pic.setAttribute("score", reply["score"]);
  1431. pic.setAttribute("title", reply["score"]);
  1432. }
  1433. }
  1434. });
  1435. }
  1436. }
  1437. function changeScore(id, pic) {
  1438. var score = pic.getAttribute("score");
  1439. var new_score = prompt(__("Please enter new score for this article:"), score);
  1440. if (new_score != undefined) {
  1441. var query = "op=article&method=setScore&id=" + param_escape(id) +
  1442. "&score=" + param_escape(new_score);
  1443. new Ajax.Request("backend.php", {
  1444. parameters: query,
  1445. onComplete: function (transport) {
  1446. var reply = JSON.parse(transport.responseText);
  1447. if (reply) {
  1448. pic.src = pic.src.replace(/score_.*?\.png/, reply["score_pic"]);
  1449. pic.setAttribute("score", new_score);
  1450. pic.setAttribute("title", new_score);
  1451. }
  1452. }
  1453. });
  1454. }
  1455. }
  1456. function displayArticleUrl(id) {
  1457. var query = "op=rpc&method=getlinktitlebyid&id=" + param_escape(id);
  1458. new Ajax.Request("backend.php", {
  1459. parameters: query,
  1460. onComplete: function (transport) {
  1461. var reply = JSON.parse(transport.responseText);
  1462. if (reply && reply.link) {
  1463. prompt(__("Article URL:"), reply.link);
  1464. }
  1465. }
  1466. });
  1467. }
  1468. function scrollToRowId(id) {
  1469. var row = $(id);
  1470. if (row)
  1471. $("headlines-frame").scrollTop = row.offsetTop - 4;
  1472. }
  1473. function updateFloatingTitle(unread_only) {
  1474. if (!isCdmMode()) return;
  1475. var hf = $("headlines-frame");
  1476. var elems = $$("#headlines-frame > div[id*=RROW]");
  1477. for (var i = 0; i < elems.length; i++) {
  1478. var child = elems[i];
  1479. if (child && child.offsetTop + child.offsetHeight > hf.scrollTop) {
  1480. var header = child.getElementsByClassName("cdmHeader")[0];
  1481. if (unread_only || child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
  1482. if (child.getAttribute("data-article-id") != $("floatingTitle").getAttribute("data-article-id")) {
  1483. $("floatingTitle").setAttribute("data-article-id", child.getAttribute("data-article-id"));
  1484. $("floatingTitle").innerHTML = header.innerHTML;
  1485. $("floatingTitle").firstChild.innerHTML = "<img class='anchor markedPic' src='images/page_white_go.png' onclick=\"scrollToRowId('" + child.id + "')\">" + $("floatingTitle").firstChild.innerHTML;
  1486. initFloatingMenu();
  1487. var cb = $$("#floatingTitle .dijitCheckBox")[0];
  1488. if (cb)
  1489. cb.parentNode.removeChild(cb);
  1490. }
  1491. if (child.hasClassName("Unread"))
  1492. $("floatingTitle").addClassName("Unread");
  1493. else
  1494. $("floatingTitle").removeClassName("Unread");
  1495. PluginHost.run(PluginHost.HOOK_FLOATING_TITLE, child);
  1496. }
  1497. $("floatingTitle").style.marginRight = hf.offsetWidth - child.offsetWidth + "px";
  1498. if (header.offsetTop + header.offsetHeight < hf.scrollTop + $("floatingTitle").offsetHeight - 5 &&
  1499. child.offsetTop + child.offsetHeight >= hf.scrollTop + $("floatingTitle").offsetHeight - 5)
  1500. $("floatingTitle").style.visibility = "visible";
  1501. else
  1502. $("floatingTitle").style.visibility = "hidden";
  1503. return;
  1504. }
  1505. }
  1506. }
  1507. function catchupCurrentBatchIfNeeded() {
  1508. if (catchup_id_batch.length > 0) {
  1509. window.clearTimeout(catchup_timeout_id);
  1510. catchup_timeout_id = window.setTimeout(catchupBatchedArticles, 1000);
  1511. if (catchup_id_batch.length >= 10) {
  1512. catchupBatchedArticles();
  1513. }
  1514. }
  1515. }
  1516. function cdmFooterClick(event) {
  1517. event.stopPropagation();
  1518. }