From 274c8096e3ccc8ea008c1a038134ffddc302fd0d Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sat, 2 Aug 2014 19:57:15 +0200 Subject: Experimental: Removed lazyload.js and use postpone attribute instead https://github.com/marienfressinaud/FreshRSS/issues/316 The performance of lazyload.js was not good enough, and not really needed anyway. This change mostly affects mainly situations when the content of articles is shown by default, not so much when they are collapsed Using HTML5 lazyload and postpone attributes by default on all img, audio, iframe, video. http://www.w3.org/TR/resource-priorities/#attr-postpone Postpone attribute is removed by JavaScript if the user does not want the lazyload behaviour. In the case when users do want the lazyload behaviour, in normal view with articles hidden, we furthermore use the data-original approach to be sure to support current browsers. +Corrected some bugs with enclosures, and some images not appearing before the first scroll. +Now faster regex processing img and iframe at once (was not practical with lazyload.js) --- app/views/helpers/javascript_vars.phtml | 1 - 1 file changed, 1 deletion(-) (limited to 'app/views/helpers/javascript_vars.phtml') diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index 6e0a20de3..a04d3d527 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -10,7 +10,6 @@ echo 'var ', ',auto_mark_site=', $mark['site'] ? 'true' : 'false', ',auto_mark_scroll=', $mark['scroll'] ? 'true' : 'false', ',auto_load_more=', $this->conf->auto_load_more ? 'true' : 'false', - ',full_lazyload=', $this->conf->lazyload && ($this->conf->display_posts || Minz_Request::param('output') === 'reader') ? 'true' : 'false', ',does_lazyload=', $this->conf->lazyload ? 'true' : 'false', ',sticky_post=', $this->conf->sticky_post ? 'true' : 'false'; -- cgit v1.2.3 From d289c5340f3b21f1561e57390e89b0b5c7881d17 Mon Sep 17 00:00:00 2001 From: Marien Fressinaud Date: Fri, 8 Aug 2014 21:30:23 +0200 Subject: Add support of HTML5 notifications Show a notification if there are at least 1 new article to read. Support only window.Notification API. See https://github.com/marienfressinaud/FreshRSS/issues/399 --- app/i18n/en.php | 2 ++ app/i18n/fr.php | 2 ++ app/views/helpers/javascript_vars.phtml | 2 ++ p/scripts/main.js | 48 ++++++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 1 deletion(-) (limited to 'app/views/helpers/javascript_vars.phtml') diff --git a/app/i18n/en.php b/app/i18n/en.php index 10327c7f5..9e5bfb223 100644 --- a/app/i18n/en.php +++ b/app/i18n/en.php @@ -343,6 +343,8 @@ return array ( 'login_required' => 'Login required:', 'confirm_action' => 'Are you sure you want to perform this action? It cannot be cancelled!', + 'notif_title_new_articles' => 'FreshRSS: new articles!', + 'notif_body_new_articles' => 'There are \d new articles to read on FreshRSS.', // DATE 'january' => 'January', diff --git a/app/i18n/fr.php b/app/i18n/fr.php index 6ab3d7335..94d2e5f06 100644 --- a/app/i18n/fr.php +++ b/app/i18n/fr.php @@ -343,6 +343,8 @@ return array ( 'login_required' => 'Accès protégé par mot de passe :', 'confirm_action' => 'Êtes-vous sûr(e) de vouloir continuer ? Cette action ne peut être annulée !', + 'notif_title_new_articles' => 'FreshRSS : nouveaux articles !', + 'notif_body_new_articles' => 'Il y a \d nouveaux articles à lire sur FreshRSS.', // DATE 'january' => 'janvier', diff --git a/app/views/helpers/javascript_vars.phtml b/app/views/helpers/javascript_vars.phtml index a04d3d527..7144c519a 100644 --- a/app/views/helpers/javascript_vars.phtml +++ b/app/views/helpers/javascript_vars.phtml @@ -49,6 +49,8 @@ echo 'authType="', $authType, '",', 'url_logout="', _url ('index', 'logout'), '",'; echo 'str_confirmation="', Minz_Translate::t('confirm_action'), '"', ",\n"; +echo 'str_notif_title_articles="', Minz_Translate::t('notif_title_new_articles'), '"', ",\n"; +echo 'str_notif_body_articles="', Minz_Translate::t('notif_body_new_articles'), '"', ",\n"; $autoActualise = Minz_Session::param('actualize_feeds', false); echo 'auto_actualize_feeds=', $autoActualise ? 'true' : 'false', ";\n"; diff --git a/p/scripts/main.js b/p/scripts/main.js index a82450e7f..bd412d6e9 100644 --- a/p/scripts/main.js +++ b/p/scripts/main.js @@ -768,6 +768,46 @@ function init_notifications() { } // +// +var notifs_html5_permission = 'denied', + notifs_html5_shown = false; + +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" || notifs_html5_shown) { + 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(); + } + + notifs_html5_shown = true; +} + +function init_notifs_html5() { + if (!notifs_html5_is_supported()) { + return; + } + + notifs_html5_permission = notifs_html5_ask_permission(); +} +// + function refreshUnreads() { $.getJSON('./?c=javascript&a=nbUnreadsPerFeed').done(function (data) { var isAll = $('.category.all > .active').length > 0; @@ -780,7 +820,12 @@ function refreshUnreads() { $('#new-article').show(); }; }); - faviconNbUnread(); + + var nb_unreads = str2int($('.category.all>a').attr('data-unread')); + if (nb_unreads > 0) { + faviconNbUnread(nb_unreads); + notifs_html5_show(nb_unreads); + } }); } @@ -1123,6 +1168,7 @@ function init_all() { init_shortcuts(); faviconNbUnread(); init_print_action(); + init_notifs_html5(); window.setInterval(refreshUnreads, 120000); } else { init_share_observers(); -- cgit v1.2.3