notification.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*!
  2. {
  3. "name": "Notification",
  4. "property": "notification",
  5. "caniuse": "notifications",
  6. "authors": ["Theodoor van Donge", "Hendrik Beskow"],
  7. "notes": [{
  8. "name": "HTML5 Rocks Tutorial",
  9. "href": "https://www.html5rocks.com/en/tutorials/notifications/quick/"
  10. },{
  11. "name": "W3C Spec",
  12. "href": "https://www.w3.org/TR/notifications/"
  13. }, {
  14. "name": "Changes in Chrome to Notifications API due to Service Worker Push Notifications",
  15. "href": "https://developers.google.com/web/updates/2015/05/Notifying-you-of-notificiation-changes"
  16. }],
  17. "knownBugs": ["Possibility of false-positive on Chrome for Android if permissions we're granted for a website prior to Chrome 44."],
  18. "polyfills": ["desktop-notify", "html5-notifications"]
  19. }
  20. !*/
  21. /* DOC
  22. Detects support for the Notifications API
  23. */
  24. define(['Modernizr'], function(Modernizr) {
  25. Modernizr.addTest('notification', function() {
  26. if (!window.Notification || !window.Notification.requestPermission) {
  27. return false;
  28. }
  29. // if permission is already granted, assume support
  30. if (window.Notification.permission === 'granted') {
  31. return true;
  32. }
  33. try {
  34. new window.Notification('');
  35. } catch (e) {
  36. if (e.name === 'TypeError') {
  37. return false;
  38. }
  39. }
  40. return true;
  41. });
  42. });