viewfeed.js 47 KB

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