-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
258 lines (208 loc) · 7.46 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<!doctype html>
<html lang="en" ng-app="app">
<head>
<meta charset="utf-8">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<title>NoobsPlayGround</title>
<link rel="stylesheet" href="lib/onsen/css/onsenui.css">
<link rel="stylesheet" href="styles/onsen-css-components.css">
<link rel="stylesheet" href="styles/app.css"/>
<script src="lib/onsen/js/angular/angular.js"></script>
<script src="lib/onsen/js/onsenui.js"></script>
<script src="cordova.js"></script>
</head>
<body ng-controller="mainController">
<ons-navigator title="Navigator" var="myNavigator">
<script>
var isOnMobile = false;
var uniqueId = "0";
var pushNotification;
var serverUri = "";
function successHandler (result) {
//alert('result = ' + result);
}
function errorHandler (error) {
// alert('error = ' + error);
}
function onNotificationAPN (event) {
if ( event.alert )
{
navigator.notification.alert(event.alert, function(){}, "NPG", "Ok");
}
if ( event.sound )
{
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge )
{
pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
}
// Android and Amazon Fire OS
function onNotification(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
var toAdd = { DeviceId: e.regid, DeviceType: "Android" };
$.ajax({
url: serverUri + "api/pushdata",
type: 'POST',
contentType:"application/json",
data: JSON.stringify(toAdd),
success: function (data) {
},
error: function (result) {
}
});
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if ( e.foreground )
{
navigator.notification.beep(1);
navigator.notification.alert(e.payload.message, function(){}, e.payload.title, "OK");
$("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
}
else
{
$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
navigator.notification.beep(1);
navigator.notification.alert(e.payload.message, function(){}, e.payload.title, "OK");
}
$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
//Only works for GCM
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');
//Only works on Amazon Fire OS
$status.append('<li>MESSAGE -> TIME: ' + e.payload.timeStamp + '</li>');
break;
case 'error':
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
break;
default:
$("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
break;
}
}
function tokenHandler (result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
var toAdd = { DeviceId: result, DeviceType: "IOS" };
$.ajax({
url: serverUri + "api/pushdata",
type: 'POST',
contentType:"application/json",
data: JSON.stringify(toAdd),
success: function (data) {
},
error: function (errordata) {
}
});
}
function jsonErrorHandler(error) {
}
//handle MPNS notifications for WP8
function onNotificationWP8(e) {
if (e.type == "toast" && e.jsonContent) {
pushNotification.showToastNotification(successHandler, errorHandler,
{
"Title": e.jsonContent["wp:Text1"], "Subtitle": e.jsonContent["wp:Text2"], "NavigationUri": e.jsonContent["wp:Param"]
});
}
if (e.type == "raw" && e.jsonContent) {
navigator.notification.alert(e.jsonContent.Body, function(){}, "NPG", "OK");
navigator.notification.beep(1);
}
}
function registerPush(){
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
pushNotification.register(
successHandler,
errorHandler,
{
"senderID":"1017425189949",
"ecb":"onNotification"
});
} else if ( device.platform == 'Win32NT'){
pushNotification.register(
channelHandler,
errorHandler,
{
"channelName": "",
"ecb": "onNotificationWP8",
"uccb": "channelHandler",
"errcb": "jsonErrorHandler"
});
} else {
pushNotification.register(
tokenHandler,
errorHandler,
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"onNotificationAPN"
});
}
}
function unregister() {
var channelName = "";
pushNotification.unregister(
successHandler, errorHandler,
{
"channelName": channelName
});
}
document.addEventListener("deviceready", function(){
var countBack = 0;
document.addEventListener("backbutton", function(e){
e.preventDefault();
if( countBack == 1){
navigator.Backbutton.goHome(function() {
}, function() {
});
}
else {
countBack = 1;
window.plugins.toast.showShortCenter('Klik de terug knop nog eens om de app te sluiten of navigeer met het slidemenu!', function(a){console.log('toast success: ' + a);}, function(b){alert('toast error: ' + b);});
setTimeout(function(){countBack = 0;}, 2000);
}
}, false);
var isOnMobile = true;
setTimeout(function() {
navigator.splashscreen.hide();
}, 2000);
uniqueId = device.uuid
pushNotification = window.plugins.pushNotification;
registerPush();
},true);
/*
function disableOnsenBack(){
}
*/
</script>
<ons-sliding-menu
menu-page="views/menu.html" main-page="views/home.html" side="right"
var="menu" type="reveal" max-slide-distance="260px" swipable="false">
</ons-sliding-menu>
</ons-navigator>
<script src="scripts/app.js"></script>
<script src="scripts/mainController.js"></script>
</body>
</html>