main.js 20 KB

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