main.js 36 KB

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