main.js 19 KB

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