viewfeed.js 47 KB

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