Skip to content

Commit 1a38e19

Browse files
committed
Upgrading to html5-desktop-notifications 3.0.0
1 parent bb0cbb0 commit 1a38e19

File tree

7 files changed

+115
-125
lines changed

7 files changed

+115
-125
lines changed

angular-web-notification.js

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
* @description
1717
* Initializes the angular web notification service.
1818
*
19-
* @param {object} notifyLib - The HTML5 notification library instance
19+
* @param {object} NotifyLib - The HTML5 notification library instance
2020
*/
21-
(function initWebNotification(notifyLib) {
21+
(function initWebNotification(NotifyLib) {
2222
'use strict';
2323

2424
var webNotification = window.angular.module('angular-web-notification', []);
@@ -36,6 +36,15 @@
3636
webNotification.factory('webNotification', function onCreateService() {
3737
var service = {};
3838

39+
/**
40+
* The internal Notification library used by this angular module.
41+
*
42+
* @memberof! webNotification
43+
* @alias webNotification.lib
44+
* @private
45+
*/
46+
service.lib = NotifyLib;
47+
3948
/**
4049
* True to enable automatic requesting of permissions if needed.
4150
*
@@ -56,7 +65,7 @@
5665
* @returns {boolean} True if permission is granted, else false
5766
*/
5867
get: function getPermission() {
59-
var permission = notifyLib.permissionLevel();
68+
var permission = NotifyLib.permission;
6069

6170
/**
6271
* True if permission is granted, else false.
@@ -66,7 +75,7 @@
6675
* @public
6776
*/
6877
var permissionGranted = false;
69-
if (permission === notifyLib.PERMISSION_GRANTED) {
78+
if (permission === 'granted') {
7079
permissionGranted = true;
7180
}
7281

@@ -104,13 +113,7 @@
104113
* @returns {boolean} True if allowed to show web notifications
105114
*/
106115
var isEnabled = function () {
107-
var enabled = notifyLib.isSupported;
108-
109-
if (enabled) {
110-
enabled = service.permissionGranted;
111-
}
112-
113-
return enabled;
116+
return service.permissionGranted;
114117
};
115118

116119
/**
@@ -132,28 +135,31 @@
132135
*/
133136
var createAndDisplayNotification = function (title, options) {
134137
var autoClose = 0;
135-
if (options && options.autoClose && (typeof options.autoClose === 'number')) {
138+
if (options.autoClose && (typeof options.autoClose === 'number')) {
136139
autoClose = options.autoClose;
137140
}
138-
notifyLib.config({
139-
autoClose: autoClose
140-
});
141141

142142
//defaults the notification icon to the website favicon.ico
143143
if (!options.icon) {
144144
options.icon = '/favicon.ico';
145145
}
146146

147-
var notification = notifyLib.createNotification(title, options);
147+
var notification = new NotifyLib(title, options);
148148

149149
//add onclick handler
150-
if (options.onClick && notification && notification.webNotification) {
151-
notification.webNotification.onclick = options.onClick;
150+
if (options.onClick && notification) {
151+
notification.onclick = options.onClick;
152152
}
153153

154-
return function hideNotification() {
154+
var hideNotification = function () {
155155
notification.close();
156156
};
157+
158+
if (autoClose) {
159+
setTimeout(hideNotification, autoClose);
160+
}
161+
162+
return hideNotification;
157163
};
158164

159165
/**
@@ -255,7 +261,7 @@
255261
hideNotification = createAndDisplayNotification(title, options);
256262
callback(null, hideNotification);
257263
} else if (service.allowRequest) {
258-
notifyLib.requestPermission(function onRequestDone() {
264+
NotifyLib.requestPermission(function onRequestDone() {
259265
if (isEnabled()) {
260266
hideNotification = createAndDisplayNotification(title, options);
261267
callback(null, hideNotification);
@@ -271,4 +277,4 @@
271277

272278
return service;
273279
});
274-
}(window.notify));
280+
}(window.Notification));

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-web-notification",
3-
"version": "1.0.15",
3+
"version": "1.0.16",
44
"description": "AngularJS service for displaying web notifications.",
55
"authors": [
66
"Sagie Gur-Ari <sagiegurari@gmail.com>"
@@ -24,7 +24,7 @@
2424
"target"
2525
],
2626
"dependencies": {
27-
"HTML5-Desktop-Notifications2": "1.0.1",
27+
"html5-desktop-notifications": "3.0.0",
2828
"angular": "~1"
2929
},
3030
"devDependencies": {

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| Date | Version | Description |
22
| ----------- | ------- | ----------- |
3+
| 2016-11-04 | v1.0.16 | Upgrading to html5-desktop-notifications 3.0.0 |
34
| 2016-10-16 | v1.0.15 | Maintenance |
45
| 2016-09-10 | v1.0.6 | Default to website favicon.ico if icon not provided in options |
56
| 2016-09-07 | v1.0.4 | Callback is now optional |

docs/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
<title>Angular Web Notification Example</title>
66
<script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
77
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script>
8-
<script type="text/javascript" src="https://rawgit.com/sagiegurari/HTML5-Desktop-Notifications/master/desktop-notify.js"></script>
9-
<script type="text/javascript" src="https://rawgit.com/sagiegurari/angular-web-notification/master/angular-web-notification.js"></script>
8+
<script type="text/javascript" src="https://rawgit.com/ttsvetko/HTML5-Desktop-Notifications/master/dist/Notification.js"></script>
9+
<script type="text/javascript" src="../angular-web-notification.js"></script>
10+
<!--TODO <script type="text/javascript" src="https://rawgit.com/sagiegurari/angular-web-notification/master/angular-web-notification.js"></script>-->
1011
<script type="text/javascript" src="example/example.js"></script>
1112

1213
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-web-notification",
3-
"version": "1.0.15",
3+
"version": "1.0.16",
44
"description": "AngularJS service for displaying web notifications.",
55
"author": {
66
"name": "Sagie Gur-Ari",

test/helpers/notify-mock.js

Lines changed: 39 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,60 @@
1-
window.notify = (function () {
1+
window.Notification = (function Notification() {
22
'use strict';
33

4-
var notifyOptions;
5-
var permission;
6-
var lib = {
7-
PERMISSION_GRANTED: 'granted',
8-
config: function (options) {
9-
notifyOptions = options;
10-
},
11-
requestPermission: function (callback) {
12-
setTimeout(function mockDelay() {
13-
callback();
14-
}, 5);
15-
},
16-
permissionLevel: function () {
17-
return permission;
18-
},
19-
getConfig: function () {
20-
return notifyOptions;
21-
}
4+
var permissionInfo = {
5+
value: null
226
};
237

24-
lib.createNotification = function (title, options) {
25-
lib.validateNotification(title, options);
8+
var oncePermission;
269

27-
var notification = {
28-
close: function mockClose() {
29-
if (options.onClick) {
30-
this.webNotification.onclick();
31-
}
10+
var Lib = function (title, options) {
11+
Lib.validateNotification(title, options);
3212

33-
return undefined;
34-
},
35-
webNotification: {}
13+
var self = this;
14+
self.close = function () {
15+
if (options.onClick) {
16+
self.onclick();
17+
}
3618
};
37-
38-
return notification;
3919
};
4020

41-
lib.setValidationNotification = function (validateNotification) {
42-
lib.validateNotification = validateNotification || function () {
43-
return undefined;
44-
};
45-
};
21+
Lib.MOCK_NOTIFY = true;
4622

47-
lib.setAllowed = function (validateNotification) {
48-
lib.setValidationNotification(validateNotification);
23+
Object.defineProperty(Lib, 'permission', {
24+
enumerable: true,
25+
get: function () {
26+
return permissionInfo.value;
27+
}
28+
});
4929

50-
lib.isSupported = true;
51-
permission = 'granted';
52-
};
30+
Lib.requestPermission = function (callback) {
31+
if (oncePermission) {
32+
oncePermission();
33+
oncePermission = null;
34+
}
5335

54-
lib.setSupportedOnly = function () {
55-
lib.setValidationNotification(null);
56-
lib.isSupported = true;
57-
permission = 'not-granted';
36+
setTimeout(callback, 5);
5837
};
5938

60-
lib.setNotSupported = function () {
61-
lib.setValidationNotification(null);
62-
lib.isSupported = false;
63-
permission = 'not-granted';
39+
Lib.setValidationNotification = function (validateNotification) {
40+
Lib.validateNotification = validateNotification || function noop() {
41+
return undefined;
42+
};
6443
};
6544

66-
lib.setFirstTimePermissions = function (validateNotification) {
67-
lib.orgRequestPermission = lib.requestPermission;
68-
lib.setValidationNotification(validateNotification);
69-
70-
lib.requestPermission = function (callback) {
71-
permission = 'granted';
45+
Lib.setAllowed = function (validateNotification) {
46+
Lib.setValidationNotification(validateNotification);
47+
permissionInfo.value = 'granted';
48+
};
7249

73-
lib.orgRequestPermission(callback);
74-
lib.requestPermission = lib.orgRequestPermission;
75-
};
50+
Lib.setNotAllowed = function (validateNotification) {
51+
Lib.setValidationNotification(validateNotification);
52+
permissionInfo.value = 'not-granted';
53+
};
7654

77-
lib.setSupportedOnly();
55+
Lib.onceRequestPermission = function (callback) {
56+
oncePermission = callback;
7857
};
7958

80-
return lib;
59+
return Lib;
8160
}());

0 commit comments

Comments
 (0)