main.js 36 KB

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