4
0

main.js 20 KB

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