main.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. "use strict";
  2. /* globals $, jQuery, context, i18n, shortcut, shortcuts, url */
  3. /* jshint strict:global */
  4. var $stream = null,
  5. isCollapsed = true,
  6. shares = 0,
  7. ajax_loading = false;
  8. function redirect(url, new_tab) {
  9. if (url) {
  10. if (new_tab) {
  11. window.open(url);
  12. } else {
  13. location.href = url;
  14. }
  15. }
  16. }
  17. function needsScroll($elem) {
  18. var $win = $(window),
  19. winTop = $win.scrollTop(),
  20. winHeight = $win.height(),
  21. winBottom = winTop + winHeight,
  22. elemTop = $elem.offset().top,
  23. elemBottom = elemTop + $elem.outerHeight();
  24. return (elemTop < winTop || elemBottom > winBottom) ? elemTop - (winHeight / 2) : 0;
  25. }
  26. function str2int(str) {
  27. if (!str) {
  28. return 0;
  29. }
  30. return parseInt(str.replace(/\D/g, ''), 10) || 0;
  31. }
  32. function numberFormat(nStr) {
  33. if (nStr < 0) {
  34. return 0;
  35. }
  36. // http://www.mredkj.com/javascript/numberFormat.html
  37. nStr += '';
  38. var x = nStr.split('.'),
  39. x1 = x[0],
  40. x2 = x.length > 1 ? '.' + x[1] : '',
  41. rgx = /(\d+)(\d{3})/;
  42. while (rgx.test(x1)) {
  43. x1 = x1.replace(rgx, '$1' + ' ' + '$2');
  44. }
  45. return x1 + x2;
  46. }
  47. function incLabel(p, inc, spaceAfter) {
  48. var i = str2int(p) + inc;
  49. return i > 0 ? ((spaceAfter ? '' : ' ') + '(' + numberFormat(i) + ')' + (spaceAfter ? ' ' : '')) : '';
  50. }
  51. function incUnreadsFeed(article, feed_id, nb) {
  52. //Update unread: feed
  53. var elem = $('#' + feed_id).get(0),
  54. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0,
  55. feed_priority = elem ? str2int(elem.getAttribute('data-priority')) : 0;
  56. if (elem) {
  57. elem.setAttribute('data-unread', feed_unreads + nb);
  58. elem = $(elem).children('.item-title').get(0);
  59. if (elem) {
  60. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  61. }
  62. }
  63. //Update unread: category
  64. elem = $('#' + feed_id).parents('.category').get(0);
  65. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  66. if (elem) {
  67. elem.setAttribute('data-unread', feed_unreads + nb);
  68. elem = $(elem).find('.title').get(0);
  69. if (elem) {
  70. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  71. }
  72. }
  73. //Update unread: all
  74. if (feed_priority > 0) {
  75. elem = $('#aside_feed .all .title').get(0);
  76. if (elem) {
  77. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  78. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  79. }
  80. }
  81. //Update unread: favourites
  82. if (article && article.closest('div').hasClass('favorite')) {
  83. elem = $('#aside_feed .favorites .title').get(0);
  84. if (elem) {
  85. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  86. elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
  87. }
  88. }
  89. var isCurrentView = false;
  90. // Update unread: title
  91. document.title = document.title.replace(/^((?:\([ 0-9]+\) )?)/, function (m, p1) {
  92. var $feed = $('#' + feed_id);
  93. if (article || ($feed.closest('.active').length > 0 && $feed.siblings('.active').length === 0)) {
  94. isCurrentView = true;
  95. return incLabel(p1, nb, true);
  96. } else if ($('.all.active').length > 0) {
  97. isCurrentView = feed_priority > 0;
  98. return incLabel(p1, feed_priority > 0 ? nb : 0, true);
  99. } else {
  100. return p1;
  101. }
  102. });
  103. return isCurrentView;
  104. }
  105. var pending_entries = {};
  106. function mark_read(active, only_not_read) {
  107. if ((active.length === 0) || (!active.attr('id')) ||
  108. context.anonymous ||
  109. (only_not_read && !active.hasClass("not_read"))) {
  110. return false;
  111. }
  112. if (pending_entries[active.attr('id')]) {
  113. return false;
  114. }
  115. pending_entries[active.attr('id')] = true;
  116. var url = '.?c=entry&a=read&id=' + active.attr('id').replace(/^flux_/, '') +
  117. (active.hasClass('not_read') ? '' : '&is_read=0');
  118. $.ajax({
  119. type: 'POST',
  120. url: url,
  121. data: {
  122. ajax: true,
  123. _csrf: context.csrf,
  124. },
  125. }).done(function (data) {
  126. var $r = active.find("a.read").attr("href", data.url),
  127. inc = 0;
  128. if (active.hasClass("not_read")) {
  129. active.removeClass("not_read");
  130. inc--;
  131. } else {
  132. active.addClass("not_read");
  133. active.addClass("keep_unread");
  134. inc++;
  135. }
  136. $r.find('.icon').replaceWith(data.icon);
  137. var feed_url = active.find(".website>a").attr("href");
  138. if (feed_url) {
  139. var feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
  140. incUnreadsFeed(active, feed_id, inc);
  141. }
  142. faviconNbUnread();
  143. delete pending_entries[active.attr('id')];
  144. }).fail(function (data) {
  145. openNotification(i18n.notif_request_failed, 'bad');
  146. delete pending_entries[active.attr('id')];
  147. });
  148. }
  149. function mark_favorite(active) {
  150. if (active.length === 0) {
  151. return false;
  152. }
  153. var url = active.find("a.bookmark").attr("href");
  154. if (url === undefined) {
  155. return false;
  156. }
  157. if (pending_entries[active.attr('id')]) {
  158. return false;
  159. }
  160. pending_entries[active.attr('id')] = true;
  161. $.ajax({
  162. type: 'POST',
  163. url: url,
  164. data: {
  165. ajax: true,
  166. _csrf: context.csrf,
  167. },
  168. }).done(function (data) {
  169. var $b = active.find("a.bookmark").attr("href", data.url),
  170. inc = 0;
  171. if (active.hasClass("favorite")) {
  172. active.removeClass("favorite");
  173. inc--;
  174. } else {
  175. active.addClass("favorite").find('.bookmark');
  176. inc++;
  177. }
  178. $b.find('.icon').replaceWith(data.icon);
  179. var favourites = $('#aside_feed .favorites .title').contents().last().get(0);
  180. if (favourites && favourites.textContent) {
  181. favourites.textContent = favourites.textContent.replace(/((?: \([ 0-9]+\))?\s*)$/, function (m, p1) {
  182. return incLabel(p1, inc, false);
  183. });
  184. }
  185. if (active.closest('div').hasClass('not_read')) {
  186. var elem = $('#aside_feed .favorites .title').get(0),
  187. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  188. if (elem) {
  189. elem.setAttribute('data-unread', numberFormat(feed_unreads + inc));
  190. }
  191. }
  192. delete pending_entries[active.attr('id')];
  193. }).fail(function (data) {
  194. openNotification(i18n.notif_request_failed, 'bad');
  195. delete pending_entries[active.attr('id')];
  196. });
  197. }
  198. function toggleContent(new_active, old_active) {
  199. if (new_active.length === 0) {
  200. return;
  201. }
  202. if (context.does_lazyload) {
  203. new_active.find('img[data-original], iframe[data-original]').each(function () {
  204. this.onload = function () { $(document.body).trigger("sticky_kit:recalc"); };
  205. this.setAttribute('src', this.getAttribute('data-original'));
  206. this.removeAttribute('data-original');
  207. });
  208. }
  209. if (old_active[0] !== new_active[0]) {
  210. if (isCollapsed) {
  211. new_active.addClass("active");
  212. }
  213. old_active.removeClass("active current");
  214. new_active.addClass("current");
  215. if (context.auto_remove_article && !old_active.hasClass('not_read')) {
  216. auto_remove(old_active);
  217. }
  218. } else {
  219. new_active.toggleClass('active');
  220. }
  221. var relative_move = context.current_view === 'global',
  222. box_to_move = $(relative_move ? "#panel" : "html,body");
  223. if (context.sticky_post) {
  224. var prev_article = new_active.prevAll('.flux'),
  225. new_pos = new_active.offset().top,
  226. old_scroll = box_to_move.scrollTop();
  227. if (prev_article.length > 0 && new_pos - prev_article.offset().top <= 150) {
  228. new_pos = prev_article.offset().top;
  229. if (relative_move) {
  230. new_pos -= box_to_move.offset().top;
  231. }
  232. }
  233. if (context.hide_posts) {
  234. if (relative_move) {
  235. new_pos += old_scroll;
  236. }
  237. new_active.children(".flux_content").first().each(function () {
  238. box_to_move.scrollTop(new_pos).scrollTop();
  239. });
  240. } else {
  241. if (relative_move) {
  242. new_pos += old_scroll;
  243. }
  244. box_to_move.scrollTop(new_pos).scrollTop();
  245. }
  246. }
  247. if (context.auto_mark_article && new_active.hasClass('active')) {
  248. mark_read(new_active, true);
  249. }
  250. }
  251. function auto_remove(element) {
  252. var p = element.prev();
  253. var n = element.next();
  254. if (p.hasClass('day') && n.hasClass('day')) {
  255. p.remove();
  256. }
  257. element.remove();
  258. $('#stream > .flux:not(.not_read):not(.active)').remove();
  259. }
  260. function prev_entry() {
  261. var old_active = $(".flux.current"),
  262. new_active = old_active.length === 0 ? $(".flux:last") : old_active.prevAll(".flux:first");
  263. toggleContent(new_active, old_active);
  264. }
  265. function next_entry() {
  266. var old_active = $(".flux.current"),
  267. new_active = old_active.length === 0 ? $(".flux:first") : old_active.nextAll(".flux:first");
  268. toggleContent(new_active, old_active);
  269. if (new_active.nextAll().length < 3) {
  270. load_more_posts();
  271. }
  272. }
  273. function prev_feed() {
  274. var active_feed = $("#aside_feed .tree-folder-items .item.active");
  275. if (active_feed.length > 0) {
  276. active_feed.prevAll(':visible:first').find('a').each(function(){this.click();});
  277. } else {
  278. last_feed();
  279. }
  280. }
  281. function next_feed() {
  282. var active_feed = $("#aside_feed .tree-folder-items .item.active");
  283. if (active_feed.length > 0) {
  284. active_feed.nextAll(':visible:first').find('a').each(function(){this.click();});
  285. } else {
  286. first_feed();
  287. }
  288. }
  289. function first_feed() {
  290. var feed = $("#aside_feed .tree-folder-items.active .item:visible:first");
  291. if (feed.length > 0) {
  292. feed.find('a')[1].click();
  293. }
  294. }
  295. function last_feed() {
  296. var feed = $("#aside_feed .tree-folder-items.active .item:visible:last");
  297. if (feed.length > 0) {
  298. feed.find('a')[1].click();
  299. }
  300. }
  301. function prev_category() {
  302. var active_cat = $("#aside_feed .tree-folder.active");
  303. if (active_cat.length > 0) {
  304. var prev_cat = active_cat.prevAll(':visible:first').find('.tree-folder-title .title');
  305. if (prev_cat.length > 0) {
  306. prev_cat[0].click();
  307. }
  308. } else {
  309. last_category();
  310. }
  311. return;
  312. }
  313. function next_category() {
  314. var active_cat = $("#aside_feed .tree-folder.active");
  315. if (active_cat.length > 0) {
  316. var next_cat = active_cat.nextAll(':visible:first').find('.tree-folder-title .title');
  317. if (next_cat.length > 0) {
  318. next_cat[0].click();
  319. }
  320. } else {
  321. first_category();
  322. }
  323. return;
  324. }
  325. function first_category() {
  326. var cat = $("#aside_feed .tree-folder:visible:first");
  327. if (cat.length > 0) {
  328. cat.find('.tree-folder-title .title')[0].click();
  329. }
  330. }
  331. function last_category() {
  332. var cat = $("#aside_feed .tree-folder:visible:last");
  333. if (cat.length > 0) {
  334. cat.find('.tree-folder-title .title')[0].click();
  335. }
  336. }
  337. function collapse_entry() {
  338. var flux_current = $(".flux.current");
  339. toggleContent(flux_current, flux_current);
  340. }
  341. function user_filter(key) {
  342. var filter = $('#dropdown-query');
  343. var filters = filter.siblings('.dropdown-menu').find('.item.query a');
  344. if (typeof key === "undefined") {
  345. if (!filter.length) {
  346. return;
  347. }
  348. // Display the filter div
  349. window.location.hash = filter.attr('id');
  350. // Force scrolling to the filter div
  351. var scroll = needsScroll($('.header'));
  352. if (scroll !== 0) {
  353. $('html,body').scrollTop(scroll);
  354. }
  355. // Force the key value if there is only one action, so we can trigger it automatically
  356. if (filters.length === 1) {
  357. key = 1;
  358. } else {
  359. return;
  360. }
  361. }
  362. // Trigger selected share action
  363. key = parseInt(key);
  364. if (key <= filters.length) {
  365. filters[key - 1].click();
  366. }
  367. }
  368. function auto_share(key) {
  369. var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]');
  370. var shares = share.siblings('.dropdown-menu').find('.item a');
  371. if (typeof key === "undefined") {
  372. if (!share.length) {
  373. return;
  374. }
  375. // Display the share div
  376. window.location.hash = share.attr('id');
  377. // Force scrolling to the share div
  378. var scroll = needsScroll(share.closest('.bottom'));
  379. if (scroll !== 0) {
  380. $('html,body').scrollTop(scroll);
  381. }
  382. // Force the key value if there is only one action, so we can trigger it automatically
  383. if (shares.length === 1) {
  384. key = 1;
  385. } else {
  386. return;
  387. }
  388. }
  389. // Trigger selected share action and hide the share div
  390. key = parseInt(key);
  391. if (key <= shares.length) {
  392. shares[key - 1].click();
  393. share.siblings('.dropdown-menu').find('.dropdown-close a')[0].click();
  394. }
  395. }
  396. function scrollAsRead(box_to_follow) {
  397. var minTop = 40 + (context.current_view === 'global' ? box_to_follow.offset().top : box_to_follow.scrollTop());
  398. $('.not_read:not(.keep_unread):visible').each(function () {
  399. var $this = $(this);
  400. if ($this.offset().top + $this.height() < minTop) {
  401. mark_read($this, true);
  402. }
  403. });
  404. }
  405. function init_posts() {
  406. var box_to_follow = context.current_view === 'global' ? $("#panel") : $(window);
  407. if (context.auto_mark_scroll) {
  408. var lastScroll = 0, //Throttle
  409. timerId = 0;
  410. box_to_follow.scroll(function () {
  411. window.clearTimeout(timerId);
  412. if (lastScroll + 500 < Date.now()) {
  413. lastScroll = Date.now();
  414. scrollAsRead(box_to_follow);
  415. } else {
  416. timerId = window.setTimeout(function() {
  417. scrollAsRead(box_to_follow);
  418. }, 500);
  419. }
  420. });
  421. }
  422. if (context.auto_load_more) {
  423. box_to_follow.scroll(function () {
  424. var load_more = $("#load_more");
  425. if (!load_more.is(':visible')) {
  426. return;
  427. }
  428. var boxBot = box_to_follow.scrollTop() + box_to_follow.height(),
  429. load_more_top = load_more.offset().top;
  430. if (boxBot >= load_more_top) {
  431. load_more_posts();
  432. }
  433. });
  434. box_to_follow.scroll();
  435. }
  436. }
  437. function inject_script(name) {
  438. var script = document.createElement('script');
  439. script.async = 'async';
  440. script.defer = 'defer';
  441. script.src = '../scripts/' + name;
  442. document.head.appendChild(script);
  443. }
  444. function init_sticky_column() {
  445. if (!window.$ || !window.$.fn.stick_in_parent) {
  446. if (window.console) {
  447. console.log('FreshRSS waiting for Sticky-kit…');
  448. }
  449. window.setTimeout(init_sticky_column, 200);
  450. return;
  451. }
  452. if ($('.toggle_aside').css('display') === 'none') {
  453. $('#aside_feed .tree').stick_in_parent({parent:'#aside_feed'});
  454. }
  455. }
  456. function init_column_categories() {
  457. if (context.current_view !== 'normal') {
  458. return;
  459. }
  460. $('#aside_feed').on('click', '.tree-folder>.tree-folder-title>a.dropdown-toggle', function () {
  461. $(this).children().each(function() {
  462. if (this.alt === '▽') {
  463. this.src = this.src.replace('/icons/down.', '/icons/up.');
  464. this.alt = '△';
  465. } else {
  466. this.src = this.src.replace('/icons/up.', '/icons/down.');
  467. this.alt = '▽';
  468. }
  469. });
  470. $(this).parent().next(".tree-folder-items").slideToggle(300 , function() { $(document.body).trigger("sticky_kit:recalc"); });
  471. return false;
  472. });
  473. $('#aside_feed').on('click', '.tree-folder-items .item .dropdown-toggle', function () {
  474. if ($(this).nextAll('.dropdown-menu').length === 0) {
  475. var feed_id = $(this).closest('.item').attr('id').substr(2),
  476. feed_web = $(this).data('fweb'),
  477. template = $('#feed_config_template').html().replace(/------/g, feed_id).replace('http://example.net/', feed_web);
  478. $(this).attr('href', '#dropdown-' + feed_id).prev('.dropdown-target').attr('id', 'dropdown-' + feed_id).parent().append(template);
  479. $('.tree-folder-items .dropdown-close a').click(function(){
  480. $('.tree').removeClass('treepadding');
  481. $(document.body).trigger("sticky_kit:recalc");
  482. });
  483. }
  484. });
  485. $('.tree-folder-items .dropdown-toggle').click(function(){
  486. $('.tree').addClass('treepadding');
  487. $(document.body).trigger("sticky_kit:recalc");
  488. });
  489. init_sticky_column();
  490. }
  491. function init_shortcuts() {
  492. if (!(window.shortcut && window.shortcuts)) {
  493. if (window.console) {
  494. console.log('FreshRSS waiting for sortcut.js…');
  495. }
  496. window.setTimeout(init_shortcuts, 200);
  497. return;
  498. }
  499. // Manipulation shortcuts
  500. shortcut.add(shortcuts.mark_read, function () {
  501. // Toggle the read state
  502. var active = $(".flux.current");
  503. mark_read(active, false);
  504. }, {
  505. 'disable_in_input': true
  506. });
  507. shortcut.add("shift+" + shortcuts.mark_read, function () {
  508. // Mark everything as read
  509. $(".nav_menu .read_all").click();
  510. }, {
  511. 'disable_in_input': true
  512. });
  513. shortcut.add(shortcuts.mark_favorite, function () {
  514. // Toggle the favorite state
  515. var active = $(".flux.current");
  516. mark_favorite(active);
  517. }, {
  518. 'disable_in_input': true
  519. });
  520. shortcut.add(shortcuts.collapse_entry, function () {
  521. // Toggle the collapse state
  522. collapse_entry();
  523. }, {
  524. 'disable_in_input': true
  525. });
  526. shortcut.add(shortcuts.auto_share, function () {
  527. // Display the share options
  528. auto_share();
  529. }, {
  530. 'disable_in_input': true
  531. });
  532. shortcut.add(shortcuts.user_filter, function () {
  533. // Display the user filters
  534. user_filter();
  535. }, {
  536. 'disable_in_input': true
  537. });
  538. function addShortcut(evt) {
  539. if ($('#dropdown-query').siblings('.dropdown-menu').is(':visible')) {
  540. user_filter(String.fromCharCode(evt.keyCode));
  541. } else {
  542. auto_share(String.fromCharCode(evt.keyCode));
  543. }
  544. }
  545. for(var i = 1; i < 10; i++) {
  546. shortcut.add(i.toString(), addShortcut, {
  547. 'disable_in_input': true
  548. });
  549. }
  550. // Entry navigation shortcuts
  551. shortcut.add(shortcuts.prev_entry, prev_entry, {
  552. 'disable_in_input': true
  553. });
  554. shortcut.add(shortcuts.first_entry, function () {
  555. var old_active = $(".flux.current"),
  556. first = $(".flux:first");
  557. if (first.hasClass("flux")) {
  558. toggleContent(first, old_active);
  559. }
  560. }, {
  561. 'disable_in_input': true
  562. });
  563. shortcut.add(shortcuts.next_entry, next_entry, {
  564. 'disable_in_input': true
  565. });
  566. shortcut.add(shortcuts.last_entry, function () {
  567. var old_active = $(".flux.current"),
  568. last = $(".flux:last");
  569. if (last.hasClass("flux")) {
  570. toggleContent(last, old_active);
  571. }
  572. }, {
  573. 'disable_in_input': true
  574. });
  575. // Feed navigation shortcuts
  576. shortcut.add("shift+" + shortcuts.prev_entry, prev_feed, {
  577. 'disable_in_input': true
  578. });
  579. shortcut.add("shift+" + shortcuts.next_entry, next_feed, {
  580. 'disable_in_input': true
  581. });
  582. shortcut.add("shift+" + shortcuts.first_entry, first_feed, {
  583. 'disable_in_input': true
  584. });
  585. shortcut.add("shift+" + shortcuts.last_entry, last_feed, {
  586. 'disable_in_input': true
  587. });
  588. // Category navigation shortcuts
  589. shortcut.add("alt+" + shortcuts.prev_entry, prev_category, {
  590. 'disable_in_input': true
  591. });
  592. shortcut.add("alt+" + shortcuts.next_entry, next_category, {
  593. 'disable_in_input': true
  594. });
  595. shortcut.add("alt+" + shortcuts.first_entry, first_category, {
  596. 'disable_in_input': true
  597. });
  598. shortcut.add("alt+" + shortcuts.last_entry, last_category, {
  599. 'disable_in_input': true
  600. });
  601. shortcut.add(shortcuts.go_website, function () {
  602. var url_website = $('.flux.current a.go_website').attr("href");
  603. if (context.auto_mark_site) {
  604. $(".flux.current").each(function () {
  605. mark_read($(this), true);
  606. });
  607. }
  608. redirect(url_website, true);
  609. }, {
  610. 'disable_in_input': true
  611. });
  612. shortcut.add(shortcuts.load_more, function () {
  613. load_more_posts();
  614. }, {
  615. 'disable_in_input': true
  616. });
  617. shortcut.add(shortcuts.focus_search, function () {
  618. focus_search();
  619. }, {
  620. 'disable_in_input': true
  621. });
  622. shortcut.add(shortcuts.help, function () {
  623. redirect(url.help, true);
  624. }, {
  625. 'disable_in_input': true
  626. });
  627. shortcut.add(shortcuts.close_dropdown, function () {
  628. window.location.hash = null;
  629. }, {
  630. 'disable_in_input': true
  631. });
  632. }
  633. function init_stream(divStream) {
  634. divStream.on('click', '.flux_header,.flux_content', function (e) { //flux_toggle
  635. if ($(e.target).closest('.content, .item.website, .item.link').length > 0) {
  636. return;
  637. }
  638. if (!context.sides_close_article && $(e.target).is('div.flux_content')) {
  639. // setting for not-closing after clicking outside article area
  640. return;
  641. }
  642. var old_active = $(".flux.current"),
  643. new_active = $(this).parent();
  644. isCollapsed = true;
  645. if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone
  646. if (context.auto_mark_article) {
  647. mark_read(new_active, true);
  648. }
  649. return true;
  650. }
  651. toggleContent(new_active, old_active);
  652. });
  653. divStream.on('click', '.flux a.read', function () {
  654. var active = $(this).parents(".flux");
  655. if (context.auto_remove_article && active.hasClass('not_read')) {
  656. auto_remove(active);
  657. }
  658. mark_read(active, false);
  659. return false;
  660. });
  661. divStream.on('click', '.flux a.bookmark', function () {
  662. var active = $(this).parents(".flux");
  663. mark_favorite(active);
  664. return false;
  665. });
  666. divStream.on('click', '.item.title > a', function (e) {
  667. // Allow default control-click behaviour such as open in backround-tab.
  668. return e.ctrlKey;
  669. });
  670. divStream.on('mouseup', '.item.title > a', function (e) {
  671. // Mouseup enables us to catch middle click.
  672. if (e.ctrlKey) {
  673. // CTRL+click, it will be manage by previous rule.
  674. return;
  675. }
  676. if (e.which == 2) {
  677. // If middle click, we want same behaviour as CTRL+click.
  678. var ev = jQuery.Event("click");
  679. ev.ctrlKey = true;
  680. $(this).trigger(ev);
  681. } else if(e.which == 1) {
  682. // Normal click, just toggle article.
  683. $(this).parent().click();
  684. }
  685. });
  686. divStream.on('click', '.flux .content a', function () {
  687. $(this).attr('target', '_blank').attr('rel', 'noreferrer');
  688. });
  689. if (context.auto_mark_site) {
  690. // catch mouseup instead of click so we can have the correct behaviour
  691. // with middle button click (scroll button).
  692. divStream.on('mouseup', '.flux .link > a', function (e) {
  693. if (e.which == 3) {
  694. return;
  695. }
  696. mark_read($(this).parents(".flux"), true);
  697. });
  698. }
  699. }
  700. function init_nav_entries() {
  701. var $nav_entries = $('#nav_entries');
  702. $nav_entries.find('.previous_entry').click(function () {
  703. prev_entry();
  704. return false;
  705. });
  706. $nav_entries.find('.next_entry').click(function () {
  707. next_entry();
  708. return false;
  709. });
  710. $nav_entries.find('.up').click(function () {
  711. var active_item = $(".flux.current"),
  712. windowTop = $(window).scrollTop(),
  713. item_top = active_item.offset().top;
  714. if (windowTop > item_top) {
  715. $("html,body").scrollTop(item_top);
  716. } else {
  717. $("html,body").scrollTop(0);
  718. }
  719. return false;
  720. });
  721. }
  722. // <actualize>
  723. var feed_processed = 0;
  724. function updateFeed(feeds, feeds_count) {
  725. var feed = feeds.pop();
  726. if (!feed) {
  727. return;
  728. }
  729. $.ajax({
  730. type: 'POST',
  731. url: feed.url,
  732. data: {
  733. _csrf: context.csrf,
  734. noCommit: feeds.length > 0 ? 1 : 0,
  735. },
  736. }).always(function (data) {
  737. feed_processed++;
  738. $("#actualizeProgress .progress").html(feed_processed + " / " + feeds_count);
  739. $("#actualizeProgress .title").html(feed.title);
  740. if (feed_processed === feeds_count) {
  741. window.location.reload();
  742. } else {
  743. updateFeed(feeds, feeds_count);
  744. }
  745. });
  746. }
  747. function init_actualize() {
  748. var auto = false;
  749. $("#actualize").click(function () {
  750. if (ajax_loading) {
  751. return false;
  752. }
  753. ajax_loading = true;
  754. $.getJSON('./?c=javascript&a=actualize').done(function (data) {
  755. if (auto && data.feeds.length < 1) {
  756. auto = false;
  757. ajax_loading = false;
  758. return false;
  759. }
  760. if (data.feeds.length === 0) {
  761. openNotification(data.feedback_no_refresh, "good");
  762. $.ajax({ //Empty request to force refresh server database cache
  763. type: 'POST',
  764. url: './?c=feed&a=actualize&id=-1',
  765. data: {
  766. _csrf: context.csrf,
  767. noCommit: 0,
  768. },
  769. }).always(function (data) {
  770. ajax_loading = false;
  771. });
  772. return;
  773. }
  774. //Progress bar
  775. var feeds_count = data.feeds.length;
  776. $('body').after('<div id="actualizeProgress" class="notification good">' + data.feedback_actualize +
  777. '<br /><span class="title">/</span><br /><span class="progress">0 / ' + feeds_count +
  778. '</span></div>');
  779. for (var i = 10; i > 0; i--) {
  780. updateFeed(data.feeds, feeds_count);
  781. }
  782. });
  783. return false;
  784. });
  785. if (context.auto_actualize_feeds) {
  786. auto = true;
  787. $("#actualize").click();
  788. }
  789. }
  790. // </actualize>
  791. // <notification>
  792. var notification = null,
  793. notification_interval = null,
  794. notification_working = false;
  795. function openNotification(msg, status) {
  796. if (notification_working === true) {
  797. return false;
  798. }
  799. notification_working = true;
  800. notification.removeClass();
  801. notification.addClass("notification");
  802. notification.addClass(status);
  803. notification.find(".msg").html(msg);
  804. notification.fadeIn(300);
  805. notification_interval = window.setTimeout(closeNotification, 4000);
  806. }
  807. function closeNotification() {
  808. notification.fadeOut(600, function() {
  809. notification.removeClass();
  810. notification.addClass('closed');
  811. window.clearInterval(notification_interval);
  812. notification_working = false;
  813. });
  814. }
  815. function init_notifications() {
  816. notification = $("#notification");
  817. notification.find("a.close").click(function () {
  818. closeNotification();
  819. return false;
  820. });
  821. if (notification.find(".msg").html().length > 0) {
  822. notification_working = true;
  823. notification_interval = window.setTimeout(closeNotification, 4000);
  824. }
  825. }
  826. // </notification>
  827. // <notifs html5>
  828. var notifs_html5_permission = 'denied';
  829. function notifs_html5_is_supported() {
  830. return window.Notification !== undefined;
  831. }
  832. function notifs_html5_ask_permission() {
  833. window.Notification.requestPermission(function () {
  834. notifs_html5_permission = window.Notification.permission;
  835. });
  836. }
  837. function notifs_html5_show(nb) {
  838. if (notifs_html5_permission !== "granted") {
  839. return;
  840. }
  841. var notification = new window.Notification(i18n.notif_title_articles, {
  842. icon: "../themes/icons/favicon-256.png",
  843. body: i18n.notif_body_articles.replace('%d', nb),
  844. tag: "freshRssNewArticles"
  845. });
  846. notification.onclick = function() {
  847. window.location.reload();
  848. window.focus();
  849. notification.close();
  850. };
  851. if (context.html5_notif_timeout !== 0) {
  852. setTimeout(function() {
  853. notification.close();
  854. }, context.html5_notif_timeout * 1000);
  855. }
  856. }
  857. function init_notifs_html5() {
  858. if (!notifs_html5_is_supported()) {
  859. return;
  860. }
  861. notifs_html5_permission = notifs_html5_ask_permission();
  862. }
  863. // </notifs html5>
  864. function refreshUnreads() {
  865. $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) {
  866. var isAll = $('.category.all.active').length > 0,
  867. new_articles = false;
  868. $.each(data, function(feed_id, nbUnreads) {
  869. feed_id = 'f_' + feed_id;
  870. var elem = $('#' + feed_id).get(0),
  871. feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
  872. if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view?
  873. (nbUnreads - feed_unreads > 0)) {
  874. $('#new-article').attr('aria-hidden', 'false').show();
  875. new_articles = true;
  876. }
  877. });
  878. var nb_unreads = str2int($('.category.all .title').attr('data-unread'));
  879. if (nb_unreads > 0 && new_articles) {
  880. faviconNbUnread(nb_unreads);
  881. notifs_html5_show(nb_unreads);
  882. }
  883. });
  884. }
  885. //<endless_mode>
  886. var url_load_more = "",
  887. load_more = false,
  888. box_load_more = null;
  889. function load_more_posts() {
  890. if (load_more || url_load_more === '' || box_load_more === null) {
  891. return;
  892. }
  893. load_more = true;
  894. $('#load_more').addClass('loading');
  895. $.get(url_load_more, function (data) {
  896. box_load_more.children('.flux:last').after($('#stream', data).children('.flux, .day'));
  897. $('.pagination').replaceWith($('.pagination', data));
  898. if (context.display_order === 'ASC') {
  899. $('#nav_menu_read_all .read_all').attr(
  900. 'formaction', $('#bigMarkAsRead').attr('formaction')
  901. );
  902. } else {
  903. $('#bigMarkAsRead').attr(
  904. 'formaction', $('#nav_menu_read_all .read_all').attr('formaction')
  905. );
  906. }
  907. $('[id^=day_]').each(function (i) {
  908. var ids = $('[id="' + this.id + '"]');
  909. if (ids.length > 1) {
  910. $('[id="' + this.id + '"]:gt(0)').remove();
  911. }
  912. });
  913. init_load_more(box_load_more);
  914. $('#load_more').removeClass('loading');
  915. $('#bigMarkAsRead').removeAttr('disabled');
  916. load_more = false;
  917. $(document.body).trigger('sticky_kit:recalc');
  918. });
  919. }
  920. function focus_search() {
  921. $('#search').focus();
  922. }
  923. var freshrssLoadMoreEvent = document.createEvent('Event');
  924. freshrssLoadMoreEvent.initEvent('freshrss:load-more', true, true);
  925. function init_load_more(box) {
  926. box_load_more = box;
  927. document.body.dispatchEvent(freshrssLoadMoreEvent);
  928. var $next_link = $("#load_more");
  929. if (!$next_link.length) {
  930. // no more article to load
  931. url_load_more = "";
  932. return;
  933. }
  934. url_load_more = $next_link.attr("href");
  935. var $prefetch = $('#prefetch');
  936. if ($prefetch.attr('href') !== url_load_more) {
  937. $prefetch.attr('rel', 'next'); //Remove prefetch
  938. $.ajax({url: url_load_more, ifModified: true }); //TODO: Try to find a less agressive solution
  939. $prefetch.attr('href', url_load_more);
  940. }
  941. $next_link.click(function () {
  942. load_more_posts();
  943. return false;
  944. });
  945. }
  946. //</endless_mode>
  947. //<crypto form (Web login)>
  948. function poormanSalt() { //If crypto.getRandomValues is not available
  949. var text = '$2a$04$',
  950. base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789/abcdefghijklmnopqrstuvwxyz';
  951. for (var i = 22; i > 0; i--) {
  952. text += base.charAt(Math.floor(Math.random() * 64));
  953. }
  954. return text;
  955. }
  956. function init_crypto_form() {
  957. /* globals dcodeIO */
  958. var $crypto_form = $('#crypto-form');
  959. if ($crypto_form.length === 0) {
  960. return;
  961. }
  962. if (!(window.dcodeIO)) {
  963. if (window.console) {
  964. console.log('FreshRSS waiting for bcrypt.js…');
  965. }
  966. window.setTimeout(init_crypto_form, 100);
  967. return;
  968. }
  969. $crypto_form.on('submit', function() {
  970. var $submit_button = $(this).find('button[type="submit"]');
  971. $submit_button.attr('disabled', '');
  972. var success = false;
  973. $.ajax({
  974. url: './?c=javascript&a=nonce&user=' + $('#username').val(),
  975. dataType: 'json',
  976. async: false
  977. }).done(function (data) {
  978. if (!data.salt1 || !data.nonce) {
  979. openNotification('Invalid user!', 'bad');
  980. } else {
  981. try {
  982. var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'),
  983. s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1),
  984. c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? dcodeIO.bcrypt.genSaltSync(4) : poormanSalt());
  985. $('#challenge').val(c);
  986. if (!s || !c) {
  987. openNotification('Crypto error!', 'bad');
  988. } else {
  989. success = true;
  990. }
  991. } catch (e) {
  992. openNotification('Crypto exception! ' + e, 'bad');
  993. }
  994. }
  995. }).fail(function() {
  996. openNotification('Communication error!', 'bad');
  997. });
  998. $submit_button.removeAttr('disabled');
  999. return success;
  1000. });
  1001. }
  1002. //</crypto form (Web login)>
  1003. function init_confirm_action() {
  1004. $('body').on('click', '.confirm', function () {
  1005. var str_confirmation = $(this).attr('data-str-confirm');
  1006. if (!str_confirmation) {
  1007. str_confirmation = i18n.confirmation_default;
  1008. }
  1009. return confirm(str_confirmation);
  1010. });
  1011. $('button.confirm').removeAttr('disabled');
  1012. }
  1013. function init_print_action() {
  1014. $('.item.share > a[href="#"]').click(function () {
  1015. var content = "<html><head><style>" +
  1016. "body { font-family: Serif; text-align: justify; }" +
  1017. "a { color: #000; text-decoration: none; }" +
  1018. "a:after { content: ' [' attr(href) ']'}" +
  1019. "</style></head><body>" +
  1020. $(".flux.current .content").html() +
  1021. "</body></html>";
  1022. var tmp_window = window.open();
  1023. tmp_window.document.writeln(content);
  1024. tmp_window.document.close();
  1025. tmp_window.focus();
  1026. tmp_window.print();
  1027. tmp_window.close();
  1028. return false;
  1029. });
  1030. }
  1031. function init_post_action() {
  1032. $('.item.share > a[href="POST"]').click(function (event) {
  1033. event.preventDefault();
  1034. var form = $(this).next('form');
  1035. $.post(form.data('url'), form.serialize());
  1036. });
  1037. }
  1038. function init_share_observers() {
  1039. shares = $('.group-share').length;
  1040. $('.share.add').on('click', function(e) {
  1041. var opt = $(this).siblings('select').find(':selected');
  1042. var row = $(this).parents('form').data(opt.data('form'));
  1043. row = row.replace(/##label##/g, opt.html().trim());
  1044. row = row.replace(/##type##/g, opt.val());
  1045. row = row.replace(/##help##/g, opt.data('help'));
  1046. row = row.replace(/##key##/g, shares);
  1047. row = row.replace(/##method##/g, opt.data('method'));
  1048. row = row.replace(/##field##/g, opt.data('field'));
  1049. $(this).parents('.form-group').before(row);
  1050. shares++;
  1051. return false;
  1052. });
  1053. }
  1054. function init_stats_observers() {
  1055. $('.select-change').on('change', function(e) {
  1056. redirect($(this).find(':selected').data('url'));
  1057. });
  1058. }
  1059. function init_remove_observers() {
  1060. $('.post').on('click', 'a.remove', function(e) {
  1061. var remove_what = $(this).attr('data-remove');
  1062. if (remove_what !== undefined) {
  1063. var remove_obj = $('#' + remove_what);
  1064. remove_obj.remove();
  1065. }
  1066. return false;
  1067. });
  1068. }
  1069. function init_feed_observers() {
  1070. $('select[id="category"]').on('change', function() {
  1071. var detail = $('#new_category_name').parent();
  1072. if ($(this).val() === 'nc') {
  1073. detail.attr('aria-hidden', 'false').show();
  1074. detail.find('input').focus();
  1075. } else {
  1076. detail.attr('aria-hidden', 'true').hide();
  1077. }
  1078. });
  1079. }
  1080. function init_password_observers() {
  1081. $('.toggle-password').on('mousedown', function(e) {
  1082. var button = $(this);
  1083. var passwordField = $('#' + button.attr('data-toggle'));
  1084. passwordField.attr('type', 'text');
  1085. button.addClass('active');
  1086. return false;
  1087. }).on('mouseup', function(e) {
  1088. var button = $(this);
  1089. var passwordField = $('#' + button.attr('data-toggle'));
  1090. passwordField.attr('type', 'password');
  1091. button.removeClass('active');
  1092. return false;
  1093. });
  1094. }
  1095. function faviconNbUnread(n) {
  1096. if (typeof n === 'undefined') {
  1097. n = str2int($('.category.all .title').attr('data-unread'));
  1098. }
  1099. //http://remysharp.com/2010/08/24/dynamic-favicons/
  1100. var canvas = document.createElement('canvas'),
  1101. link = document.getElementById('favicon').cloneNode(true);
  1102. if (canvas.getContext && link) {
  1103. canvas.height = canvas.width = 16;
  1104. var img = document.createElement('img');
  1105. img.onload = function () {
  1106. var ctx = canvas.getContext('2d');
  1107. ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
  1108. if (n > 0) {
  1109. var text = '';
  1110. if (n < 1000) {
  1111. text = n;
  1112. } else if (n < 100000) {
  1113. text = Math.floor(n / 1000) + 'k';
  1114. } else {
  1115. text = 'E' + Math.floor(Math.log10(n));
  1116. }
  1117. ctx.font = 'bold 9px "Arial", sans-serif';
  1118. ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
  1119. ctx.fillRect(0, 7, ctx.measureText(text).width, 9);
  1120. ctx.fillStyle = '#F00';
  1121. ctx.fillText(text, 0, canvas.height - 1);
  1122. }
  1123. link.href = canvas.toDataURL('image/png');
  1124. $('link[rel~=icon]').remove();
  1125. document.head.appendChild(link);
  1126. };
  1127. img.src = '../favicon.ico';
  1128. }
  1129. }
  1130. function init_slider_observers() {
  1131. var slider = $('#slider'),
  1132. closer = $('#close-slider');
  1133. if (slider.length < 1) {
  1134. return;
  1135. }
  1136. $('.post').on('click', '.open-slider', function() {
  1137. if (ajax_loading) {
  1138. return false;
  1139. }
  1140. ajax_loading = true;
  1141. var url_slide = $(this).attr('href');
  1142. $.ajax({
  1143. type: 'GET',
  1144. url: url_slide,
  1145. data: { ajax: true }
  1146. }).done(function (data) {
  1147. slider.html(data);
  1148. closer.addClass('active');
  1149. slider.addClass('active');
  1150. ajax_loading = false;
  1151. });
  1152. return false;
  1153. });
  1154. closer.on('click', function() {
  1155. closer.removeClass('active');
  1156. slider.removeClass('active');
  1157. return false;
  1158. });
  1159. }
  1160. function init_configuration_alert() {
  1161. $(window).on('submit', function(e) {
  1162. window.hasSubmit = true;
  1163. });
  1164. $(window).on('beforeunload', function(e) {
  1165. if (window.hasSubmit) {
  1166. return;
  1167. }
  1168. var fields = $("[data-leave-validation]");
  1169. for (var i = 0; i < fields.length; i++) {
  1170. if ($(fields[i]).attr('type') === 'checkbox' || $(fields[i]).attr('type') === 'radio') {
  1171. // The use of != is done on purpose to check boolean against integer
  1172. if ($(fields[i]).is(':checked') != $(fields[i]).attr('data-leave-validation')) {
  1173. return false;
  1174. }
  1175. } else {
  1176. if ($(fields[i]).attr('data-leave-validation') !== $(fields[i]).val()) {
  1177. return false;
  1178. }
  1179. }
  1180. }
  1181. return;
  1182. });
  1183. }
  1184. function init_subscription() {
  1185. $('body').on('click', '.bookmarkClick', function (e) {
  1186. return false;
  1187. });
  1188. }
  1189. function parseJsonVars() {
  1190. var jsonVars = document.getElementById('jsonVars'),
  1191. json = JSON.parse(jsonVars.innerHTML);
  1192. jsonVars.outerHTML = '';
  1193. window.context = json.context;
  1194. window.shortcuts = json.shortcuts;
  1195. window.url = json.url;
  1196. window.i18n = json.i18n;
  1197. window.icons = json.icons;
  1198. }
  1199. function init_normal() {
  1200. $stream = $('#stream');
  1201. if ($stream.length < 1) {
  1202. if (window.console) {
  1203. console.log('FreshRSS waiting for content…');
  1204. }
  1205. window.setTimeout(init_normal, 100);
  1206. return;
  1207. }
  1208. init_column_categories();
  1209. init_stream($stream);
  1210. init_shortcuts();
  1211. init_actualize();
  1212. faviconNbUnread();
  1213. }
  1214. function init_beforeDOM() {
  1215. if (!window.$) {
  1216. if (window.console) {
  1217. console.log('FreshRSS waiting for jQuery…');
  1218. }
  1219. window.setTimeout(init_beforeDOM, 100);
  1220. return;
  1221. }
  1222. if (['normal', 'reader', 'global'].indexOf(context.current_view) >= 0) {
  1223. inject_script('jquery.sticky-kit.min.js');
  1224. init_normal();
  1225. }
  1226. }
  1227. function init_afterDOM() {
  1228. if (!window.$) {
  1229. if (window.console) {
  1230. console.log('FreshRSS waiting again for jQuery…');
  1231. }
  1232. window.setTimeout(init_afterDOM, 100);
  1233. return;
  1234. }
  1235. init_notifications();
  1236. $stream = $('#stream');
  1237. if ($stream.length > 0) {
  1238. init_confirm_action();
  1239. init_load_more($stream);
  1240. init_posts();
  1241. init_nav_entries();
  1242. init_print_action();
  1243. init_post_action();
  1244. init_notifs_html5();
  1245. window.setInterval(refreshUnreads, 120000);
  1246. } else {
  1247. init_subscription();
  1248. init_crypto_form();
  1249. init_share_observers();
  1250. init_remove_observers();
  1251. init_feed_observers();
  1252. init_password_observers();
  1253. init_stats_observers();
  1254. init_slider_observers();
  1255. init_configuration_alert();
  1256. }
  1257. if (window.console) {
  1258. console.log('FreshRSS init done.');
  1259. }
  1260. }
  1261. parseJsonVars();
  1262. init_beforeDOM(); //Can be called before DOM is fully loaded
  1263. if (document.readyState && document.readyState !== 'loading') {
  1264. init_afterDOM();
  1265. } else if (document.addEventListener) {
  1266. document.addEventListener('DOMContentLoaded', function () {
  1267. if (window.console) {
  1268. console.log('FreshRSS waiting for DOMContentLoaded…');
  1269. }
  1270. init_afterDOM();
  1271. }, false);
  1272. }