modernizr
Version:
Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.
47 lines (44 loc) • 1.31 kB
JavaScript
/*!
{
"name": "Notification",
"property": "notification",
"caniuse": "notifications",
"authors": ["Theodoor van Donge", "Hendrik Beskow"],
"notes": [{
"name": "HTML5 Rocks tutorial",
"href": "http://www.html5rocks.com/en/tutorials/notifications/quick/"
},{
"name": "W3C spec",
"href": "https://www.w3.org/TR/notifications/"
}, {
"name": "Changes in Chrome to Notifications API due to Service Worker Push Notifications",
"href": "https://developers.google.com/web/updates/2015/05/Notifying-you-of-notificiation-changes"
}],
"knownBugs": [
"Possibility of false-positive on Chrome for Android if permissions we're granted for a website prior to Chrome 44."
],
"polyfills": ["desktop-notify", "html5-notifications"]
}
!*/
/* DOC
Detects support for the Notifications API
*/
define(['Modernizr'], function(Modernizr) {
Modernizr.addTest('notification', function() {
if (!window.Notification || !window.Notification.requestPermission) {
return false;
}
// if permission is already granted, assume support
if (window.Notification.permission === 'granted') {
return true;
}
try {
new window.Notification('');
} catch (e) {
if (e.name === 'TypeError') {
return false;
}
}
return true;
});
});