aboutsummaryrefslogtreecommitdiff
path: root/p/scripts
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-08-24 15:29:09 +0200
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2014-08-24 15:29:09 +0200
commit07444280d1a03daa7880c1539bde3a6e80945dab (patch)
treec328a11f59e07d12e624576ed86b11ada1b9d198 /p/scripts
parent1d2527b8bc2a125cc8b8508402417f60d314e330 (diff)
parentd1f79fee69a3667913f419cd9726ffb11f410bd0 (diff)
Merge branch 'dev' into beta
Conflicts: README.md
Diffstat (limited to 'p/scripts')
-rw-r--r--p/scripts/jquery.lazyload.min.js15
-rw-r--r--p/scripts/main.js146
2 files changed, 122 insertions, 39 deletions
diff --git a/p/scripts/jquery.lazyload.min.js b/p/scripts/jquery.lazyload.min.js
deleted file mode 100644
index 8dd097dc3..000000000
--- a/p/scripts/jquery.lazyload.min.js
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Lazy Load - jQuery plugin for lazy loading images
- *
- * Copyright (c) 2007-2013 Mika Tuupola
- *
- * Licensed under the MIT license:
- * http://www.opensource.org/licenses/mit-license.php
- *
- * Project home:
- * http://www.appelsiini.net/projects/lazyload
- *
- * Version: 1.9.0
- *
- */
-!function(a,b,c,d){var e=a(b);a.fn.lazyload=function(f){function g(){var b=0;i.each(function(){var c=a(this);if(!j.skip_invisible||c.is(":visible"))if(a.abovethetop(this,j)||a.leftofbegin(this,j));else if(a.belowthefold(this,j)||a.rightoffold(this,j)){if(++b>j.failure_limit)return!1}else c.trigger("appear"),b=0})}var h,i=this,j={threshold:0,failure_limit:0,event:"scroll",effect:"show",container:b,data_attribute:"original",skip_invisible:!0,appear:null,load:null,placeholder:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC"};return f&&(d!==f.failurelimit&&(f.failure_limit=f.failurelimit,delete f.failurelimit),d!==f.effectspeed&&(f.effect_speed=f.effectspeed,delete f.effectspeed),a.extend(j,f)),h=j.container===d||j.container===b?e:a(j.container),0===j.event.indexOf("scroll")&&h.bind(j.event,function(){return g()}),this.each(function(){var b=this,c=a(b);b.loaded=!1,(c.attr("src")===d||c.attr("src")===!1)&&c.attr("src",j.placeholder),c.one("appear",function(){if(!this.loaded){if(j.appear){var d=i.length;j.appear.call(b,d,j)}a("<img />").bind("load",function(){var d=c.data(j.data_attribute);c.hide(),c.is("img")?c.attr("src",d):c.css("background-image","url('"+d+"')"),c[j.effect](j.effect_speed),b.loaded=!0;var e=a.grep(i,function(a){return!a.loaded});if(i=a(e),j.load){var f=i.length;j.load.call(b,f,j)}}).attr("src",c.data(j.data_attribute))}}),0!==j.event.indexOf("scroll")&&c.bind(j.event,function(){b.loaded||c.trigger("appear")})}),e.bind("resize",function(){g()}),/iphone|ipod|ipad.*os 5/gi.test(navigator.appVersion)&&e.bind("pageshow",function(b){b.originalEvent&&b.originalEvent.persisted&&i.each(function(){a(this).trigger("appear")})}),a(c).ready(function(){g()}),this},a.belowthefold=function(c,f){var g;return g=f.container===d||f.container===b?(b.innerHeight?b.innerHeight:e.height())+e.scrollTop():a(f.container).offset().top+a(f.container).height(),g<=a(c).offset().top-f.threshold},a.rightoffold=function(c,f){var g;return g=f.container===d||f.container===b?e.width()+e.scrollLeft():a(f.container).offset().left+a(f.container).width(),g<=a(c).offset().left-f.threshold},a.abovethetop=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollTop():a(f.container).offset().top,g>=a(c).offset().top+f.threshold+a(c).height()},a.leftofbegin=function(c,f){var g;return g=f.container===d||f.container===b?e.scrollLeft():a(f.container).offset().left,g>=a(c).offset().left+f.threshold+a(c).width()},a.inviewport=function(b,c){return!(a.rightoffold(b,c)||a.leftofbegin(b,c)||a.belowthefold(b,c)||a.abovethetop(b,c))},a.extend(a.expr[":"],{"below-the-fold":function(b){return a.belowthefold(b,{threshold:0})},"above-the-top":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-screen":function(b){return a.rightoffold(b,{threshold:0})},"left-of-screen":function(b){return!a.rightoffold(b,{threshold:0})},"in-viewport":function(b){return a.inviewport(b,{threshold:0})},"above-the-fold":function(b){return!a.belowthefold(b,{threshold:0})},"right-of-fold":function(b){return a.rightoffold(b,{threshold:0})},"left-of-fold":function(b){return!a.rightoffold(b,{threshold:0})}})}(jQuery,window,document); \ No newline at end of file
diff --git a/p/scripts/main.js b/p/scripts/main.js
index d0f3c27e9..c37f9f6f2 100644
--- a/p/scripts/main.js
+++ b/p/scripts/main.js
@@ -69,6 +69,10 @@ function incUnreadsFeed(article, feed_id, nb) {
feed_priority = elem ? str2int(elem.getAttribute('data-priority')) : 0;
if (elem) {
elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
+ elem = $(elem).closest('li').get(0);
+ if (elem) {
+ elem.setAttribute('data-unread', feed_unreads + nb);
+ }
}
//Update unread: category
@@ -76,6 +80,10 @@ function incUnreadsFeed(article, feed_id, nb) {
feed_unreads = elem ? str2int(elem.getAttribute('data-unread')) : 0;
if (elem) {
elem.setAttribute('data-unread', numberFormat(feed_unreads + nb));
+ elem = $(elem).closest('li').get(0);
+ if (elem) {
+ elem.setAttribute('data-unread', feed_unreads + nb);
+ }
}
//Update unread: all
@@ -98,16 +106,16 @@ function incUnreadsFeed(article, feed_id, nb) {
var isCurrentView = false;
//Update unread: title
- document.title = document.title.replace(/^((?:\([ 0-9]+\) )?)(.*? · )((?:\([ 0-9]+\) )?)/, function (m, p1, p2, p3) {
+ document.title = document.title.replace(/^((?:\([ 0-9]+\) )?)/, function (m, p1) {
var $feed = $('#' + feed_id);
if (article || ($feed.closest('.active').length > 0 && $feed.siblings('.active').length === 0)) {
isCurrentView = true;
- return incLabel(p1, nb, true) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0, true);
+ return incLabel(p1, nb, true);
} else if ($('.all.active').length > 0) {
isCurrentView = feed_priority > 0;
- return incLabel(p1, feed_priority > 0 ? nb : 0, true) + p2 + incLabel(p3, feed_priority > 0 ? nb : 0, true);
+ return incLabel(p1, feed_priority > 0 ? nb : 0, true);
} else {
- return p1 + p2 + incLabel(p3, feed_priority > 0 ? nb : 0, true);
+ return p1;
}
});
return isCurrentView;
@@ -152,6 +160,7 @@ function mark_read(active, only_not_read) {
$r.find('.icon').replaceWith(data.icon);
incUnreadsFeed(active, feed_id, inc);
+ faviconNbUnread();
pending_feeds.splice(index_pending, 1);
});
@@ -361,7 +370,12 @@ function last_category() {
function collapse_entry() {
isCollapsed = !isCollapsed;
- $(".flux.current").toggleClass("active");
+
+ var flux_current = $(".flux.current");
+ flux_current.toggleClass("active");
+ if (isCollapsed) {
+ mark_read(flux_current, true);
+ }
}
function auto_share(key) {
@@ -407,21 +421,7 @@ function inMarkViewport(flux, box_to_follow, relative_follow) {
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()) {
@@ -663,7 +663,7 @@ function init_stream(divStream) {
if (auto_mark_site) {
divStream.on('click', '.flux .link > a', function () {
- mark_read($(this).parent().parent().parent(), true);
+ mark_read($(this).parents(".flux"), true);
});
}
}
@@ -768,18 +768,66 @@ function init_notifications() {
}
// </notification>
+// <notifs html5>
+var notifs_html5_permission = 'denied';
+
+function notifs_html5_is_supported() {
+ return window.Notification !== undefined;
+}
+
+function notifs_html5_ask_permission() {
+ window.Notification.requestPermission(function () {
+ notifs_html5_permission = window.Notification.permission;
+ });
+}
+
+function notifs_html5_show(nb) {
+ if (notifs_html5_permission !== "granted") {
+ return
+ }
+
+ var notification = new window.Notification(str_notif_title_articles, {
+ icon: "../themes/icons/favicon-256.png",
+ body: str_notif_body_articles.replace("\d", nb)
+ });
+
+ notification.onclick = function() {
+ window.location.reload();
+ }
+}
+
+function init_notifs_html5() {
+ if (!notifs_html5_is_supported()) {
+ return;
+ }
+
+ notifs_html5_permission = notifs_html5_ask_permission();
+}
+// </notifs html5>
+
function refreshUnreads() {
$.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) {
- var isAll = $('.category.all > .active').length > 0;
+ var isAll = $('.category.all > .active').length > 0,
+ new_articles = false;
+
$.each(data, function(feed_id, nbUnreads) {
feed_id = 'f_' + feed_id;
var elem = $('#' + feed_id + '>.feed').get(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();
+ new_articles = true;
};
});
+
+ var nb_unreads = str2int($('.category.all>a').attr('data-unread'));
+
+ if (nb_unreads > 0 && new_articles) {
+ faviconNbUnread(nb_unreads);
+ notifs_html5_show(nb_unreads);
+ }
});
}
@@ -812,7 +860,6 @@ function load_more_posts() {
});
init_load_more(box_load_more);
- init_lazyload();
$('#load_more').removeClass('loading');
load_more = false;
@@ -826,6 +873,12 @@ function focus_search() {
function init_load_more(box) {
box_load_more = box;
+ if (!does_lazyload) {
+ $('img[postpone], audio[postpone], iframe[postpone], video[postpone]').each(function () {
+ this.removeAttribute('postpone');
+ });
+ }
+
var $next_link = $("#load_more");
if (!$next_link.length) {
// no more article to load
@@ -967,7 +1020,7 @@ function init_persona() {
//</persona>
function init_confirm_action() {
- $('.confirm').click(function () {
+ $('body').on('click', '.confirm', function () {
return confirm(str_confirmation);
});
}
@@ -1010,6 +1063,12 @@ function init_share_observers() {
});
}
+function init_stats_observers() {
+ $('#feed_select').on('change', function(e) {
+ redirect($(this).find(':selected').data('url'));
+ });
+}
+
function init_remove_observers() {
$('.post').on('click', 'a.remove', function(e) {
var remove_what = $(this).attr('data-remove');
@@ -1052,8 +1111,44 @@ function init_password_observers() {
});
}
+function faviconNbUnread(n) {
+ if (typeof n === 'undefined') {
+ n = str2int($('.category.all>a').attr('data-unread'));
+ }
+ //http://remysharp.com/2010/08/24/dynamic-favicons/
+ var canvas = document.createElement('canvas'),
+ link = document.getElementById('favicon').cloneNode(true);
+ if (canvas.getContext && link) {
+ canvas.height = canvas.width = 16;
+ var img = document.createElement('img');
+ img.onload = function () {
+ var ctx = canvas.getContext('2d');
+ ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
+ if (n > 0) {
+ var text = '';
+ if (n < 1000) {
+ text = n;
+ } else if (n < 100000) {
+ text = Math.floor(n / 1000) + 'k';
+ } else {
+ text = 'E' + Math.floor(Math.log10(n));
+ }
+ ctx.font = 'bold 9px "Arial", sans-serif';
+ ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
+ ctx.fillRect(0, 7, ctx.measureText(text).width, 9);
+ ctx.fillStyle = '#F00';
+ ctx.fillText(text, 0, canvas.height - 1);
+ }
+ link.href = canvas.toDataURL('image/png');
+ $('link[rel~=icon]').remove();
+ document.head.appendChild(link);
+ };
+ img.src = '../favicon.ico';
+ }
+}
+
function init_all() {
- if (!(window.$ && window.url_freshrss && ((!full_lazyload) || $.fn.lazyload))) {
+ if (!(window.$ && window.url_freshrss)) {
if (window.console) {
console.log('FreshRSS waiting for JS…');
}
@@ -1079,13 +1174,16 @@ function init_all() {
init_stream($stream);
init_nav_entries();
init_shortcuts();
+ faviconNbUnread();
init_print_action();
+ init_notifs_html5();
window.setInterval(refreshUnreads, 120000);
} else {
init_share_observers();
init_remove_observers();
init_feed_observers();
init_password_observers();
+ init_stats_observers();
}
if (window.console) {