viewfeed.js 54 KB

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