viewfeed.js 54 KB

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