index.html 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <html data-ng-app>
  2. <head>
  3. <title></title>
  4. <link href="notifications.css" type="text/css" rel="stylesheet"/>
  5. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.min.js"></script>
  6. <script type="text/javascript" src="desktop-notify-min.js"></script>
  7. <script>
  8. function NotificationCenter($scope) {
  9. var permissionLevels = {};
  10. permissionLevels[notify.PERMISSION_GRANTED] = 0;
  11. permissionLevels[notify.PERMISSION_DEFAULT] = 1;
  12. permissionLevels[notify.PERMISSION_DENIED] = 2;
  13. $scope.isSupported = notify.isSupported;
  14. $scope.permissionLevel = permissionLevels[notify.permissionLevel()];
  15. $scope.getClassName = function() {
  16. if ($scope.permissionLevel === 0) {
  17. return "allowed"
  18. } else if ($scope.permissionLevel === 1) {
  19. return "default"
  20. } else {
  21. return "denied"
  22. }
  23. }
  24. $scope.callback = function() {
  25. console.log("test");
  26. }
  27. $scope.requestPermissions = function() {
  28. notify.requestPermission(function() {
  29. $scope.$apply($scope.permissionLevel = permissionLevels[notify.permissionLevel()]);
  30. })
  31. }
  32. }
  33. function show() {
  34. notify.createNotification("Notification", {body:"Body", icon: "alert.ico"})
  35. }
  36. </script>
  37. </head>
  38. <body data-ng-controller="NotificationCenter">
  39. <div class="warningMsg" data-ng-show="!isSupported" style="display: none;">
  40. Desktop notifications are currently not supported for your browser.
  41. <p>
  42. Open the page in Chrome(version 23+), Safari(version6+), Firefox(with ff-html5notifications plugin installed) and IE9+.
  43. </div>
  44. <a class="notificationLevel" ng-class="getClassName()" data-ng-click="requestPermissions()" data-ng-pluralize data-count="permissionLevel" when="{
  45. '0': 'Notifications allowed.',
  46. '1': 'Notifications not allowed. (click to enable)',
  47. '2': 'Notifications denied. (Change notifications permission in you browser\'s settings)'}">
  48. </a>
  49. <button onclick="show()">Show notification</button>
  50. </body>
  51. </html>