forked from ttsvetko/HTML5-Desktop-Notifications
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
79 lines (69 loc) · 2.85 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<html data-ng-app>
<head>
<title></title>
<link href="notifications.css" type="text/css" rel="stylesheet" />
<script src="http://apps.bdimg.com/libs/angular.js/1.0.3/angular.min.js"></script>
<script type="text/javascript" src="desktop-notify.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");
}
notify.config({pageVisibility: false, autoClose: 2000});
$scope.requestPermissions = function() {
notify.requestPermission(function() {
$scope.$apply($scope.permissionLevel = permissionLevels[notify.permissionLevel()]);
})
}
}
function show() {
notify.createNotification("Notification", {
body: "Body",
icon: "alert.ico",
tag: '{"content":"text content", "id":"100"}'
}, {
show: function(msg) {
alert('show ' + msg.content);
},
click: function(msg) {
alert('click ' + msg.content);
},
close: function(msg) {
alert('close ' + msg.content);
},
error: function(msg) {
alert('error ' + msg.content);
}
})
}
</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>