4
0

main.js 20 KB

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