viewfeed.js 52 KB

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