main.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. "use strict";
  2. var $stream = null,
  3. isCollapsed = true;
  4. function is_normal_mode() {
  5. return $stream.hasClass('normal');
  6. }
  7. function is_global_mode() {
  8. return $stream.hasClass('global');
  9. }
  10. function redirect(url, new_tab) {
  11. if (url) {
  12. if (new_tab) {
  13. window.open(url);
  14. } else {
  15. location.href = url;
  16. }
  17. }
  18. }
  19. function incLabel(p, inc) {
  20. var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc;
  21. return i > 0 ? ' (' + i + ')' : '';
  22. }
  23. function incUnreadsFeed(article, feed_id, nb) {
  24. //Update unread: feed
  25. var elem = $('#' + feed_id + '>.feed').get(0),
  26. feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0,
  27. feed_priority = elem ? (parseInt(elem.getAttribute('data-priority'), 10) || 0) : 0;
  28. if (elem) {
  29. elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb));
  30. }
  31. //Update unread: category
  32. elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0);
  33. feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0;
  34. if (elem) {
  35. elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb));
  36. }
  37. //Update unread: all
  38. if (feed_priority > 0) {
  39. elem = $('#aside_flux .all').children(':first').get(0);
  40. if (elem) {
  41. feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0;
  42. elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb));
  43. }
  44. }
  45. //Update unread: favourites
  46. if (article && article.closest('div').hasClass('favorite')) {
  47. elem = $('#aside_flux .favorites').children(':first').get(0);
  48. if (elem) {
  49. feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0;
  50. elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb));
  51. }
  52. }
  53. //Update unread: title
  54. document.title = document.title.replace(/((?: \(\d+\))?)( · .*?)((?: \(\d+\))?)$/, function (m, p1, p2, p3) {
  55. if (article || ($('#' + feed_id).closest('.active').length > 0)) {
  56. return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0);
  57. } else {
  58. return p1 + p2 + incLabel(p3, feed_priority > 0 ? nb : 0);
  59. }
  60. });
  61. }
  62. function mark_read(active, only_not_read) {
  63. if (active.length === 0 || (only_not_read === true && !active.hasClass("not_read"))) {
  64. return false;
  65. }
  66. var url = active.find("a.read").attr("href");
  67. if (url === undefined) {
  68. return false;
  69. }
  70. $.ajax({
  71. type: 'POST',
  72. url: url,
  73. data : { ajax: true }
  74. }).done(function (data) {
  75. var $r = active.find("a.read").attr("href", data.url),
  76. inc = 0;
  77. if (active.hasClass("not_read")) {
  78. active.removeClass("not_read");
  79. inc--;
  80. } else if (only_not_read !== true || active.hasClass("not_read")) {
  81. active.addClass("not_read");
  82. inc++;
  83. }
  84. $r.find('.icon').replaceWith(data.icon);
  85. var feed_url = active.find(".website>a").attr("href"),
  86. feed_id = feed_url.substr(feed_url.lastIndexOf('f_'));
  87. incUnreadsFeed(active, feed_id, inc);
  88. });
  89. }
  90. function mark_favorite(active) {
  91. if (active.length === 0) {
  92. return false;
  93. }
  94. var url = active.find("a.bookmark").attr("href");
  95. if (url === undefined) {
  96. return false;
  97. }
  98. $.ajax({
  99. type: 'POST',
  100. url: url,
  101. data : { ajax: true }
  102. }).done(function (data) {
  103. var $b = active.find("a.bookmark").attr("href", data.url),
  104. inc = 0;
  105. if (active.hasClass("favorite")) {
  106. active.removeClass("favorite");
  107. inc--;
  108. } else {
  109. active.addClass("favorite").find('.bookmark');
  110. inc++;
  111. }
  112. $b.find('.icon').replaceWith(data.icon);
  113. var favourites = $('.favorites>a').contents().last().get(0);
  114. if (favourites && favourites.textContent) {
  115. favourites.textContent = favourites.textContent.replace(/((?: \(\d+\))?\s*)$/, function (m, p1) {
  116. return incLabel(p1, inc);
  117. });
  118. }
  119. if (active.closest('div').hasClass('not_read')) {
  120. var elem = $('#aside_flux .favorites').children(':first').get(0),
  121. feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0;
  122. if (elem) {
  123. elem.setAttribute('data-unread', Math.max(0, feed_unreads + inc));
  124. }
  125. }
  126. });
  127. }
  128. function toggleContent(new_active, old_active) {
  129. old_active.removeClass("active").removeClass("current");
  130. if (new_active.length === 0) {
  131. return;
  132. }
  133. if (does_lazyload) {
  134. new_active.find('img[data-original], iframe[data-original]').each(function () {
  135. this.setAttribute('src', this.getAttribute('data-original'));
  136. this.removeAttribute('data-original');
  137. });
  138. }
  139. if (old_active[0] !== new_active[0]) {
  140. if (isCollapsed) {
  141. new_active.addClass("active");
  142. }
  143. new_active.addClass("current");
  144. }
  145. var box_to_move = "html,body",
  146. relative_move = false;
  147. if (is_global_mode()) {
  148. box_to_move = "#panel";
  149. relative_move = true;
  150. }
  151. var new_pos = new_active.position().top,
  152. old_scroll = $(box_to_move).scrollTop();
  153. if (hide_posts) {
  154. new_pos = new_active.position().top;
  155. old_scroll = $(box_to_move).scrollTop();
  156. if (relative_move) {
  157. new_pos += old_scroll;
  158. }
  159. if (old_active[0] !== new_active[0]) {
  160. new_active.children(".flux_content").first().each(function () {
  161. $(box_to_move).scrollTop(new_pos).scrollTop();
  162. });
  163. }
  164. } else {
  165. if (relative_move) {
  166. new_pos += old_scroll;
  167. }
  168. $(box_to_move).scrollTop(new_pos).scrollTop();
  169. }
  170. if (auto_mark_article) {
  171. mark_read(new_active, true);
  172. }
  173. }
  174. function prev_entry() {
  175. var old_active = $(".flux.current"),
  176. new_active = old_active.length === 0 ? $(".flux:last") : old_active.prevAll(".flux:first");
  177. toggleContent(new_active, old_active);
  178. }
  179. function next_entry() {
  180. var old_active = $(".flux.current"),
  181. new_active = old_active.length === 0 ? $(".flux:first") : old_active.nextAll(".flux:first");
  182. toggleContent(new_active, old_active);
  183. if (!auto_load_more) {
  184. var last_active = $(".flux:last");
  185. if (last_active.attr("id") === new_active.attr("id")) {
  186. load_more_posts();
  187. }
  188. }
  189. }
  190. function collapse_entry() {
  191. isCollapsed = !isCollapsed;
  192. $(".flux.current").toggleClass("active");
  193. }
  194. function auto_share() {
  195. var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]');
  196. if (share.length) {
  197. window.location.hash = share.attr('id');
  198. }
  199. }
  200. function inMarkViewport(flux, box_to_follow, relative_follow) {
  201. var top = flux.position().top;
  202. if (relative_follow) {
  203. top += box_to_follow.scrollTop();
  204. }
  205. var height = flux.height(),
  206. begin = top + 3 * height / 4,
  207. bot = Math.min(begin + 75, top + height),
  208. windowTop = box_to_follow.scrollTop(),
  209. windowBot = windowTop + box_to_follow.height() / 2;
  210. return (windowBot >= begin && bot >= windowBot);
  211. }
  212. function init_lazyload() {
  213. if ($.fn.lazyload) {
  214. if (is_global_mode()) {
  215. $(".flux_content img").lazyload({
  216. container: $("#panel")
  217. });
  218. } else {
  219. $(".flux_content img").lazyload();
  220. }
  221. }
  222. }
  223. function init_posts() {
  224. init_lazyload();
  225. var box_to_follow = $(window),
  226. relative_follow = false;
  227. if (is_global_mode()) {
  228. box_to_follow = $("#panel");
  229. relative_follow = true;
  230. }
  231. if (auto_mark_scroll) {
  232. box_to_follow.scroll(function () {
  233. $('.not_read:visible').each(function () {
  234. if ($(this).children(".flux_content").is(':visible') && inMarkViewport($(this), box_to_follow, relative_follow)) {
  235. mark_read($(this), true);
  236. }
  237. });
  238. });
  239. }
  240. if (auto_load_more) {
  241. box_to_follow.scroll(function () {
  242. var load_more = $("#load_more");
  243. if (!load_more.is(':visible')) {
  244. return;
  245. }
  246. var boxBot = box_to_follow.scrollTop() + box_to_follow.height(),
  247. load_more_top = load_more.position().top;
  248. if (relative_follow) {
  249. load_more_top += box_to_follow.scrollTop();
  250. }
  251. if (boxBot >= load_more_top) {
  252. load_more_posts();
  253. }
  254. });
  255. }
  256. }
  257. function init_column_categories() {
  258. if (!is_normal_mode()) {
  259. return;
  260. }
  261. $('#aside_flux').on('click', '.category>a.dropdown-toggle', function () {
  262. $(this).children().each(function() {
  263. if (this.alt === '▽') {
  264. this.src = this.src.replace('/icons/down.', '/icons/up.');
  265. this.alt = '△';
  266. } else {
  267. this.src = this.src.replace('/icons/up.', '/icons/down.');
  268. this.alt = '▽';
  269. }
  270. });
  271. $(this).parent().next(".feeds").slideToggle();
  272. return false;
  273. });
  274. $('#aside_flux').on('click', '.feeds .dropdown-toggle', function () {
  275. if ($(this).nextAll('.dropdown-menu').length === 0) {
  276. var feed_id = $(this).closest('li').attr('id').substr(2),
  277. feed_web = $(this).data('fweb'),
  278. template = $('#feed_config_template').html().replace(/!!!!!!/g, feed_id).replace('http://example.net/', feed_web);
  279. $(this).attr('href', '#dropdown-' + feed_id).prev('.dropdown-target').attr('id', 'dropdown-' + feed_id).parent().append(template);
  280. }
  281. });
  282. }
  283. function init_shortcuts() {
  284. if (!(window.shortcut && window.shortcuts)) {
  285. if (window.console) {
  286. console.log('FreshRSS waiting for sortcut.js…');
  287. }
  288. window.setTimeout(init_shortcuts, 50);
  289. return;
  290. }
  291. // Touches de manipulation
  292. shortcut.add(shortcuts.mark_read, function () {
  293. // on marque comme lu ou non lu
  294. var active = $(".flux.current");
  295. mark_read(active, false);
  296. }, {
  297. 'disable_in_input': true
  298. });
  299. shortcut.add("shift+" + shortcuts.mark_read, function () {
  300. // on marque tout comme lu
  301. var url = $(".nav_menu a.read_all").attr("href");
  302. redirect(url, false);
  303. }, {
  304. 'disable_in_input': true
  305. });
  306. shortcut.add(shortcuts.mark_favorite, function () {
  307. // on marque comme favori ou non favori
  308. var active = $(".flux.current");
  309. mark_favorite(active);
  310. }, {
  311. 'disable_in_input': true
  312. });
  313. shortcut.add(shortcuts.collapse_entry, function () {
  314. collapse_entry();
  315. }, {
  316. 'disable_in_input': true
  317. });
  318. shortcut.add(shortcuts.auto_share, function () {
  319. auto_share();
  320. }, {
  321. 'disable_in_input': true
  322. });
  323. // Touches de navigation
  324. shortcut.add(shortcuts.prev_entry, prev_entry, {
  325. 'disable_in_input': true
  326. });
  327. shortcut.add("shift+" + shortcuts.prev_entry, function () {
  328. var old_active = $(".flux.current"),
  329. first = $(".flux:first");
  330. if (first.hasClass("flux")) {
  331. toggleContent(first, old_active);
  332. }
  333. }, {
  334. 'disable_in_input': true
  335. });
  336. shortcut.add(shortcuts.next_entry, next_entry, {
  337. 'disable_in_input': true
  338. });
  339. shortcut.add("shift+" + shortcuts.next_entry, function () {
  340. var old_active = $(".flux.current"),
  341. last = $(".flux:last");
  342. if (last.hasClass("flux")) {
  343. toggleContent(last, old_active);
  344. }
  345. }, {
  346. 'disable_in_input': true
  347. });
  348. shortcut.add(shortcuts.go_website, function () {
  349. var url_website = $(".flux.active .link a").attr("href");
  350. if (auto_mark_site) {
  351. $(".flux.current").each(function () {
  352. mark_read($(this), true);
  353. });
  354. }
  355. redirect(url_website, true);
  356. }, {
  357. 'disable_in_input': true
  358. });
  359. shortcut.add(shortcuts.load_more, function () {
  360. load_more_posts();
  361. }, {
  362. 'disable_in_input': true
  363. });
  364. }
  365. function init_stream(divStream) {
  366. divStream.on('click', '.flux_header', function (e) { //flux_header_toggle
  367. if ($(e.target).closest('.item.website > a').length > 0) {
  368. return;
  369. }
  370. var old_active = $(".flux.current"),
  371. new_active = $(this).parent();
  372. isCollapsed = true;
  373. if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone
  374. if (auto_mark_article) {
  375. mark_read(new_active, true);
  376. }
  377. return true;
  378. }
  379. toggleContent(new_active, old_active);
  380. });
  381. divStream.on('click', '.flux a.read', function () {
  382. var active = $(this).parents(".flux");
  383. mark_read(active, false);
  384. return false;
  385. });
  386. divStream.on('click', '.flux a.bookmark', function () {
  387. var active = $(this).parents(".flux");
  388. mark_favorite(active);
  389. return false;
  390. });
  391. divStream.on('click', '.item.title>a', function (e) {
  392. if (e.ctrlKey) {
  393. return true; //Allow default control-click behaviour such as open in backround-tab
  394. }
  395. $(this).parent().click(); //Will perform toggle flux_content
  396. return false;
  397. });
  398. divStream.on('click', '.flux .content a', function () {
  399. $(this).attr('target', '_blank');
  400. });
  401. if (auto_mark_site) {
  402. divStream.on('click', '.flux .link a', function () {
  403. mark_read($(this).parent().parent().parent(), true);
  404. });
  405. }
  406. }
  407. function init_nav_entries() {
  408. var $nav_entries = $('#nav_entries');
  409. $nav_entries.find('.previous_entry').click(function () {
  410. prev_entry();
  411. return false;
  412. });
  413. $nav_entries.find('.next_entry').click(function () {
  414. next_entry();
  415. return false;
  416. });
  417. $nav_entries.find('.up').click(function () {
  418. var active_item = $(".flux.current"),
  419. windowTop = $(window).scrollTop(),
  420. item_top = active_item.position().top;
  421. if (windowTop > item_top) {
  422. $("html,body").scrollTop(item_top);
  423. } else {
  424. $("html,body").scrollTop(0);
  425. }
  426. return false;
  427. });
  428. }
  429. function init_actualize() {
  430. $("#actualize").click(function () {
  431. $.getScript('./?c=javascript&a=actualize').done(function () {
  432. updateFeeds();
  433. });
  434. return false;
  435. });
  436. if(auto_actualize_feeds) {
  437. $.getScript('./?c=javascript&a=actualize').done(function () {
  438. updateFeeds();
  439. });
  440. }
  441. }
  442. function closeNotification() {
  443. $(".notification").fadeOut(600, function () {
  444. $(".notification").remove();
  445. });
  446. }
  447. function init_notifications() {
  448. var notif = $(".notification");
  449. if (notif.length > 0) {
  450. window.setInterval(closeNotification, 4000);
  451. notif.find("a.close").click(function () {
  452. closeNotification();
  453. return false;
  454. });
  455. }
  456. }
  457. function refreshUnreads() {
  458. $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) {
  459. var new_article = false;
  460. $.each(data, function(feed_id, nbUnreads) {
  461. feed_id = 'f_' + feed_id;
  462. var elem = $('#' + feed_id + '>.feed').get(0),
  463. feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0;
  464. incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads);
  465. if (nbUnreads - feed_unreads > 0) {
  466. new_article = true;
  467. }
  468. });
  469. if (new_article) {
  470. $('#new-article').show();
  471. }
  472. });
  473. }
  474. //<endless_mode>
  475. var url_load_more = "",
  476. load_more = false,
  477. box_load_more = null;
  478. function load_more_posts() {
  479. if (load_more || url_load_more === '' || box_load_more === null) {
  480. return;
  481. }
  482. load_more = true;
  483. $('#load_more').addClass('loading');
  484. $.get(url_load_more, function (data) {
  485. box_load_more.children('.flux:last').after($('#stream', data).children('.flux, .day'));
  486. $('.pagination').replaceWith($('.pagination', data));
  487. $('#bigMarkAsRead').attr('href', $('#nav_menu_read_all>a').attr('href'));
  488. $('[id^=day_]').each(function (i) {
  489. var ids = $('[id="' + this.id + '"]');
  490. if (ids.length > 1) {
  491. $('[id="' + this.id + '"]:gt(0)').remove();
  492. }
  493. });
  494. init_load_more(box_load_more);
  495. init_lazyload();
  496. $('#load_more').removeClass('loading');
  497. load_more = false;
  498. });
  499. }
  500. function init_load_more(box) {
  501. box_load_more = box;
  502. var $next_link = $("#load_more");
  503. if (!$next_link.length) {
  504. // no more article to load
  505. url_load_more = "";
  506. return;
  507. }
  508. url_load_more = $next_link.attr("href");
  509. var $prefetch = $('#prefetch');
  510. if ($prefetch.attr('href') !== url_load_more) {
  511. $prefetch.attr('rel', 'next'); //Remove prefetch
  512. $.ajax({url: url_load_more, ifModified: true }); //TODO: Try to find a less agressive solution
  513. $prefetch.attr('href', url_load_more);
  514. }
  515. $next_link.click(function () {
  516. load_more_posts();
  517. return false;
  518. });
  519. }
  520. //</endless_mode>
  521. //<Web login form>
  522. function poormanSalt() { //If crypto.getRandomValues is not available
  523. var text = '$2a$04$',
  524. base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789/abcdefghijklmnopqrstuvwxyz';
  525. for (var i = 22; i > 0; i--) {
  526. text += base.charAt(Math.floor(Math.random() * 64));
  527. }
  528. return text;
  529. }
  530. function init_loginForm() {
  531. var $loginForm = $('#loginForm');
  532. if ($loginForm.length === 0) {
  533. return;
  534. }
  535. if (!(window.dcodeIO)) {
  536. if (window.console) {
  537. console.log('FreshRSS waiting for bcrypt.js…');
  538. }
  539. window.setTimeout(init_loginForm, 100);
  540. return;
  541. }
  542. $loginForm.on('submit', function() {
  543. $('#loginButton').attr('disabled', '');
  544. var success = false;
  545. $.ajax({
  546. url: './?c=javascript&a=nonce&user=' + $('#username').val(),
  547. dataType: 'json',
  548. async: false
  549. }).done(function (data) {
  550. if (data.salt1 == '' || data.nonce == '') {
  551. alert('Invalid user!');
  552. } else {
  553. var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'),
  554. s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1),
  555. c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt());
  556. $('#challenge').val(c);
  557. if (s == '' || c == '') {
  558. alert('Crypto error!');
  559. } else {
  560. success = true;
  561. }
  562. }
  563. }).fail(function() {
  564. alert('Communication error!');
  565. });
  566. $('#loginButton').removeAttr('disabled');
  567. return success;
  568. });
  569. }
  570. //</Web login form>
  571. //<persona>
  572. function init_persona() {
  573. if (!(navigator.id)) {
  574. if (window.console) {
  575. console.log('FreshRSS waiting for Persona…');
  576. }
  577. window.setTimeout(init_persona, 100);
  578. return;
  579. }
  580. $('a.signin').click(function() {
  581. navigator.id.request();
  582. return false;
  583. });
  584. $('a.signout').click(function() {
  585. navigator.id.logout();
  586. return false;
  587. });
  588. navigator.id.watch({
  589. loggedInUser: current_user_mail,
  590. onlogin: function(assertion) {
  591. // A user has logged in! Here you need to:
  592. // 1. Send the assertion to your backend for verification and to create a session.
  593. // 2. Update your UI.
  594. $.ajax ({
  595. type: 'POST',
  596. url: url_login,
  597. data: {assertion: assertion},
  598. success: function(res, status, xhr) {
  599. /*if (res.status === 'failure') {
  600. alert (res_obj.reason);
  601. } else*/ if (res.status === 'okay') {
  602. location.href = url_freshrss;
  603. }
  604. },
  605. error: function(res, status, xhr) {
  606. alert("Login failure: " + res);
  607. }
  608. });
  609. },
  610. onlogout: function() {
  611. // A user has logged out! Here you need to:
  612. // Tear down the user's session by redirecting the user or making a call to your backend.
  613. // Also, make sure loggedInUser will get set to null on the next page load.
  614. // (That's a literal JavaScript null. Not false, 0, or undefined. null.)
  615. $.ajax ({
  616. type: 'POST',
  617. url: url_logout,
  618. success: function(res, status, xhr) {
  619. location.href = url_freshrss;
  620. },
  621. error: function(res, status, xhr) {
  622. //alert("logout failure" + res);
  623. }
  624. });
  625. }
  626. });
  627. }
  628. //</persona>
  629. function init_confirm_action() {
  630. $('.confirm').click(function () {
  631. return confirm(str_confirmation);
  632. });
  633. }
  634. function init_print_action() {
  635. $('.print-article').click(function () {
  636. var content = "<html><head><style>"
  637. + "body { font-family: Serif; text-align: justify; }"
  638. + "a { color: #000; text-decoration: none; }"
  639. + "a:after { content: ' [' attr(href) ']'}"
  640. + "</style></head><body>"
  641. + $(".flux.current .content").html()
  642. + "</body></html>";
  643. var tmp_window = window.open();
  644. tmp_window.document.writeln(content);
  645. tmp_window.document.close();
  646. tmp_window.focus();
  647. tmp_window.print();
  648. tmp_window.close();
  649. return false;
  650. });
  651. }
  652. function init_all() {
  653. if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) {
  654. if (window.console) {
  655. console.log('FreshRSS waiting for JS…');
  656. }
  657. window.setTimeout(init_all, 50);
  658. return;
  659. }
  660. init_notifications();
  661. switch (authType) {
  662. case 'form':
  663. init_loginForm();
  664. break;
  665. case 'persona':
  666. init_persona();
  667. break;
  668. }
  669. init_confirm_action();
  670. $stream = $('#stream');
  671. if ($stream.length > 0) {
  672. init_actualize();
  673. init_column_categories();
  674. init_load_more($stream);
  675. init_posts();
  676. init_stream($stream);
  677. init_nav_entries();
  678. init_shortcuts();
  679. init_print_action();
  680. window.setInterval(refreshUnreads, 120000);
  681. }
  682. if (window.console) {
  683. console.log('FreshRSS init done.');
  684. }
  685. }
  686. if (document.readyState && document.readyState !== 'loading') {
  687. if (window.console) {
  688. console.log('FreshRSS immediate init…');
  689. }
  690. init_all();
  691. } else if (document.addEventListener) {
  692. document.addEventListener('DOMContentLoaded', function () {
  693. if (window.console) {
  694. console.log('FreshRSS waiting for DOMContentLoaded…');
  695. }
  696. init_all();
  697. }, false);
  698. }