viewfeed.js 55 KB

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