diff options
| author | 2013-11-04 14:15:59 -0800 | |
|---|---|---|
| committer | 2013-11-04 14:15:59 -0800 | |
| commit | aff58561e94396f2078c4f724cc50ab8acf26898 (patch) | |
| tree | 6aad9fbd05ed6b3cbd690ae7b71e2d3785193f54 /public | |
| parent | cabacaff97f45ab858cc68fe00b0dd2585b6af02 (diff) | |
| parent | e7dd4829799e9e14456e1b1fc3aca20412394798 (diff) | |
Merge pull request #214 from Alkarex/updateUnreads
Mise à jour automatique des nombres d'articles non lus et favoris
Diffstat (limited to 'public')
| -rw-r--r-- | public/scripts/main.js | 53 | ||||
| -rw-r--r-- | public/themes/default/freshrss.css | 39 | ||||
| -rw-r--r-- | public/themes/flat-design/freshrss.css | 35 |
3 files changed, 89 insertions, 38 deletions
diff --git a/public/scripts/main.js b/public/scripts/main.js index 72795be51..ea4f3bec6 100644 --- a/public/scripts/main.js +++ b/public/scripts/main.js @@ -71,6 +71,11 @@ function toggleContent (new_active, old_active) { } } +function _incLabel(p, inc) { + var i = (parseInt(p.replace(/\D/g, '')) || 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"))) { @@ -91,11 +96,41 @@ function mark_read (active, only_not_read) { active.find ("a.read").attr ("href", res.url); + var 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++; + } + + //Update unread: feed //Alex + var feed_url = active.find(".website>a").attr("href"), + feed_id = feed_url.substr(feed_url.lastIndexOf('f_')), + elem = $('#' + feed_id + ' .feed').get(0), + attr_unread = elem ? elem.getAttributeNode('data-unread') : null, + feed_priority = elem ? parseInt(elem.getAttribute('data-priority')) : 0; + if (attr_unread) + attr_unread.value = Math.max(0, parseInt(attr_unread.value) + inc); + + //Update unread: category + elem = $('#' + feed_id).parent().prevAll('.category').children(':first').get(0); + attr_unread = elem ? elem.getAttributeNode('data-unread') : null; + if (attr_unread) + attr_unread.value = Math.max(0, parseInt(attr_unread.value) + inc); + + if (feed_priority > 0) { //Update unread: all + elem = $('#aside_flux .all').children(':first').get(0); + attr_unread = elem ? elem.getAttributeNode('data-unread') : null; + if (attr_unread) + attr_unread.value = Math.max(0, parseInt(attr_unread.value) + 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); + }); }); } @@ -117,11 +152,20 @@ function mark_favorite (active) { res = jQuery.parseJSON(data); active.find ("a.bookmark").attr ("href", res.url); + var inc = 0; if (active.hasClass ("favorite")) { active.removeClass ("favorite"); + inc--; } else { active.addClass ("favorite"); + inc++; } + + 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); + }); }); } @@ -235,9 +279,10 @@ function init_column_categories () { return; } - $(".category").addClass ("stick"); - $(".categories .category .btn:first-child").width ("160px"); - $(".category").append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>"); + //TODO: toggle class in PHP and remove the CSS changes done in JavaScript + $(".category:not(.all):not(.favorites) .btn:first-child").width ("160px"); + $(".category:not(.all):not(.favorites)").addClass("stick"). + append ("<a class=\"btn dropdown-toggle\" href=\"#\"><i class=\"icon i_down\"></i></a>"); $(".category + .feeds").not(".active").hide(); $(".category.active a.dropdown-toggle i").toggleClass ("i_up"); @@ -391,7 +436,7 @@ function init_nav_entries() { function init_templates() { $('#aside_flux').on('click', '.dropdown-toggle', function () { if ($(this).nextAll('.dropdown-menu').length === 0) { - var feed_id = $(this).data('fid'), + 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); diff --git a/public/themes/default/freshrss.css b/public/themes/default/freshrss.css index bf4b0ab09..144c77c92 100644 --- a/public/themes/default/freshrss.css +++ b/public/themes/default/freshrss.css @@ -93,9 +93,7 @@ text-align: center; list-style: none; } - .categories .all, - .categories .favorites, - .categories .category { + .category { display: block; padding: 5px 0; width: 220px; @@ -105,12 +103,23 @@ white-space: nowrap; text-overflow: ellipsis; } - .categories .all .btn, - .categories .favorites .btn, - .categories .category .btn:first-child { + .category .btn:first-child { width: 195px; position: relative; } + .category .btn:first-child:not([data-unread="0"]):after { + content: attr(data-unread); + position: absolute; + top: 3px; right: 3px; + padding: 1px 5px; + background: #ccc; + color: #fff; + font-size: 90%; + border: 1px solid #bbb; + border-radius: 5px; + box-shadow: 1px 3px 3px #aaa inset; + text-shadow: 0 0 1px #aaa; + } .categories .feeds { width: 100%; margin: 0; @@ -146,6 +155,12 @@ white-space: nowrap; text-overflow: ellipsis; } + .feed:not([data-unread="0"]) { + font-weight:bold; + } + .feed:not([data-unread="0"]):before { + content: "(" attr(data-unread) ") "; + } .categories .feeds .dropdown .dropdown-menu { left: 0; } @@ -163,18 +178,6 @@ background-color: #fff; border-radius: 3px; } - .categories .notRead { - position: absolute; - top: 3px; right: 3px; - padding: 1px 5px; - background: #ccc; - color: #fff; - font-size: 90%; - border: 1px solid #bbb; - border-radius: 5px; - box-shadow: 1px 3px 3px #aaa inset; - text-shadow: 0 0 1px #aaa; - } .post { padding: 10px 50px; diff --git a/public/themes/flat-design/freshrss.css b/public/themes/flat-design/freshrss.css index ede188ccb..60c454bbe 100644 --- a/public/themes/flat-design/freshrss.css +++ b/public/themes/flat-design/freshrss.css @@ -92,9 +92,7 @@ body { text-align: center; list-style: none; } - .categories .all, - .categories .favorites, - .categories .category { + .category { display: block; padding: 5px 0; width: 220px; @@ -104,12 +102,21 @@ body { white-space: nowrap; text-overflow: ellipsis; } - .categories .all .btn, - .categories .favorites .btn, - .categories .category .btn:first-child { + .category .btn:first-child { width: 195px; position: relative; } + .category .btn:first-child:not([data-unread="0"]):after { + content: attr(data-unread); + position: absolute; + top: 5px; right: 0px; + padding: 0 5px; + color: #fff; + font-size: 90%; + background: #3498DB; + border-left: 3px solid #2980B9; + border-radius: 5px 0 0 5px; + } .categories .feeds { width: 220px; margin: 0 auto; @@ -138,6 +145,12 @@ body { white-space: nowrap; text-overflow: ellipsis; } + .feed:not([data-unread="0"]) { + font-weight:bold; + } + .feed:not([data-unread="0"]):before { + content: "(" attr(data-unread) ") "; + } .categories .feeds .dropdown .dropdown-menu { left: 0; } @@ -155,16 +168,6 @@ body { background-color: #95a5a6; border-radius: 3px; } - .categories .notRead { - position: absolute; - top: 5px; right: 0px; - padding: 0 5px; - color: #fff; - font-size: 90%; - background: #3498DB; - border-left: 3px solid #2980B9; - border-radius: 5px 0 0 5px; - } .categories .btn:hover .notRead, .categories .btn.active .notRead { background: #2980B9; |
