From 58300c36ad77e8d788e99825d509fe8657a36854 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 26 Dec 2013 01:56:58 +0100 Subject: Cookie : sous-répertoire pour index (changements de répertoires !) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Implémente https://github.com/marienfressinaud/FreshRSS/issues/333 /public/ est renommé /p/ /public/index.php est déplacé dans /p/i/index.php Le cookie de session est limité à /p/i/ --- p/scripts/main.js | 693 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 693 insertions(+) create mode 100644 p/scripts/main.js (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js new file mode 100644 index 000000000..ef05eb2fb --- /dev/null +++ b/p/scripts/main.js @@ -0,0 +1,693 @@ +"use strict"; +var $stream = null, + isCollapsed = true; + +function is_normal_mode() { + return $stream.hasClass('normal'); +} + +function is_global_mode() { + return $stream.hasClass('global'); +} + +function redirect(url, new_tab) { + if (url) { + if (new_tab) { + window.open(url); + } else { + location.href = url; + } + } +} + +function incLabel(p, inc) { + var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc; + return i > 0 ? ' (' + i + ')' : ''; +} + +function mark_read(active, only_not_read) { + if (active[0] === undefined || (only_not_read === true && !active.hasClass("not_read"))) { + return false; + } + + var url = active.find("a.read").attr("href"); + if (url === undefined) { + return false; + } + + $.ajax({ + type: 'POST', + url: url, + data : { ajax: true } + }).done(function (data) { + var $r = active.find("a.read").attr("href", data.url), + inc = 0; + if (active.hasClass("not_read")) { + active.removeClass("not_read"); + inc--; + } else if (only_not_read !== true || active.hasClass("not_read")) { + active.addClass("not_read"); + inc++; + } + $r.find('.icon').replaceWith(data.icon); + + //Update unread: feed + var feed_url = active.find(".website>a").attr("href"), + feed_id = feed_url.substr(feed_url.lastIndexOf('f_')), + elem = $('#' + feed_id + ' .feed').get(0), + feed_unread = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0, + feed_priority = elem ? (parseInt(elem.getAttribute('data-priority'), 10) || 0) : 0; + if (elem) { + elem.setAttribute('data-unread', Math.max(0, feed_unread + inc)); + } + + //Update unread: category + elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0); + feed_unread = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + if (elem) { + elem.setAttribute('data-unread', Math.max(0, feed_unread + inc)); + } + + //Update unread: all + if (feed_priority > 0) { + elem = $('#aside_flux .all').children(':first').get(0); + if (elem) { + feed_unread = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + elem.setAttribute('data-unread', Math.max(0, feed_unread + inc)); + } + } + + //Update unread: favourites + if (active.closest('div').hasClass('favorite')) { + elem = $('#aside_flux .favorites').children(':first').get(0); + if (elem) { + feed_unread = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + elem.setAttribute('data-unread', Math.max(0, feed_unread + inc)); + } + } + + //Update unread: title + document.title = document.title.replace(/((?: \(\d+\))?)( - .*?)((?: \(\d+\))?)$/, function (m, p1, p2, p3) { + return incLabel(p1, inc) + p2 + incLabel(p3, feed_priority > 0 ? inc : 0); + }); + }); +} + +function mark_favorite(active) { + if (active[0] === undefined) { + return false; + } + + var url = active.find("a.bookmark").attr("href"); + if (url === undefined) { + return false; + } + + $.ajax({ + type: 'POST', + url: url, + data : { ajax: true } + }).done(function (data) { + var $b = active.find("a.bookmark").attr("href", data.url), + inc = 0; + if (active.hasClass("favorite")) { + active.removeClass("favorite"); + inc--; + } else { + active.addClass("favorite").find('.bookmark'); + inc++; + } + $b.find('.icon').replaceWith(data.icon); + + var favourites = $('.favorites>a').contents().last().get(0); + if (favourites && favourites.textContent) { + favourites.textContent = favourites.textContent.replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { + return incLabel(p1, inc); + }); + } + + if (active.closest('div').hasClass('not_read')) { + var elem = $('#aside_flux .favorites').children(':first').get(0), + feed_unread = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + elem.setAttribute('data-unread', Math.max(0, feed_unread + inc)); + } + }); +} + +function toggleContent(new_active, old_active) { + if (does_lazyload) { + new_active.find('img[data-original], iframe[data-original]').each(function () { + this.setAttribute('src', this.getAttribute('data-original')); + this.removeAttribute('data-original'); + }); + } + + old_active.removeClass("active").removeClass("current"); + if (old_active[0] !== new_active[0]) { + if (isCollapsed) { + new_active.addClass("active"); + } + new_active.addClass("current"); + } + + var box_to_move = "html,body", + relative_move = false; + if (is_global_mode()) { + box_to_move = "#panel"; + relative_move = true; + } + + var new_pos = new_active.position().top, + old_scroll = $(box_to_move).scrollTop(); + if (hide_posts) { + + new_pos = new_active.position().top; + old_scroll = $(box_to_move).scrollTop(); + + if (relative_move) { + new_pos += old_scroll; + } + + if (old_active[0] !== new_active[0]) { + new_active.children(".flux_content").first().each(function () { + $(box_to_move).scrollTop(new_pos).scrollTop(); + }); + } + } else { + if (relative_move) { + new_pos += old_scroll; + } + + $(box_to_move).scrollTop(new_pos).scrollTop(); + } + + if (auto_mark_article) { + mark_read(new_active, true); + } +} + +function prev_entry() { + var old_active = $(".flux.current"), + last_active = $(".flux:last"), + new_active = old_active.prevAll(".flux:first"); + + if (new_active.hasClass("flux")) { + toggleContent(new_active, old_active); + } else if (old_active[0] === undefined && new_active[0] === undefined) { + toggleContent(last_active, old_active); + } +} + +function next_entry() { + var old_active = $(".flux.current"), + first_active = $(".flux:first"), + last_active = $(".flux:last"), + new_active = old_active.nextAll(".flux:first"); + + if (new_active.hasClass("flux")) { + toggleContent(new_active, old_active); + } else if (old_active[0] === undefined && new_active[0] === undefined) { + toggleContent(first_active, old_active); + } + + if ((!auto_load_more) && (last_active.attr("id") === new_active.attr("id"))) { + load_more_posts(); + } +} + +function collapse_entry() { + isCollapsed = !isCollapsed; + $(".flux.current").toggleClass("active"); +} + +function inMarkViewport(flux, box_to_follow, relative_follow) { + var top = flux.position().top; + if (relative_follow) { + top += box_to_follow.scrollTop(); + } + var height = flux.height(), + begin = top + 3 * height / 4, + bot = Math.min(begin + 75, top + height), + windowTop = box_to_follow.scrollTop(), + windowBot = windowTop + box_to_follow.height() / 2; + + return (windowBot >= begin && bot >= windowBot); +} + +function init_lazyload() { + if ($.fn.lazyload) { + if (is_global_mode()) { + $(".flux_content img").lazyload({ + container: $("#panel") + }); + } else { + $(".flux_content img").lazyload(); + } + } +} + +function init_posts() { + init_lazyload(); + + var box_to_follow = $(window), + relative_follow = false; + if (is_global_mode()) { + box_to_follow = $("#panel"); + relative_follow = true; + } + + if (auto_mark_scroll) { + box_to_follow.scroll(function () { + $('.not_read:visible').each(function () { + if ($(this).children(".flux_content").is(':visible') && inMarkViewport($(this), box_to_follow, relative_follow)) { + mark_read($(this), true); + } + }); + }); + } + + if (auto_load_more) { + box_to_follow.scroll(function () { + var load_more = $("#load_more"); + if (!load_more.is(':visible')) { + return; + } + var boxBot = box_to_follow.scrollTop() + box_to_follow.height(), + load_more_top = load_more.position().top; + if (relative_follow) { + load_more_top += box_to_follow.scrollTop(); + } + if (boxBot >= load_more_top) { + load_more_posts(); + } + }); + } +} + +function init_column_categories() { + if (!is_normal_mode()) { + return; + } + $('#aside_flux').on('click', '.category>a.dropdown-toggle', function () { + $(this).children().each(function() { + if (this.alt === '▽') { + this.src = this.src.replace('/icons/down.', '/icons/up.'); + this.alt = '△'; + } else { + this.src = this.src.replace('/icons/up.', '/icons/down.'); + this.alt = '▽'; + } + }); + $(this).parent().next(".feeds").slideToggle(); + return false; + }); +} + +function init_shortcuts() { + if (!(window.shortcut && window.shortcuts)) { + if (window.console) { + console.log('FreshRSS waiting for sortcut.js…'); + } + window.setTimeout(init_shortcuts, 50); + return; + } + // Touches de manipulation + shortcut.add(shortcuts.mark_read, function () { + // on marque comme lu ou non lu + var active = $(".flux.current"); + mark_read(active, false); + }, { + 'disable_in_input': true + }); + shortcut.add("shift+" + shortcuts.mark_read, function () { + // on marque tout comme lu + var url = $(".nav_menu a.read_all").attr("href"); + redirect(url, false); + }, { + 'disable_in_input': true + }); + shortcut.add(shortcuts.mark_favorite, function () { + // on marque comme favori ou non favori + var active = $(".flux.current"); + mark_favorite(active); + }, { + 'disable_in_input': true + }); + shortcut.add(shortcuts.collapse_entry, function () { + collapse_entry(); + }, { + 'disable_in_input': true + }); + + // Touches de navigation + shortcut.add(shortcuts.prev_entry, prev_entry, { + 'disable_in_input': true + }); + shortcut.add("shift+" + shortcuts.prev_entry, function () { + var old_active = $(".flux.current"), + first = $(".flux:first"); + + if (first.hasClass("flux")) { + toggleContent(first, old_active); + } + }, { + 'disable_in_input': true + }); + shortcut.add(shortcuts.next_entry, next_entry, { + 'disable_in_input': true + }); + shortcut.add("shift+" + shortcuts.next_entry, function () { + var old_active = $(".flux.current"), + last = $(".flux:last"); + + if (last.hasClass("flux")) { + toggleContent(last, old_active); + } + }, { + 'disable_in_input': true + }); + shortcut.add(shortcuts.go_website, function () { + var url_website = $(".flux.active .link a").attr("href"); + + if (auto_mark_site) { + $(".flux.current").each(function () { + mark_read($(this), true); + }); + } + + redirect(url_website, true); + }, { + 'disable_in_input': true + }); + + shortcut.add(shortcuts.load_more, function () { + load_more_posts(); + }, { + 'disable_in_input': true + }); +} + +function init_stream_delegates(divStream) { + divStream.on('click', '.flux_header', function (e) { //flux_header_toggle + var old_active = $(".flux.current"), + new_active = $(this).parent(); + isCollapsed = true; + if (e.target.tagName.toUpperCase() === 'A') { //Leave real links alone + if (auto_mark_article) { + mark_read(new_active, true); + } + return true; + } + toggleContent(new_active, old_active); + }); + + divStream.on('click', '.flux a.read', function () { + var active = $(this).parents(".flux"); + mark_read(active, false); + + return false; + }); + + divStream.on('click', '.flux a.bookmark', function () { + var active = $(this).parents(".flux"); + mark_favorite(active); + + return false; + }); + + divStream.on('click', '.flux .content a', function () { + $(this).attr('target', '_blank'); + }); + + divStream.on('click', '.item.title>a', function (e) { + if (e.ctrlKey) { + return true; //Allow default control-click behaviour such as open in backround-tab + } + $(this).parent().click(); //Will perform toggle flux_content + return false; + }); + + if (auto_mark_site) { + divStream.on('click', '.flux .link a', function () { + mark_read($(this).parent().parent().parent(), true); + }); + } +} + +function init_nav_entries() { + var $nav_entries = $('#nav_entries'); + $nav_entries.find('.previous_entry').click(function () { + prev_entry(); + return false; + }); + $nav_entries.find('.next_entry').click(function () { + next_entry(); + return false; + }); + $nav_entries.find('.up').click(function () { + var active_item = $(".flux.current"), + windowTop = $(window).scrollTop(), + item_top = active_item.position().top; + + if (windowTop > item_top) { + $("html,body").scrollTop(item_top); + } else { + $("html,body").scrollTop(0); + } + return false; + }); +} + +function init_templates() { + $('#aside_flux').on('click', '.feeds .dropdown-toggle', function () { + if ($(this).nextAll('.dropdown-menu').length === 0) { + var feed_id = $(this).closest('li').attr('id').substr(2), + feed_web = $(this).data('fweb'), + template = $('#feed_config_template').html().replace(/!!!!!!/g, feed_id).replace('http://example.net/', feed_web); + $(this).attr('href', '#dropdown-' + feed_id).prev('.dropdown-target').attr('id', 'dropdown-' + feed_id).parent().append(template); + } + }); +} + +function init_actualize() { + $("#actualize").click(function () { + $.getScript('./?c=javascript&a=actualize').done(function () { + updateFeeds(); + }); + return false; + }); + + if(auto_actualize_feeds) { + $.getScript('./?c=javascript&a=actualize').done(function () { + updateFeeds(); + }); + } +} + +function closeNotification() { + $(".notification").fadeOut(600, function () { + $(".notification").remove(); + }); +} + +function init_notifications() { + var notif = $(".notification"); + if (notif[0] !== undefined) { + window.setInterval(closeNotification, 4000); + + notif.find("a.close").click(function () { + closeNotification(); + return false; + }); + } +} + +// +var url_load_more = "", + load_more = false, + box_load_more = null; + +function load_more_posts() { + if (load_more || url_load_more === '' || box_load_more === null) { + return; + } + + load_more = true; + $('#load_more').addClass('loading'); + $.get(url_load_more, function (data) { + box_load_more.children('.flux:last').after($('#stream', data).children('.flux, .day')); + $('.pagination').replaceWith($('.pagination', data)); + $('#bigMarkAsRead').attr('href', $('#nav_menu_read_all>a').attr('href')); + + $('[id^=day_]').each(function (i) { + var ids = $('[id="' + this.id + '"]'); + if (ids.length > 1) { + $('[id="' + this.id + '"]:gt(0)').remove(); + } + }); + + init_load_more(box_load_more); + init_lazyload(); + + $('#load_more').removeClass('loading'); + load_more = false; + }); +} + +function init_load_more(box) { + var $next_link = $("#load_more"); + if (!$next_link.length) { + // no more article to load + url_load_more = ""; + return; + } + + box_load_more = box; + + url_load_more = $next_link.attr("href"); + var $prefetch = $('#prefetch'); + if ($prefetch.attr('href') !== url_load_more) { + $prefetch.attr('rel', 'next'); //Remove prefetch + $.ajax({url: url_load_more, ifModified: true }); //TODO: Try to find a less agressive solution + $prefetch.attr('href', url_load_more); + } + + $next_link.click(function () { + load_more_posts(); + return false; + }); +} +// + +// +function init_persona() { + if (!(navigator.id)) { + if (window.console) { + console.log('FreshRSS waiting for Persona…'); + } + window.setTimeout(init_persona, 100); + return; + } + $('a.signin').click(function() { + navigator.id.request(); + return false; + }); + + $('a.signout').click(function() { + navigator.id.logout(); + return false; + }); + + navigator.id.watch({ + loggedInUser: current_user_mail, + + onlogin: function(assertion) { + // A user has logged in! Here you need to: + // 1. Send the assertion to your backend for verification and to create a session. + // 2. Update your UI. + $.ajax ({ + type: 'POST', + url: url_login, + data: {assertion: assertion}, + success: function(res, status, xhr) { + /*if (res.status === 'failure') { + alert (res_obj.reason); + } else*/ if (res.status === 'okay') { + location.href = url_freshrss; + } + }, + error: function(res, status, xhr) { + alert("Login failure: " + res); + } + }); + }, + onlogout: function() { + // A user has logged out! Here you need to: + // Tear down the user's session by redirecting the user or making a call to your backend. + // Also, make sure loggedInUser will get set to null on the next page load. + // (That's a literal JavaScript null. Not false, 0, or undefined. null.) + $.ajax ({ + type: 'POST', + url: url_logout, + success: function(res, status, xhr) { + location.href = url_freshrss; + }, + error: function(res, status, xhr) { + //alert("logout failure" + res); + } + }); + } + }); +} +// + +function init_confirm_action() { + $('.confirm').click(function () { + return confirm(str_confirmation); + }); +} + +function init_print_action() { + $('.print-article').click(function () { + var content = "" + + $(".flux.current .content").html() + + ""; + + var tmp_window = window.open(); + tmp_window.document.writeln(content); + tmp_window.document.close(); + tmp_window.focus(); + tmp_window.print(); + tmp_window.close(); + + return false; + }); +} + +function init_all() { + if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) { + if (window.console) { + console.log('FreshRSS waiting for JS…'); + } + window.setTimeout(init_all, 50); + return; + } + $stream = $('#stream'); + init_posts(); + init_column_categories(); + if (load_shortcuts) { + init_shortcuts(); + } + init_stream_delegates($stream); + init_nav_entries(); + init_templates(); + init_notifications(); + init_actualize(); + init_load_more($stream); + if (use_persona) { + init_persona(); + } + init_confirm_action(); + init_print_action(); + if (window.console) { + console.log('FreshRSS init done.'); + } +} + +if (document.readyState && document.readyState !== 'loading') { + if (window.console) { + console.log('FreshRSS immediate init…'); + } + init_all(); +} else if (document.addEventListener) { + document.addEventListener('DOMContentLoaded', function () { + if (window.console) { + console.log('FreshRSS waiting for DOMContentLoaded…'); + } + init_all(); + }, false); +} -- cgit v1.2.3 From 7db271e95ebab52c31c78f51270de71af1d750d2 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Fri, 3 Jan 2014 00:01:29 -0500 Subject: Add a shortcut to open the share div. The default shortcut is "s". --- app/Models/Configuration.php | 1 + app/i18n/en.php | 1 + app/i18n/fr.php | 1 + app/views/configure/shortcut.phtml | 7 +++++++ app/views/helpers/javascript_vars.phtml | 3 ++- p/scripts/main.js | 12 ++++++++++++ 6 files changed, 24 insertions(+), 1 deletion(-) (limited to 'p/scripts/main.js') diff --git a/app/Models/Configuration.php b/app/Models/Configuration.php index d44420f56..c29e74603 100644 --- a/app/Models/Configuration.php +++ b/app/Models/Configuration.php @@ -33,6 +33,7 @@ class FreshRSS_Configuration { 'prev_entry' => 'k', 'collapse_entry' => 'c', 'load_more' => 'm', + 'auto_share' => 's', ), 'topline_read' => true, 'topline_favorite' => true, diff --git a/app/i18n/en.php b/app/i18n/en.php index 28aa1296a..06bbf48e6 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -123,6 +123,7 @@ return array ( 'next_page' => 'Skip to the next page', 'previous_page' => 'Skip to the previous page', 'collapse_article' => 'Collapse current article', + 'auto_share' => 'Share current article', 'file_to_import' => 'File to import', 'import' => 'Import', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 39aeaf29a..cb689610b 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -123,6 +123,7 @@ return array ( 'next_page' => 'Passer à la page suivante', 'previous_page' => 'Passer à la page précédente', 'collapse_article' => 'Refermer l’article courant', + 'auto_share' => 'Partager l’article courant', 'file_to_import' => 'Fichier à importer', 'import' => 'Importer', diff --git a/app/views/configure/shortcut.phtml b/app/views/configure/shortcut.phtml index 2e564a7b6..b0867f711 100644 --- a/app/views/configure/shortcut.phtml +++ b/app/views/configure/shortcut.phtml @@ -68,6 +68,13 @@ +
+ +
+ +
+
+
diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 8419b9391..92c068f7e 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -18,7 +18,8 @@ 'prev_entry:"', $s['prev_entry'], '",', 'next_entry:"', $s['next_entry'], '",', 'collapse_entry:"', $s['collapse_entry'], '",', - 'load_more:"', $s['load_more'], '"', + 'load_more:"', $s['load_more'], '",', + 'auto_share:"', $s['auto_share'], '"', "},\n"; if (Minz_Request::param ('output') === 'global') { diff --git a/p/scripts/main.js b/p/scripts/main.js index ef05eb2fb..43b0384e8 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -220,6 +220,13 @@ function collapse_entry() { $(".flux.current").toggleClass("active"); } +function auto_share() { + var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]'); + if (share.length) { + window.location.replace('/i/#' + share.attr('id')); + } +} + function inMarkViewport(flux, box_to_follow, relative_follow) { var top = flux.position().top; if (relative_follow) { @@ -338,6 +345,11 @@ function init_shortcuts() { }, { 'disable_in_input': true }); + shortcut.add(shortcuts.auto_share, function () { + auto_share(); + }, { + 'disable_in_input': true + }); // Touches de navigation shortcut.add(shortcuts.prev_entry, prev_entry, { -- cgit v1.2.3 From 4640dd934b4cfe43d67abdf05e27d279953592af Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Jan 2014 14:14:42 +0100 Subject: Corrections raccourci partage https://github.com/marienfressinaud/FreshRSS/pull/340 --- app/views/helpers/view/normal_view.phtml | 8 +++----- p/scripts/main.js | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index 50afa6903..ce036e281 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -7,11 +7,9 @@ if (!empty($this->entries)) { $display_today = true; $display_yesterday = true; $display_others = true; - if ($this->loginOk) { - $shaarli = $this->conf->sharing ('shaarli'); - $poche = $this->conf->sharing ('poche'); - $diaspora = $this->conf->sharing ('diaspora'); - } + $shaarli = $this->loginOk && $this->conf->sharing ('shaarli'); + $poche = $this->loginOk && $this->conf->sharing ('poche'); + $diaspora = $this->loginOk && $this->conf->sharing ('diaspora'); $twitter = $this->conf->sharing ('twitter'); $google_plus = $this->conf->sharing ('g+'); $facebook = $this->conf->sharing ('facebook'); diff --git a/p/scripts/main.js b/p/scripts/main.js index 43b0384e8..dbd484473 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -223,7 +223,7 @@ function collapse_entry() { function auto_share() { var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]'); if (share.length) { - window.location.replace('/i/#' + share.attr('id')); + window.location.replace('./#' + share.attr('id')); } } -- cgit v1.2.3 From b243ec163a41642307a8ed637b9c0021dfbe1cdf Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Fri, 3 Jan 2014 15:22:37 +0100 Subject: Changement de hash plus standard https://github.com/marienfressinaud/FreshRSS/pull/340 --- p/scripts/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index dbd484473..1a41dac9c 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -223,7 +223,7 @@ function collapse_entry() { function auto_share() { var share = $(".flux.current.active").find('.dropdown-target[id^="dropdown-share"]'); if (share.length) { - window.location.replace('./#' + share.attr('id')); + window.location.hash = share.attr('id'); } } -- cgit v1.2.3 From b381d2a592ebe4e3446e342fdcf961d76f33e89a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 7 Jan 2014 20:38:45 +0100 Subject: Un peu de typographie MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remplace les tirets de soustraction par points médians ou des tirets cadratins (si c'est trop long, nous pourrions mettre des demi-cadratins). * Met les abréviations des jours anglais en exposant, comme `3rd` --- app/Controllers/configureController.php | 18 +++++++++--------- app/Controllers/errorController.php | 2 +- app/Controllers/indexController.php | 6 +++--- app/i18n/en.php | 4 ++-- app/i18n/fr.php | 4 ++-- app/i18n/install.en.php | 4 ++-- app/i18n/install.fr.php | 4 ++-- app/views/configure/display.phtml | 8 ++++---- app/views/helpers/view/normal_view.phtml | 6 +++--- app/views/helpers/view/reader_view.phtml | 2 +- app/views/index/about.phtml | 2 +- p/scripts/main.js | 2 +- 12 files changed, 31 insertions(+), 31 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.php index 0a403fc2d..5b5770cbe 100755 --- a/app/Controllers/configureController.php +++ b/app/Controllers/configureController.php @@ -66,7 +66,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $this->view->feeds = $feedDAO->listFeeds (); $this->view->flux = false; - Minz_View::prependTitle (Minz_Translate::t ('categories_management') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('categories_management') . ' · '); } public function feedAction () { @@ -133,10 +133,10 @@ class FreshRSS_configure_Controller extends Minz_ActionController { Minz_Request::forward (array ('c' => 'configure', 'a' => 'feed', 'params' => array ('id' => $id)), true); } - Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' - ' . $this->view->flux->name () . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' — ' . $this->view->flux->name () . ' · '); } } else { - Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('rss_feed_management') . ' · '); } } @@ -185,7 +185,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { $this->view->themes = FreshRSS_Themes::get(); - Minz_View::prependTitle (Minz_Translate::t ('reading_configuration') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('reading_configuration') . ' · '); } public function sharingAction () { @@ -212,7 +212,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { Minz_Request::forward (array ('c' => 'configure', 'a' => 'sharing'), true); } - Minz_View::prependTitle (Minz_Translate::t ('sharing_management') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('sharing') . ' · '); } public function importExportAction () { @@ -277,7 +277,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { // au niveau de la vue, permet de ne pas voir un flux sélectionné dans la liste $this->view->flux = false; - Minz_View::prependTitle (Minz_Translate::t ('import_export_opml') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('import_export_opml') . ' · '); } public function shortcutAction () { @@ -313,11 +313,11 @@ class FreshRSS_configure_Controller extends Minz_ActionController { Minz_Request::forward (array ('c' => 'configure', 'a' => 'shortcut'), true); } - Minz_View::prependTitle (Minz_Translate::t ('shortcuts_management') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('shortcuts') . ' · '); } public function usersAction() { - Minz_View::prependTitle(Minz_Translate::t ('users') . ' - '); + Minz_View::prependTitle(Minz_Translate::t ('users') . ' · '); } public function archivingAction () { @@ -339,7 +339,7 @@ class FreshRSS_configure_Controller extends Minz_ActionController { Minz_Request::forward(array('c' => 'configure', 'a' => 'archiving'), true); } - Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' - '); + Minz_View::prependTitle(Minz_Translate::t('archiving_configuration') . ' · '); $entryDAO = new FreshRSS_EntryDAO(); $this->view->nb_total = $entryDAO->count(); diff --git a/app/Controllers/errorController.php b/app/Controllers/errorController.php index d1c2f8fec..dc9a2ee25 100644 --- a/app/Controllers/errorController.php +++ b/app/Controllers/errorController.php @@ -21,6 +21,6 @@ class FreshRSS_error_Controller extends Minz_ActionController { $this->view->logs = Minz_Request::param ('logs'); - Minz_View::prependTitle ($this->view->code . ' - '); + Minz_View::prependTitle ($this->view->code . ' · '); } } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 690ca57be..81dfefabb 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -83,7 +83,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { Minz_View::prependTitle ( $this->view->currentName . ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') . - ' - ' + ' · ' ); // On récupère les différents éléments de filtrage @@ -204,7 +204,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { } public function aboutAction () { - Minz_View::prependTitle (Minz_Translate::t ('about') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('about') . ' · '); } public function logsAction () { @@ -215,7 +215,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { ); } - Minz_View::prependTitle (Minz_Translate::t ('logs') . ' - '); + Minz_View::prependTitle (Minz_Translate::t ('logs') . ' · '); if (Minz_Request::isPost ()) { FreshRSS_LogDAO::truncate(); diff --git a/app/i18n/en.php b/app/i18n/en.php index 06bbf48e6..4588a054a 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -287,6 +287,6 @@ return array ( 'Nov' => '\N\o\v\e\m\b\e\r', 'Dec' => '\D\e\c\e\m\b\e\r', // format for date() function, %s allows to indicate month in letter - 'format_date' => '%s dS Y', - 'format_date_hour' => '%s dS Y \a\t H\.i', + 'format_date' => '%s j\<\s\u\p\>S\<\/\s\u\p\> Y', + 'format_date_hour' => '%s j\<\s\u\p\>S\<\/\s\u\p\> Y \a\t H\.i', ); diff --git a/app/i18n/fr.php b/app/i18n/fr.php index cb689610b..20085e6b4 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -287,6 +287,6 @@ return array ( 'Nov' => '\n\o\v\e\m\b\r\e', 'Dec' => '\d\é\c\e\m\b\r\e', // format pour la fonction date(), %s permet d'indiquer le mois en toutes lettres - 'format_date' => 'd %s Y', - 'format_date_hour' => '\l\e d %s Y \à H\:i', + 'format_date' => 'j %s Y', + 'format_date_hour' => '\l\e j %s Y \à H\:i', ); diff --git a/app/i18n/install.en.php b/app/i18n/install.en.php index 8145abffa..24335c6c9 100644 --- a/app/i18n/install.en.php +++ b/app/i18n/install.en.php @@ -1,8 +1,8 @@ 'Installation - FreshRSS', + 'freshrss_installation' => 'Installation · FreshRSS', 'freshrss' => 'FreshRSS', - 'installation_step' => 'Installation - step %d', + 'installation_step' => 'Installation — step %d · FreshRSS', 'steps' => 'Steps', 'checks' => 'Checks', 'general_configuration' => 'General configuration', diff --git a/app/i18n/install.fr.php b/app/i18n/install.fr.php index 3211ddf19..554d17587 100644 --- a/app/i18n/install.fr.php +++ b/app/i18n/install.fr.php @@ -1,8 +1,8 @@ 'Installation - FreshRSS', + 'freshrss_installation' => 'Installation · FreshRSS', 'freshrss' => 'FreshRSS', - 'installation_step' => 'Installation - étape %d', + 'installation_step' => 'Installation — étape %d · FreshRSS', 'steps' => 'Étapes', 'checks' => 'Vérifications', 'general_configuration' => 'Configuration générale', diff --git a/app/views/configure/display.phtml b/app/views/configure/display.phtml index 11a987610..3cc5442fb 100644 --- a/app/views/configure/display.phtml +++ b/app/views/configure/display.phtml @@ -24,7 +24,7 @@ @@ -81,7 +81,7 @@
@@ -91,7 +91,7 @@ @@ -101,7 +101,7 @@ diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index 5e46f3c8e..7e4457ecc 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -43,14 +43,14 @@ if (!empty($this->entries)) { isDay (FreshRSS_Days::TODAY, $this->today)) { ?>
- - + currentName; ?>
isDay (FreshRSS_Days::YESTERDAY, $this->today)) { ?>
- - + currentName; ?>
@@ -118,7 +118,7 @@ if (!empty($this->entries)) { link ()); - $title = urlencode ($item->title () . ' - ' . $feed->name ()); + $title = urlencode ($item->title () . ' · ' . $feed->name ()); ?> diff --git a/app/views/configure/users.phtml b/app/views/configure/users.phtml index 68111bdbe..1597004e1 100644 --- a/app/views/configure/users.phtml +++ b/app/views/configure/users.phtml @@ -20,7 +20,7 @@
- +
@@ -52,11 +52,11 @@
- $_SERVER['REMOTE_USER'] = ``
@@ -141,6 +141,14 @@ +
+ +
+ + +
+
+
conf->mail_login; ?> diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 92c068f7e..935294e60 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -30,8 +30,8 @@ if ($mail != 'null') { $mail = '"' . $mail . '"'; } - echo 'use_persona=', Minz_Configuration::authType() === 'persona' ? 'true' : 'false', - ',url_freshrss="', _url ('index', 'index'), '",', + echo 'authType="', Minz_Configuration::authType(), '",', + 'url_freshrss="', _url ('index', 'index'), '",', 'url_login="', _url ('index', 'login'), '",', 'url_logout="', _url ('index', 'logout'), '",', 'current_user_mail=', $mail, ",\n"; diff --git a/app/views/helpers/view/login.phtml b/app/views/helpers/view/login.phtml new file mode 100644 index 000000000..e4a24f9ed --- /dev/null +++ b/app/views/helpers/view/login.phtml @@ -0,0 +1,43 @@ +
+ +

+
+ +
+ +
+
+
+ +
+ + + +
+
+
+
+ +
+
+

FreshRSS

+

+ +

+
diff --git a/app/views/index/index.phtml b/app/views/index/index.phtml index 549d0b61e..9b69233e9 100644 --- a/app/views/index/index.phtml +++ b/app/views/index/index.phtml @@ -1,15 +1,5 @@
-

-

-

-
loginOk || Minz_Configuration::allowAnonymous()) { @@ -31,8 +21,8 @@ if ($this->loginOk || Minz_Configuration::allowAnonymous()) { if ($token_is_ok) { $this->renderHelper ('view/rss_view'); } else { - showForbidden(); + $this->renderHelper ('view/login'); } } else { - showForbidden(); + $this->renderHelper ('view/login'); } diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php index 2c30661ed..433992e0d 100644 --- a/lib/Minz/Configuration.php +++ b/lib/Minz/Configuration.php @@ -109,7 +109,7 @@ class Minz_Configuration { return self::$auth_type !== 'none'; } public static function canLogIn() { - return self::$auth_type === 'persona'; + return self::$auth_type === 'form' || self::$auth_type === 'persona'; } public static function _allowAnonymous($allow = false) { @@ -118,6 +118,7 @@ class Minz_Configuration { public static function _authType($value) { $value = strtolower($value); switch ($value) { + case 'form': case 'http_auth': case 'persona': case 'none': diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php index 7b8526bc8..80eda8877 100644 --- a/lib/Minz/FrontController.php +++ b/lib/Minz/FrontController.php @@ -34,7 +34,7 @@ class Minz_FrontController { */ public function __construct () { if (LOG_PATH === false) { - $this->killApp ('Path doesn’t exist : LOG_PATH'); + $this->killApp ('Path not found: LOG_PATH'); } try { diff --git a/p/scripts/main.js b/p/scripts/main.js index 24af1b210..0c4c3f1b2 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -587,6 +587,54 @@ function init_load_more(box) { } // +// +function poormanSalt() { //If crypto.getRandomValues is not available + var text = '$2a$04$', + base = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ.0123456789/abcdefghijklmnopqrstuvwxyz'; + for (var i = 22; i > 0; i--) { + text += base.charAt(Math.floor(Math.random() * 64)); + } + return text; +} + +function init_loginForm() { + var $loginForm = $('#loginForm'); + if ($loginForm.length === 0) { + return; + } + if (!(window.dcodeIO)) { + if (window.console) { + console.log('FreshRSS waiting for bcrypt.js…'); + } + window.setTimeout(init_loginForm, 100); + return; + } + $loginForm.on('submit', function() { + $('#loginButton').attr('disabled', ''); + var success = false; + $.ajax({ + url: './?c=javascript&a=nonce&user=' + $('#username').val(), + dataType: 'json', + async: false + }).done(function (data) { + if (data.salt1 == '' || data.nonce == '') { + alert('Invalid user!'); + } else { + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + success = true; + } + }).fail(function() { + alert('Communication error!'); + }); + $('#loginButton').removeAttr('disabled'); + return success; + }); +} +// + // function init_persona() { if (!(navigator.id)) { @@ -696,8 +744,13 @@ function init_all() { init_notifications(); init_actualize(); init_load_more($stream); - if (use_persona) { - init_persona(); + switch (authType) { + case 'form': + init_loginForm(); + break; + case 'persona': + init_persona(); + break; } init_confirm_action(); init_print_action(); -- cgit v1.2.3 From 4de5e6c2756f2a300014b80108cf2bf5e91f69a3 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 12 Jan 2014 20:26:26 +0100 Subject: Corrige problème CSS partage/tags + problème raffraîchissement automatique des articles non-lus MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit + Léger nettoyage JavaScript --- app/views/helpers/javascript_vars.phtml | 2 -- p/scripts/main.js | 53 +++++++++++++++++---------------- p/themes/default/freshrss.css | 4 ++- p/themes/default_dark/freshrss.css | 4 ++- p/themes/flat-design/freshrss.css | 4 ++- 5 files changed, 36 insertions(+), 31 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 935294e60..f4f36b4f3 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -36,8 +36,6 @@ 'url_logout="', _url ('index', 'logout'), '",', 'current_user_mail=', $mail, ",\n"; - echo 'load_shortcuts=', Minz_Request::controllerName () === 'index' && Minz_Request::actionName () === 'index' ? 'true' : 'false', ",\n"; - echo 'str_confirmation="', Minz_Translate::t('confirm_action'), '"', ",\n"; $autoActualise = Minz_Session::param('actualize_feeds', false); diff --git a/p/scripts/main.js b/p/scripts/main.js index 0c4c3f1b2..7415d0c24 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -61,7 +61,11 @@ function incUnreadsFeed(article, feed_id, nb) { //Update unread: title document.title = document.title.replace(/((?: \(\d+\))?)( · .*?)((?: \(\d+\))?)$/, function (m, p1, p2, p3) { - return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); + if (article || ($('#' + feed_id).closest('.active').length > 0)) { + return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); + } else { + return p1 + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); + } }); } @@ -312,6 +316,14 @@ function init_column_categories() { $(this).parent().next(".feeds").slideToggle(); return false; }); + $('#aside_flux').on('click', '.feeds .dropdown-toggle', function () { + if ($(this).nextAll('.dropdown-menu').length === 0) { + var feed_id = $(this).closest('li').attr('id').substr(2), + feed_web = $(this).data('fweb'), + template = $('#feed_config_template').html().replace(/!!!!!!/g, feed_id).replace('http://example.net/', feed_web); + $(this).attr('href', '#dropdown-' + feed_id).prev('.dropdown-target').attr('id', 'dropdown-' + feed_id).parent().append(template); + } + }); } function init_shortcuts() { @@ -403,7 +415,7 @@ function init_shortcuts() { }); } -function init_stream_delegates(divStream) { +function init_stream(divStream) { divStream.on('click', '.flux_header', function (e) { //flux_header_toggle if ($(e.target).closest('.item.website > a').length > 0) { return; @@ -475,17 +487,6 @@ function init_nav_entries() { }); } -function init_templates() { - $('#aside_flux').on('click', '.feeds .dropdown-toggle', function () { - if ($(this).nextAll('.dropdown-menu').length === 0) { - var feed_id = $(this).closest('li').attr('id').substr(2), - feed_web = $(this).data('fweb'), - template = $('#feed_config_template').html().replace(/!!!!!!/g, feed_id).replace('http://example.net/', feed_web); - $(this).attr('href', '#dropdown-' + feed_id).prev('.dropdown-target').attr('id', 'dropdown-' + feed_id).parent().append(template); - } - }); -} - function init_actualize() { $("#actualize").click(function () { $.getScript('./?c=javascript&a=actualize').done(function () { @@ -732,18 +733,7 @@ function init_all() { window.setTimeout(init_all, 50); return; } - $stream = $('#stream'); - init_posts(); - init_column_categories(); - if (load_shortcuts) { - init_shortcuts(); - } - init_stream_delegates($stream); - init_nav_entries(); - init_templates(); init_notifications(); - init_actualize(); - init_load_more($stream); switch (authType) { case 'form': init_loginForm(); @@ -753,8 +743,19 @@ function init_all() { break; } init_confirm_action(); - init_print_action(); - window.setInterval(refreshUnreads, 120000); + $stream = $('#stream'); + if ($stream.length > 0) { + init_actualize(); + init_column_categories(); + init_load_more($stream); + init_posts(); + init_stream($stream); + init_nav_entries(); + init_shortcuts(); + init_print_action(); + window.setInterval(refreshUnreads, 120000); + } + if (window.console) { console.log('FreshRSS init done.'); } diff --git a/p/themes/default/freshrss.css b/p/themes/default/freshrss.css index 733807938..593f21d30 100644 --- a/p/themes/default/freshrss.css +++ b/p/themes/default/freshrss.css @@ -259,9 +259,11 @@ } .flux .item { line-height: 40px; + white-space: nowrap; + } + .flux_header > .item { overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; } .flux .item.manage { width: 40px; diff --git a/p/themes/default_dark/freshrss.css b/p/themes/default_dark/freshrss.css index 884e2884d..e9eb2c705 100644 --- a/p/themes/default_dark/freshrss.css +++ b/p/themes/default_dark/freshrss.css @@ -250,9 +250,11 @@ } .flux .item { line-height: 40px; + white-space: nowrap; + } + .flux_header > .item { overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; } .flux .item.manage { width: 40px; diff --git a/p/themes/flat-design/freshrss.css b/p/themes/flat-design/freshrss.css index df1dfdde3..dca1b3f28 100644 --- a/p/themes/flat-design/freshrss.css +++ b/p/themes/flat-design/freshrss.css @@ -245,9 +245,11 @@ body { } .flux .item { line-height: 40px; + white-space: nowrap; + } + .flux_header > .item { overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; } .flux .item.manage { width: 40px; -- cgit v1.2.3 From 7516549f60462a7bb7d5998300491df9d7e5fe82 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 13 Jan 2014 20:07:43 +0100 Subject: Ferme le dernier article lorsqu'il n'y a pas de suivant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Permet de mieux voir qu'on est arrivé à la fin de la liste des articles. + Bonne optimisation JavaScript de prev_entry() next_entry() avec réduction du code et évitement des opérations inutiles. --- p/scripts/main.js | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index 7415d0c24..5bdc316db 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -70,7 +70,7 @@ function incUnreadsFeed(article, feed_id, nb) { } function mark_read(active, only_not_read) { - if (active[0] === undefined || (only_not_read === true && !active.hasClass("not_read"))) { + if (active.length === 0 || (only_not_read === true && !active.hasClass("not_read"))) { return false; } @@ -102,7 +102,7 @@ function mark_read(active, only_not_read) { } function mark_favorite(active) { - if (active[0] === undefined) { + if (active.length === 0) { return false; } @@ -143,6 +143,12 @@ function mark_favorite(active) { } function toggleContent(new_active, old_active) { + old_active.removeClass("active").removeClass("current"); + + if (new_active.length === 0) { + return; + } + if (does_lazyload) { new_active.find('img[data-original], iframe[data-original]').each(function () { this.setAttribute('src', this.getAttribute('data-original')); @@ -150,7 +156,6 @@ function toggleContent(new_active, old_active) { }); } - old_active.removeClass("active").removeClass("current"); if (old_active[0] !== new_active[0]) { if (isCollapsed) { new_active.addClass("active"); @@ -196,30 +201,20 @@ function toggleContent(new_active, old_active) { function prev_entry() { var old_active = $(".flux.current"), - last_active = $(".flux:last"), - new_active = old_active.prevAll(".flux:first"); - - if (new_active.hasClass("flux")) { - toggleContent(new_active, old_active); - } else if (old_active[0] === undefined && new_active[0] === undefined) { - toggleContent(last_active, old_active); - } + new_active = old_active.length === 0 ? $(".flux:last") : old_active.prevAll(".flux:first"); + toggleContent(new_active, old_active); } function next_entry() { var old_active = $(".flux.current"), - first_active = $(".flux:first"), - last_active = $(".flux:last"), - new_active = old_active.nextAll(".flux:first"); - - if (new_active.hasClass("flux")) { - toggleContent(new_active, old_active); - } else if (old_active[0] === undefined && new_active[0] === undefined) { - toggleContent(first_active, old_active); - } + new_active = old_active.length === 0 ? $(".flux:first") : old_active.nextAll(".flux:first"); + toggleContent(new_active, old_active); - if ((!auto_load_more) && (last_active.attr("id") === new_active.attr("id"))) { - load_more_posts(); + if (!auto_load_more) { + var last_active = $(".flux:last"); + if (last_active.attr("id") === new_active.attr("id")) { + load_more_posts(); + } } } @@ -510,7 +505,7 @@ function closeNotification() { function init_notifications() { var notif = $(".notification"); - if (notif[0] !== undefined) { + if (notif.length > 0) { window.setInterval(closeNotification, 4000); notif.find("a.close").click(function () { @@ -625,7 +620,11 @@ function init_loginForm() { s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); $('#challenge').val(c); - success = true; + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; + } } }).fail(function() { alert('Communication error!'); -- cgit v1.2.3 From fdd179d344dbe8734480b83bb7a0fba189275d5a Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 18 Jan 2014 19:29:44 +0100 Subject: Corrections vue globale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Contribue à https://github.com/marienfressinaud/FreshRSS/issues/353 --- app/Controllers/entryController.php | 2 +- app/Controllers/indexController.php | 6 ++---- app/views/helpers/view/global_view.phtml | 16 ++++++++++------ lib/Minz/View.php | 6 +++--- p/scripts/global_view.js | 10 ++++++++++ p/scripts/main.js | 8 +++++--- 6 files changed, 31 insertions(+), 17 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/Controllers/entryController.php b/app/Controllers/entryController.php index ded7598d9..1756c91e5 100755 --- a/app/Controllers/entryController.php +++ b/app/Controllers/entryController.php @@ -11,7 +11,7 @@ class FreshRSS_entry_Controller extends Minz_ActionController { $this->params = array (); $output = Minz_Request::param('output', ''); - if (($output != '') && ($this->conf->view_mode !== $output)) { + if (($output != '') && ($this->view->conf->view_mode !== $output)) { $this->params['output'] = $output; } diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index d05a106bb..45ded6fd4 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -46,10 +46,8 @@ class FreshRSS_index_Controller extends Minz_ActionController { // no layout for RSS output $this->view->_useLayout (false); header('Content-Type: application/rss+xml; charset=utf-8'); - } else { - if ($output === 'global') { - Minz_View::appendScript (Minz_Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); - } + } elseif ($output === 'global') { + Minz_View::appendScript (Minz_Url::display ('/scripts/global_view.js?' . @filemtime(PUBLIC_PATH . '/scripts/global_view.js'))); } $this->view->cat_aside = $this->catDAO->listCategories (); diff --git a/app/views/helpers/view/global_view.phtml b/app/views/helpers/view/global_view.phtml index ca7b66e0c..4fb807649 100644 --- a/app/views/helpers/view/global_view.phtml +++ b/app/views/helpers/view/global_view.phtml @@ -2,18 +2,22 @@
'index', 'a' => 'index', 'params' => array()); + if ($this->conf->view_mode !== 'normal') { + $arUrl['params']['output'] = 'normal'; } + $p = Minz_Request::param('state', ''); + if (($p != '') && ($this->conf->default_view !== $p)) { + $arUrl['params']['state'] = $p; + } + foreach ($this->cat_aside as $cat) { $feeds = $cat->feeds (); if (!empty ($feeds)) { ?>
@@ -22,7 +26,7 @@ nbNotRead (); ?>
  • ✇ - + name(); ?>
  • diff --git a/lib/Minz/View.php b/lib/Minz/View.php index ba9555cd7..e170bd406 100644 --- a/lib/Minz/View.php +++ b/lib/Minz/View.php @@ -63,7 +63,7 @@ class Minz_View { * Affiche la Vue en elle-même */ public function render () { - if ((@include($this->view_filename)) === false) { + if ((include($this->view_filename)) === false) { Minz_Log::record ('File not found: `' . $this->view_filename . '`', Minz_Log::NOTICE); @@ -79,7 +79,7 @@ class Minz_View { . self::LAYOUT_PATH_NAME . '/' . $part . '.phtml'; - if ((@include($fic_partial)) === false) { + if ((include($fic_partial)) === false) { Minz_Log::record ('File not found: `' . $fic_partial . '`', Minz_Log::WARNING); @@ -95,7 +95,7 @@ class Minz_View { . '/views/helpers/' . $helper . '.phtml'; - if ((@include($fic_helper)) === false) {; + if ((include($fic_helper)) === false) {; Minz_Log::record ('File not found: `' . $fic_helper . '`', Minz_Log::WARNING); diff --git a/p/scripts/global_view.js b/p/scripts/global_view.js index c34fbf1a7..3973cb2ec 100644 --- a/p/scripts/global_view.js +++ b/p/scripts/global_view.js @@ -24,6 +24,16 @@ function load_panel(link) { // en en ouvrant une autre ensuite, on se retrouve au même point de scroll $("#panel").scrollTop(0); + $('#nav_menu_read_all a, #bigMarkAsRead').click(function () { + $.ajax({ + url: $(this).attr("href"), + async: false + }); + //$("#panel .close").first().click(); + window.location.reload(false); + return false; + }); + panel_loading = false; }); } diff --git a/p/scripts/main.js b/p/scripts/main.js index 5bdc316db..3f6352baf 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -137,7 +137,9 @@ function mark_favorite(active) { if (active.closest('div').hasClass('not_read')) { var elem = $('#aside_flux .favorites').children(':first').get(0), feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - elem.setAttribute('data-unread', Math.max(0, feed_unreads + inc)); + if (elem) { + elem.setAttribute('data-unread', Math.max(0, feed_unreads + inc)); + } } }); } @@ -559,6 +561,8 @@ function load_more_posts() { } function init_load_more(box) { + box_load_more = box; + var $next_link = $("#load_more"); if (!$next_link.length) { // no more article to load @@ -566,8 +570,6 @@ function init_load_more(box) { return; } - box_load_more = box; - url_load_more = $next_link.attr("href"); var $prefetch = $('#prefetch'); if ($prefetch.attr('href') !== url_load_more) { -- cgit v1.2.3 From 2a6443a0f0f52272e1e3269d0c32f56322a9a3ec Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Sat, 25 Jan 2014 14:06:34 +0100 Subject: Demande rafraîchissement page quand nvx articles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout d'une indication pour rafraîchir la page si de nouveaux articles ont été détectés via le serveur Voir #379 --- app/i18n/en.php | 1 + app/i18n/fr.php | 1 + app/views/helpers/view/normal_view.phtml | 7 +++++++ p/scripts/main.js | 9 +++++++++ p/themes/Dark/freshrss.css | 19 +++++++++++++++++++ p/themes/Flat/freshrss.css | 19 +++++++++++++++++++ p/themes/Origine/freshrss.css | 19 +++++++++++++++++++ 7 files changed, 75 insertions(+) (limited to 'p/scripts/main.js') diff --git a/app/i18n/en.php b/app/i18n/en.php index 683d7ca22..5d9b01f0b 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -241,6 +241,7 @@ return array ( 'today' => 'Today', 'yesterday' => 'Yesterday', 'before_yesterday' => 'Before yesterday', + 'new_article' => 'There are new available articles, click to refresh the page.', 'by_author' => 'By %s', 'related_tags' => 'Related tags', 'no_feed_to_display' => 'There is no article to show.', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index c20bf98e7..fd2257c70 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -241,6 +241,7 @@ return array ( 'today' => 'Aujourd’hui', 'yesterday' => 'Hier', 'before_yesterday' => 'À partir d’avant-hier', + 'new_article' => 'Il y a de nouveaux articles disponibles, cliquez pour rafraîchir la page.', 'by_author' => 'Par %s', 'related_tags' => 'Tags associés', 'no_feed_to_display' => 'Il n’y a aucun article à afficher.', diff --git a/app/views/helpers/view/normal_view.phtml b/app/views/helpers/view/normal_view.phtml index a1df87579..af5ff03fe 100644 --- a/app/views/helpers/view/normal_view.phtml +++ b/app/views/helpers/view/normal_view.phtml @@ -63,6 +63,13 @@ if (!empty($this->entries)) { $display_others = false; } + if ($this->entries[0]->id () === $item->id ()) { + ?>
    +
      loginOk) { diff --git a/p/scripts/main.js b/p/scripts/main.js index 3f6352baf..0c3a5fa3d 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -519,12 +519,21 @@ function init_notifications() { function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { + var new_article = false; $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads); + + if (nbUnreads - feed_unreads > 0) { + new_article = true; + } }); + + if (new_article) { + $('#new-article').show(); + } }); } diff --git a/p/themes/Dark/freshrss.css b/p/themes/Dark/freshrss.css index c394ad98b..2ad30fab2 100644 --- a/p/themes/Dark/freshrss.css +++ b/p/themes/Dark/freshrss.css @@ -224,6 +224,25 @@ text-align: right; } +#new-article { + display: none; + min-height: 40px; + background: #26303F; + text-align: center; +} + #new-article:hover { + background: #4A5D7A; + } + #new-article a { + display: block; + line-height: 40px; + color: #fff; + font-weight: bold; + } + #new-article a:hover { + text-decoration: none; + } + .flux { border-left: 3px solid #aaa; background: #1c1c1c; diff --git a/p/themes/Flat/freshrss.css b/p/themes/Flat/freshrss.css index b2d92f86b..80e0da330 100644 --- a/p/themes/Flat/freshrss.css +++ b/p/themes/Flat/freshrss.css @@ -217,6 +217,25 @@ body { z-index: -10; } +#new-article { + display: none; + min-height: 40px; + background: #3498db; + text-align: center; +} + #new-article:hover { + background: #2980b9; + } + #new-article a { + display: block; + line-height: 40px; + color: #fff; + font-weight: bold; + } + #new-article a:hover { + text-decoration: none; + } + .flux { border-left: 3px solid #ecf0f1; } diff --git a/p/themes/Origine/freshrss.css b/p/themes/Origine/freshrss.css index 86745af1a..bedeff695 100644 --- a/p/themes/Origine/freshrss.css +++ b/p/themes/Origine/freshrss.css @@ -230,6 +230,25 @@ text-align: right; } +#new-article { + display: none; + min-height: 40px; + background: #0084CC; + text-align: center; +} + #new-article:hover { + background: #0066CC; + } + #new-article a { + display: block; + line-height: 40px; + color: #fff; + font-weight: bold; + } + #new-article a:hover { + text-decoration: none; + } + .flux { border-left: 3px solid #aaa; background: #fafafa; -- cgit v1.2.3 From fa03aedac75a6ccb62b889e22fa0ec2e848cfa0b Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 25 Jan 2014 16:07:50 +0100 Subject: Message articles disponibles uniquement lorsque approprié MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ne montre le message articles disponibles uniquement lorsque la vue en cours est concernée https://github.com/marienfressinaud/FreshRSS/issues/379 --- p/scripts/main.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index 0c3a5fa3d..93e0c53b3 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -59,14 +59,17 @@ function incUnreadsFeed(article, feed_id, nb) { } } + var isCurrentView = false; //Update unread: title document.title = document.title.replace(/((?: \(\d+\))?)( · .*?)((?: \(\d+\))?)$/, function (m, p1, p2, p3) { if (article || ($('#' + feed_id).closest('.active').length > 0)) { + isCurrentView = true; return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); } else { return p1 + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); } }); + return isCurrentView; } function mark_read(active, only_not_read) { @@ -519,21 +522,15 @@ function init_notifications() { function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { - var new_article = false; $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads); - - if (nbUnreads - feed_unreads > 0) { - new_article = true; - } + if (incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) && //Update of current view? + (nbUnreads - feed_unreads > 0)) { + $('#new-article').show(); + }; }); - - if (new_article) { - $('#new-article').show(); - } }); } -- cgit v1.2.3 From fbf48f5861b18714986b7fba1dc57642ba29a8b5 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 25 Jan 2014 16:37:02 +0100 Subject: Bug articles disponibles https://github.com/marienfressinaud/FreshRSS/issues/379 --- p/scripts/main.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index 93e0c53b3..d891299a8 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -62,7 +62,8 @@ function incUnreadsFeed(article, feed_id, nb) { var isCurrentView = false; //Update unread: title document.title = document.title.replace(/((?: \(\d+\))?)( · .*?)((?: \(\d+\))?)$/, function (m, p1, p2, p3) { - if (article || ($('#' + feed_id).closest('.active').length > 0)) { + var $feed = $('#' + feed_id); + if (article || ($feed.closest('.active').length > 0 && $feed.siblings('.active').length === 0)) { isCurrentView = true; return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); } else { @@ -522,11 +523,12 @@ function init_notifications() { function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { + var isAll = $('.category.all > .active').length > 0; $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - if (incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) && //Update of current view? + if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? (nbUnreads - feed_unreads > 0)) { $('#new-article').show(); }; -- cgit v1.2.3 From 7a510af73a0ef04ce09fb7eedd98c844e7bff51c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 26 Jan 2014 19:06:42 +0100 Subject: Compatibilité bcrypt.js oubliée MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Corrige https://github.com/marienfressinaud/FreshRSS/issues/396 + Ajoute de meilleurs messages d'erreur --- app/Controllers/indexController.php | 2 ++ app/Controllers/javascriptController.php | 2 +- app/Controllers/usersController.php | 1 + p/scripts/main.js | 20 ++++++++++++-------- 4 files changed, 16 insertions(+), 9 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index cb6be6049..c49054a5c 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -320,6 +320,8 @@ class FreshRSS_index_Controller extends Minz_ActionController { } catch (Minz_Exception $me) { Minz_Log::record('Login failure: ' . $me->getMessage(), Minz_Log::WARNING); } + } else { + Minz_Log::record('Invalid credential parameters: user=' . $username . ' challenge=' . $c . ' nonce=' . $nonce, Minz_Log::DEBUG); } if (!$ok) { $notif = array( diff --git a/app/Controllers/javascriptController.php b/app/Controllers/javascriptController.php index 02e424437..b879dcd6d 100755 --- a/app/Controllers/javascriptController.php +++ b/app/Controllers/javascriptController.php @@ -37,7 +37,7 @@ class FreshRSS_javascript_Controller extends Minz_ActionController { return; //Success } } catch (Minz_Exception $me) { - Minz_Log::record('Login failure: ' . $me->getMessage(), Minz_Log::WARNING); + Minz_Log::record('Nonce failure: ' . $me->getMessage(), Minz_Log::WARNING); } } $this->view->nonce = ''; //Failure diff --git a/app/Controllers/usersController.php b/app/Controllers/usersController.php index a044cd25b..8314b75fc 100644 --- a/app/Controllers/usersController.php +++ b/app/Controllers/usersController.php @@ -106,6 +106,7 @@ class FreshRSS_users_Controller extends Minz_ActionController { } $passwordHash = password_hash($passwordPlain, PASSWORD_BCRYPT, array('cost' => self::BCRYPT_COST)); $passwordPlain = ''; + $passwordHash = preg_replace('/^\$2[xy]\$/', '\$2a\$', $passwordHash); //Compatibility with bcrypt.js $ok &= ($passwordHash != ''); } if (empty($passwordHash)) { diff --git a/p/scripts/main.js b/p/scripts/main.js index d891299a8..d775b3a20 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -626,14 +626,18 @@ function init_loginForm() { if (data.salt1 == '' || data.nonce == '') { alert('Invalid user!'); } else { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; + try { + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; + } + } catch (e) { + alert('Crypto exception! ' + e); } } }).fail(function() { -- cgit v1.2.3 From 9da20e18942139b0673034dcba2b9256b62563f6 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 19:53:54 +0100 Subject: Formatage du nombre de non lus --- p/scripts/main.js | 82 +++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 24 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index d775b3a20..be5f4f3e4 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -25,28 +25,43 @@ function incLabel(p, inc) { return i > 0 ? ' (' + i + ')' : ''; } +function numberFormat(nStr) { + // Thx to http://www.mredkj.com/javascript/numberFormat.html + nStr += ''; + var x = nStr.split('.'); + var x1 = x[0]; + var x2 = x.length > 1 ? '.' + x[1] : ''; + var rgx = /(\d+)(\d{3})/; + while (rgx.test(x1)) { + x1 = x1.replace(rgx, '$1' + " " + '$2'); + } + return x1 + x2; +} + function incUnreadsFeed(article, feed_id, nb) { + //Update unread: feed var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0, + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0, feed_priority = elem ? (parseInt(elem.getAttribute('data-priority'), 10) || 0) : 0; if (elem) { - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } //Update unread: category elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0); - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if (elem) { - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } //Update unread: all if (feed_priority > 0) { elem = $('#aside_flux .all').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + alert(elem.getAttribute('data-unread') + "\n" + feed_unreads); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } @@ -54,8 +69,8 @@ function incUnreadsFeed(article, feed_id, nb) { if (article && article.closest('div').hasClass('favorite')) { elem = $('#aside_flux .favorites').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; - elem.setAttribute('data-unread', Math.max(0, feed_unreads + nb)); + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } @@ -140,9 +155,9 @@ function mark_favorite(active) { if (active.closest('div').hasClass('not_read')) { var elem = $('#aside_flux .favorites').children(':first').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if (elem) { - elem.setAttribute('data-unread', Math.max(0, feed_unreads + inc)); + elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + inc))); } } }); @@ -527,7 +542,7 @@ function refreshUnreads() { $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread'), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? (nbUnreads - feed_unreads > 0)) { $('#new-article').show(); @@ -626,18 +641,14 @@ function init_loginForm() { if (data.salt1 == '' || data.nonce == '') { alert('Invalid user!'); } else { - try { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; - } - } catch (e) { - alert('Crypto exception! ' + e); + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; } } }).fail(function() { @@ -738,6 +749,29 @@ function init_print_action() { }); } +function init_number_format_unreads() { + // Init global counter + var elem = $('#aside_flux .categories li .all a'); + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + + // Init favorites counter + elem = $('#aside_flux .categories li .favorites a'); + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + + // Init feeds counters + $('#aside_flux .categories li .stick').each(function() { + // Category-level counter + elem = $(this).find('a'); + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + + // Feeds counters + $(this).parent().find('ul.feeds li.item').each(function() { + elem = $(this).find('a.feed'); // There are two links here. a.feed is the title. + elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + }); + }); +} + function init_all() { if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) { if (window.console) { @@ -768,7 +802,7 @@ function init_all() { init_print_action(); window.setInterval(refreshUnreads, 120000); } - + init_number_format_unreads(); if (window.console) { console.log('FreshRSS init done.'); } -- cgit v1.2.3 From ec720c4f69759fb08bf07ef322eb2ecac187909f Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 20:31:38 +0100 Subject: Formatage du nombre de favoris --- p/scripts/main.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index be5f4f3e4..87df5b551 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -20,11 +20,6 @@ function redirect(url, new_tab) { } } -function incLabel(p, inc) { - var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc; - return i > 0 ? ' (' + i + ')' : ''; -} - function numberFormat(nStr) { // Thx to http://www.mredkj.com/javascript/numberFormat.html nStr += ''; @@ -38,6 +33,11 @@ function numberFormat(nStr) { return x1 + x2; } +function incLabel(p, inc) { + var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc; + return i > 0 ? ' (' + numberFormat(i) + ')' : ''; +} + function incUnreadsFeed(article, feed_id, nb) { //Update unread: feed @@ -148,7 +148,10 @@ function mark_favorite(active) { var favourites = $('.favorites>a').contents().last().get(0); if (favourites && favourites.textContent) { - favourites.textContent = favourites.textContent.replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { + // Without javascript, the text displayed is « Favorites (1544) » where 1544 is the number unformatted. + // With Javascript, we replace this with « Favorites (1 544) ». To update this, the text is converted + // to the non-javascript format before. + favourites.textContent = favourites.textContent.replace(/ /g, '').replace('(', ' (').replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { return incLabel(p1, inc); }); } @@ -749,15 +752,20 @@ function init_print_action() { }); } -function init_number_format_unreads() { +function init_number_formats() { // Init global counter var elem = $('#aside_flux .categories li .all a'); elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); - // Init favorites counter + // Init favorites counters elem = $('#aside_flux .categories li .favorites a'); elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); + var numFavorites = elem.text().replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { + return numberFormat(p1) + }); + elem.text(numFavorites); + // Init feeds counters $('#aside_flux .categories li .stick').each(function() { // Category-level counter @@ -802,7 +810,7 @@ function init_all() { init_print_action(); window.setInterval(refreshUnreads, 120000); } - init_number_format_unreads(); + init_number_formats(); if (window.console) { console.log('FreshRSS init done.'); } -- cgit v1.2.3 From 0a1a7816093f0593dd140e664cbd09e79c0833c3 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 21:26:46 +0100 Subject: Suppression d'un message de débogage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- p/scripts/main.js | 1 - 1 file changed, 1 deletion(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index 87df5b551..bd9321202 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -60,7 +60,6 @@ function incUnreadsFeed(article, feed_id, nb) { elem = $('#aside_flux .all').children(':first').get(0); if (elem) { feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; - alert(elem.getAttribute('data-unread') + "\n" + feed_unreads); elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } -- cgit v1.2.3 From 19eefd434c45791ff48c0b5a9ecc642da72b71da Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 21:36:42 +0100 Subject: Correction d'un conflit de PR Conflit avec le commit https://github.com/marienfressinaud/FreshRSS/commit/7a510af73a0ef04ce09fb7eedd98c844e7bff51c --- p/scripts/main.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index bd9321202..ed3cf3779 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -643,15 +643,19 @@ function init_loginForm() { if (data.salt1 == '' || data.nonce == '') { alert('Invalid user!'); } else { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; - } + try { + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; + } + } catch (e) { + alert('Crypto exception! ' + e); + } } }).fail(function() { alert('Communication error!'); -- cgit v1.2.3 From d56f51d5fc375ef808433d9f32455dab28d71c84 Mon Sep 17 00:00:00 2001 From: Amaury Carrade Date: Sun, 26 Jan 2014 21:39:21 +0100 Subject: Style de code --- p/scripts/main.js | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index ed3cf3779..ddfa0aec8 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -644,18 +644,18 @@ function init_loginForm() { alert('Invalid user!'); } else { try { - var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), - s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), - c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); - $('#challenge').val(c); - if (s == '' || c == '') { - alert('Crypto error!'); - } else { - success = true; - } - } catch (e) { - alert('Crypto exception! ' + e); - } + var strong = window.Uint32Array && window.crypto && (typeof window.crypto.getRandomValues === 'function'), + s = dcodeIO.bcrypt.hashSync($('#passwordPlain').val(), data.salt1), + c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); + $('#challenge').val(c); + if (s == '' || c == '') { + alert('Crypto error!'); + } else { + success = true; + } + } catch (e) { + alert('Crypto exception! ' + e); + } } }).fail(function() { alert('Communication error!'); -- cgit v1.2.3 From fdefc8c731c05d8a7db626e55fe41d7211488f98 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Mon, 27 Jan 2014 22:35:27 +0100 Subject: Formatage des nombres https://github.com/marienfressinaud/FreshRSS/pull/398 --- app/Controllers/indexController.php | 4 +-- app/layout/aside_flux.phtml | 10 +++--- app/views/helpers/view/global_view.phtml | 4 +-- lib/lib_rss.php | 2 +- p/scripts/main.js | 58 +++++++++----------------------- 5 files changed, 25 insertions(+), 53 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index c49054a5c..70560b98b 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -66,11 +66,11 @@ class FreshRSS_index_Controller extends Minz_ActionController { // mise à jour des titres $this->view->rss_title = $this->view->currentName . ' | ' . Minz_View::title(); if ($this->view->nb_not_read > 0) { - Minz_View::appendTitle (' (' . $this->view->nb_not_read . ')'); + Minz_View::appendTitle (' (' . formatNumber($this->view->nb_not_read) . ')'); } Minz_View::prependTitle ( $this->view->currentName . - ($this->nb_not_read_cat > 0 ? ' (' . $this->nb_not_read_cat . ')' : '') . + ($this->nb_not_read_cat > 0 ? ' (' . formatNumber($this->nb_not_read_cat) . ')' : '') . ' · ' ); diff --git a/app/layout/aside_flux.phtml b/app/layout/aside_flux.phtml index 1e3211886..8454b4459 100644 --- a/app/layout/aside_flux.phtml +++ b/app/layout/aside_flux.phtml @@ -21,7 +21,7 @@ ?>
    • - + @@ -30,9 +30,9 @@
    • @@ -47,7 +47,7 @@ $c_active = true; } ?>
    ✇ name(); ?>name(); ?>
    @@ -26,7 +26,7 @@ nbNotRead (); ?>
  • ✇ - + name(); ?>
  • diff --git a/lib/lib_rss.php b/lib/lib_rss.php index b953f96ce..1bb117ab6 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -63,7 +63,7 @@ function small_hash ($txt) { } function formatNumber($n, $precision = 0) { - return str_replace(' ', ' ', //Espace fine insécable + return str_replace(' ', ' ', //Espace insécable //TODO: remplacer par une espace _fine_ insécable number_format($n, $precision, '.', ' ')); //number_format does not seem to be Unicode-compatible } diff --git a/p/scripts/main.js b/p/scripts/main.js index ddfa0aec8..4ee861ade 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -21,14 +21,14 @@ function redirect(url, new_tab) { } function numberFormat(nStr) { - // Thx to http://www.mredkj.com/javascript/numberFormat.html + // http://www.mredkj.com/javascript/numberFormat.html nStr += ''; - var x = nStr.split('.'); - var x1 = x[0]; - var x2 = x.length > 1 ? '.' + x[1] : ''; - var rgx = /(\d+)(\d{3})/; + var x = nStr.split('.'), + x1 = x[0], + x2 = x.length > 1 ? '.' + x[1] : '', + rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) { - x1 = x1.replace(rgx, '$1' + " " + '$2'); + x1 = x1.replace(rgx, '$1' + ' ' + '$2'); } return x1 + x2; } @@ -42,7 +42,7 @@ function incUnreadsFeed(article, feed_id, nb) { //Update unread: feed var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0, + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0, feed_priority = elem ? (parseInt(elem.getAttribute('data-priority'), 10) || 0) : 0; if (elem) { elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); @@ -50,7 +50,7 @@ function incUnreadsFeed(article, feed_id, nb) { //Update unread: category elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0); - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if (elem) { elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } @@ -59,7 +59,7 @@ function incUnreadsFeed(article, feed_id, nb) { if (feed_priority > 0) { elem = $('#aside_flux .all').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } @@ -68,7 +68,7 @@ function incUnreadsFeed(article, feed_id, nb) { if (article && article.closest('div').hasClass('favorite')) { elem = $('#aside_flux .favorites').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); } } @@ -157,7 +157,7 @@ function mark_favorite(active) { if (active.closest('div').hasClass('not_read')) { var elem = $('#aside_flux .favorites').children(':first').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if (elem) { elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + inc))); } @@ -544,7 +544,7 @@ function refreshUnreads() { $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? (nbUnreads - feed_unreads > 0)) { $('#new-article').show(); @@ -649,9 +649,9 @@ function init_loginForm() { c = dcodeIO.bcrypt.hashSync(data.nonce + s, strong ? 4 : poormanSalt()); $('#challenge').val(c); if (s == '' || c == '') { - alert('Crypto error!'); + alert('Crypto error!'); } else { - success = true; + success = true; } } catch (e) { alert('Crypto exception! ' + e); @@ -755,34 +755,6 @@ function init_print_action() { }); } -function init_number_formats() { - // Init global counter - var elem = $('#aside_flux .categories li .all a'); - elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); - - // Init favorites counters - elem = $('#aside_flux .categories li .favorites a'); - elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); - - var numFavorites = elem.text().replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { - return numberFormat(p1) - }); - elem.text(numFavorites); - - // Init feeds counters - $('#aside_flux .categories li .stick').each(function() { - // Category-level counter - elem = $(this).find('a'); - elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); - - // Feeds counters - $(this).parent().find('ul.feeds li.item').each(function() { - elem = $(this).find('a.feed'); // There are two links here. a.feed is the title. - elem.attr('data-unread', numberFormat(elem.attr('data-unread'))); - }); - }); -} - function init_all() { if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) { if (window.console) { @@ -813,7 +785,7 @@ function init_all() { init_print_action(); window.setInterval(refreshUnreads, 120000); } - init_number_formats(); + if (window.console) { console.log('FreshRSS init done.'); } -- cgit v1.2.3 From 2fe2f876eac5e5fb8730000ef3d32ab45eefa8ea Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Mon, 27 Jan 2014 23:27:42 +0100 Subject: Corrige mise à jour titre en JavaScript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le nombre de non lus n'était pas mis à jour correctement. Voir #398 (comments) --- p/scripts/main.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'p/scripts/main.js') diff --git a/p/scripts/main.js b/p/scripts/main.js index 4ee861ade..921005e3c 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -75,15 +75,21 @@ function incUnreadsFeed(article, feed_id, nb) { var isCurrentView = false; //Update unread: title - document.title = document.title.replace(/((?: \(\d+\))?)( · .*?)((?: \(\d+\))?)$/, function (m, p1, p2, p3) { + document.title = document.title.replace(/^([^\(]*)((?: \([0-9 ]+\))?)( · .*?)((?: \([0-9 ]+\))?)$/, function(m, p1, p2, p3, p4) { var $feed = $('#' + feed_id); - if (article || ($feed.closest('.active').length > 0 && $feed.siblings('.active').length === 0)) { + + p2 = p2.replace(/ /g, ''); + p4 = p4.replace(/ /g, ''); + + if ($('.category.all > .active').length == 0 && $('.category.favorites > .active').length == 0) { // If the current page is not the home page or the favorites page isCurrentView = true; - return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); + return p1 + incLabel(p2, nb) + p3 + incLabel(p4, feed_priority > 0 ? nb : 0); } else { - return p1 + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); + return p1 + p3 + incLabel(p4, feed_priority > 0 ? nb : 0); } + }); + return isCurrentView; } -- cgit v1.2.3 From a6f122e03cebd9b2ceed029344ddd2e72af460e3 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 28 Jan 2014 00:18:30 +0100 Subject: Formatage des nombres #2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/marienfressinaud/FreshRSS/pull/398 Je suis reparti du commit 7a510af73a0ef04ce09fb7eedd98c844e7bff51c, ai ajouté la gestion des espaces à une fonction de conversion des entiers, corrigé ce qui devait être fait côté PHP, et remis manuellement les patchs intermédiaires (j'espère ne pas avoir oublié de corrections). Le code est même plus simple qu'avant. Testé aussi sur titre et favoris --- app/Controllers/indexController.php | 5 ++-- p/scripts/main.js | 56 ++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 30 deletions(-) (limited to 'p/scripts/main.js') diff --git a/app/Controllers/indexController.php b/app/Controllers/indexController.php index 7d6d73c28..986a322a1 100755 --- a/app/Controllers/indexController.php +++ b/app/Controllers/indexController.php @@ -44,6 +44,7 @@ class FreshRSS_index_Controller extends Minz_ActionController { $this->view->cat_aside = $catDAO->listCategories (); $this->view->nb_favorites = $entryDAO->countUnreadReadFavorites (); + $this->view->nb_not_read = FreshRSS_CategoryDAO::CountUnreads($this->view->cat_aside, 1); $this->view->currentName = ''; $this->view->get_c = ''; @@ -61,8 +62,6 @@ class FreshRSS_index_Controller extends Minz_ActionController { return; } - $this->view->nb_not_read = FreshRSS_CategoryDAO::CountUnreads($this->view->cat_aside, 1); - // mise à jour des titres $this->view->rss_title = $this->view->currentName . ' | ' . Minz_View::title(); if ($this->view->nb_not_read > 0) { @@ -153,10 +152,12 @@ class FreshRSS_index_Controller extends Minz_ActionController { switch ($getType) { case 'a': $this->view->currentName = Minz_Translate::t ('your_rss_feeds'); + $this->nb_not_read_cat = $this->view->nb_not_read; $this->view->get_c = $getType; return true; case 's': $this->view->currentName = Minz_Translate::t ('your_favorites'); + $this->nb_not_read_cat = $this->view->nb_favorites['unread']; $this->view->get_c = $getType; return true; case 'c': diff --git a/p/scripts/main.js b/p/scripts/main.js index 921005e3c..f0d2bbf7b 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -20,7 +20,17 @@ function redirect(url, new_tab) { } } +function str2int(str) { + if (str == '') { + return 0; + } + return parseInt(str.replace(/\D/g, ''), 10) || 0; +} + function numberFormat(nStr) { + if (nStr < 0) { + return 0; + } // http://www.mredkj.com/javascript/numberFormat.html nStr += ''; var x = nStr.split('.'), @@ -34,33 +44,32 @@ function numberFormat(nStr) { } function incLabel(p, inc) { - var i = (parseInt(p.replace(/\D/g, ''), 10) || 0) + inc; + var i = str2int(p) + inc; return i > 0 ? ' (' + numberFormat(i) + ')' : ''; } function incUnreadsFeed(article, feed_id, nb) { - //Update unread: feed var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0, - feed_priority = elem ? (parseInt(elem.getAttribute('data-priority'), 10) || 0) : 0; + feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0, + feed_priority = elem ? str2int(elem.getAttribute('data-priority')) : 0; if (elem) { - elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); + elem.setAttribute('data-unread', numberFormat(feed_unreads + nb)); } //Update unread: category elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0); - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; if (elem) { - elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); + elem.setAttribute('data-unread', numberFormat(feed_unreads + nb)); } //Update unread: all if (feed_priority > 0) { elem = $('#aside_flux .all').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; - elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); + feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; + elem.setAttribute('data-unread', numberFormat(feed_unreads + nb)); } } @@ -68,28 +77,22 @@ function incUnreadsFeed(article, feed_id, nb) { if (article && article.closest('div').hasClass('favorite')) { elem = $('#aside_flux .favorites').children(':first').get(0); if (elem) { - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; - elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + nb))); + feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; + elem.setAttribute('data-unread', numberFormat(feed_unreads + nb)); } } var isCurrentView = false; //Update unread: title - document.title = document.title.replace(/^([^\(]*)((?: \([0-9 ]+\))?)( · .*?)((?: \([0-9 ]+\))?)$/, function(m, p1, p2, p3, p4) { + document.title = document.title.replace(/((?: \([ 0-9]+\))?)( · .*?)((?: \([ 0-9]+\))?)$/, function (m, p1, p2, p3) { var $feed = $('#' + feed_id); - - p2 = p2.replace(/ /g, ''); - p4 = p4.replace(/ /g, ''); - - if ($('.category.all > .active').length == 0 && $('.category.favorites > .active').length == 0) { // If the current page is not the home page or the favorites page + if (article || ($feed.closest('.active').length > 0 && $feed.siblings('.active').length === 0)) { isCurrentView = true; - return p1 + incLabel(p2, nb) + p3 + incLabel(p4, feed_priority > 0 ? nb : 0); + return incLabel(p1, nb) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); } else { - return p1 + p3 + incLabel(p4, feed_priority > 0 ? nb : 0); + return p1 + p2 + incLabel(p3, feed_priority > 0 ? nb : 0); } - }); - return isCurrentView; } @@ -153,19 +156,16 @@ function mark_favorite(active) { var favourites = $('.favorites>a').contents().last().get(0); if (favourites && favourites.textContent) { - // Without javascript, the text displayed is « Favorites (1544) » where 1544 is the number unformatted. - // With Javascript, we replace this with « Favorites (1 544) ». To update this, the text is converted - // to the non-javascript format before. - favourites.textContent = favourites.textContent.replace(/ /g, '').replace('(', ' (').replace(/((?: \(\d+\))?\s*)$/, function (m, p1) { + favourites.textContent = favourites.textContent.replace(/((?: \([ 0-9]+\))?\s*)$/, function (m, p1) { return incLabel(p1, inc); }); } if (active.closest('div').hasClass('not_read')) { var elem = $('#aside_flux .favorites').children(':first').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; if (elem) { - elem.setAttribute('data-unread', numberFormat(Math.max(0, feed_unreads + inc))); + elem.setAttribute('data-unread', numberFormat(feed_unreads + inc)); } } }); @@ -550,7 +550,7 @@ function refreshUnreads() { $.each(data, function(feed_id, nbUnreads) { feed_id = 'f_' + feed_id; var elem = $('#' + feed_id + '>.feed').get(0), - feed_unreads = elem ? (parseInt(elem.getAttribute('data-unread').replace(' ', ''), 10) || 0) : 0; + feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0; if ((incUnreadsFeed(null, feed_id, nbUnreads - feed_unreads) || isAll) && //Update of current view? (nbUnreads - feed_unreads > 0)) { $('#new-article').show(); -- cgit v1.2.3