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