diff options
| author | 2014-08-08 22:17:06 +0200 | |
|---|---|---|
| committer | 2014-08-08 22:17:06 +0200 | |
| commit | ad1ad913f3cadc62c175f11e56d1cc44220b605e (patch) | |
| tree | 863d496c34dfaaf9514d913b2dd102677645db10 | |
| parent | a7632b54293100d71a6eadfcb98746da05358ddb (diff) | |
| parent | d289c5340f3b21f1561e57390e89b0b5c7881d17 (diff) | |
Merge branch 'notification' into dev
| -rw-r--r-- | app/i18n/en.php | 2 | ||||
| -rw-r--r-- | app/i18n/fr.php | 2 | ||||
| -rw-r--r-- | app/views/helpers/javascript_vars.phtml | 2 | ||||
| -rw-r--r-- | p/scripts/main.js | 48 |
4 files changed, 53 insertions, 1 deletions
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() { } // </notification> +// <notifs html5> +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(); +} +// </notifs html5> + 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(); |
