Skip to content

Commit 81ac2e1

Browse files
author
Matthew Sun
committed
update/fix example PushNotification.js, fix odd code formatting
1 parent 894232c commit 81ac2e1

File tree

2 files changed

+70
-57
lines changed

2 files changed

+70
-57
lines changed

Example/www/PushNotification.js

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,78 @@
1-
21
var PushNotification = function() {
32
};
43

4+
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
5+
PushNotification.prototype.register = function(successCallback, errorCallback, options) {
6+
if (errorCallback == null) { errorCallback = function() {}}
7+
8+
if (typeof errorCallback != "function") {
9+
console.log("PushNotification.register failure: failure parameter not a function");
10+
return
11+
}
12+
13+
if (typeof successCallback != "function") {
14+
console.log("PushNotification.register failure: success callback parameter must be a function");
15+
return
16+
}
17+
18+
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
19+
};
520

6-
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
7-
PushNotification.prototype.register = function(successCallback, errorCallback, options) {
8-
if (errorCallback == null) { errorCallback = function() {}}
21+
// Call this to unregister for push notifications
22+
PushNotification.prototype.unregister = function(successCallback, errorCallback, options) {
23+
if (errorCallback == null) { errorCallback = function() {}}
924

10-
if (typeof errorCallback != "function") {
11-
console.log("PushNotification.register failure: failure parameter not a function");
12-
return;
13-
}
25+
if (typeof errorCallback != "function") {
26+
console.log("PushNotification.unregister failure: failure parameter not a function");
27+
return
28+
}
1429

15-
if (typeof successCallback != "function") {
16-
console.log("PushNotification.register failure: success callback parameter must be a function");
17-
return;
18-
}
30+
if (typeof successCallback != "function") {
31+
console.log("PushNotification.unregister failure: success callback parameter must be a function");
32+
return
33+
}
1934

20-
cordova.exec(successCallback, errorCallback, "PushPlugin", "register", [options]);
21-
};
35+
cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", [options]);
36+
};
2237

23-
// Call this to unregister for push notifications
24-
PushNotification.prototype.unregister = function(successCallback, errorCallback) {
25-
if (errorCallback == null) { errorCallback = function() {}}
38+
// Call this if you want to show toast notification on WP8
39+
PushNotification.prototype.showToastNotification = function (successCallback, errorCallback, options) {
40+
if (errorCallback == null) { errorCallback = function () { } }
2641

27-
if (typeof errorCallback != "function") {
28-
console.log("PushNotification.unregister failure: failure parameter not a function");
29-
return;
30-
}
42+
if (typeof errorCallback != "function") {
43+
console.log("PushNotification.register failure: failure parameter not a function");
44+
return
45+
}
3146

32-
if (typeof successCallback != "function") {
33-
console.log("PushNotification.unregister failure: success callback parameter must be a function");
34-
return;
35-
}
47+
cordova.exec(successCallback, errorCallback, "PushPlugin", "showToastNotification", [options]);
48+
}
3649

37-
cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", []);
38-
};
39-
40-
41-
// Call this to set the application icon badge
42-
PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, badge) {
43-
if (errorCallback == null) { errorCallback = function() {}}
50+
// Call this to set the application icon badge
51+
PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, errorCallback, badge) {
52+
if (errorCallback == null) { errorCallback = function() {}}
4453

45-
if (typeof errorCallback != "function") {
46-
console.log("PushNotification.setApplicationIconBadgeNumber failure: failure parameter not a function");
47-
return;
48-
}
54+
if (typeof errorCallback != "function") {
55+
console.log("PushNotification.setApplicationIconBadgeNumber failure: failure parameter not a function");
56+
return
57+
}
4958

50-
if (typeof successCallback != "function") {
51-
console.log("PushNotification.setApplicationIconBadgeNumber failure: success callback parameter must be a function");
52-
return;
53-
}
59+
if (typeof successCallback != "function") {
60+
console.log("PushNotification.setApplicationIconBadgeNumber failure: success callback parameter must be a function");
61+
return
62+
}
5463

55-
cordova.exec(successCallback, successCallback, "PushPlugin", "setApplicationIconBadgeNumber", [{badge: badge}]);
56-
};
64+
cordova.exec(successCallback, errorCallback, "PushPlugin", "setApplicationIconBadgeNumber", [{badge: badge}]);
65+
};
5766

5867
//-------------------------------------------------------------------
5968

60-
if(!window.plugins) {
61-
window.plugins = {};
69+
if (!window.plugins) {
70+
window.plugins = {};
6271
}
6372
if (!window.plugins.pushNotification) {
64-
window.plugins.pushNotification = new PushNotification();
73+
window.plugins.pushNotification = new PushNotification();
74+
}
75+
76+
if (typeof module != 'undefined' && module.exports) {
77+
module.exports = PushNotification;
6578
}

www/PushNotification.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
var PushNotification = function() {
22
};
33

4-
54
// Call this to register for push notifications. Content of [options] depends on whether we are working with APNS (iOS) or GCM (Android)
65
PushNotification.prototype.register = function(successCallback, errorCallback, options) {
76
if (errorCallback == null) { errorCallback = function() {}}
@@ -36,17 +35,18 @@ PushNotification.prototype.unregister = function(successCallback, errorCallback,
3635
cordova.exec(successCallback, errorCallback, "PushPlugin", "unregister", [options]);
3736
};
3837

39-
// Call this if you want to show toast notification on WP8
40-
PushNotification.prototype.showToastNotification = function (successCallback, errorCallback, options) {
41-
if (errorCallback == null) { errorCallback = function () { } }
42-
43-
if (typeof errorCallback != "function") {
44-
console.log("PushNotification.register failure: failure parameter not a function");
45-
return
46-
}
38+
// Call this if you want to show toast notification on WP8
39+
PushNotification.prototype.showToastNotification = function (successCallback, errorCallback, options) {
40+
if (errorCallback == null) { errorCallback = function () { } }
4741

48-
cordova.exec(successCallback, errorCallback, "PushPlugin", "showToastNotification", [options]);
42+
if (typeof errorCallback != "function") {
43+
console.log("PushNotification.register failure: failure parameter not a function");
44+
return
4945
}
46+
47+
cordova.exec(successCallback, errorCallback, "PushPlugin", "showToastNotification", [options]);
48+
}
49+
5050
// Call this to set the application icon badge
5151
PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallback, errorCallback, badge) {
5252
if (errorCallback == null) { errorCallback = function() {}}
@@ -66,7 +66,7 @@ PushNotification.prototype.setApplicationIconBadgeNumber = function(successCallb
6666

6767
//-------------------------------------------------------------------
6868

69-
if(!window.plugins) {
69+
if (!window.plugins) {
7070
window.plugins = {};
7171
}
7272
if (!window.plugins.pushNotification) {
@@ -75,4 +75,4 @@ if (!window.plugins.pushNotification) {
7575

7676
if (typeof module != 'undefined' && module.exports) {
7777
module.exports = PushNotification;
78-
}
78+
}

0 commit comments

Comments
 (0)