Skip to content

Commit fa6c663

Browse files
committed
added support to disable automatic permission request
1 parent f1c0748 commit fa6c663

File tree

3 files changed

+54
-17
lines changed

3 files changed

+54
-17
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,11 @@ bower install angular-web-notification --save
6464
## Limitations
6565
The web notifications API is not fully supported in all browsers.
6666

67-
Please see [HTML5-Desktop-Notifications](https://github.com/ttsvetko/HTML5-Desktop-Notifications) for more information.
67+
Please see http://caniuse.com/#feat=notifications for more information on the official spec support and at [HTML5-Desktop-Notifications](https://github.com/ttsvetko/HTML5-Desktop-Notifications) for more browser specific API support.
6868

6969
## Release History
7070

71+
* 2014-12-09 v0.0.3 API now enables/disables the capability to automatically request for permissions needed to display the notification.
7172
* 2014-12-08 v0.0.2 Initial release.
7273

7374
## License

angular-web-notification.js

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*global notify: false, angular: false */
2+
23
(function (notifyLib) {
34
'use strict';
45

@@ -39,7 +40,14 @@
3940
};
4041
};
4142

42-
return {
43+
var service = {
44+
/**
45+
* True to enable automatic requesting of permissions if needed.
46+
*
47+
* @memberof! webNotification
48+
* @public
49+
*/
50+
allowRequest: true,//true to enable automatic requesting of permissions if needed
4351
/**
4452
* Shows the notification based on the provided input.<br>
4553
* The callback invoked will get an error object (in case of an error, null in
@@ -48,8 +56,8 @@
4856
* @function
4957
* @memberof! webNotification
5058
* @public
51-
* @param {string} title - The notification title text
52-
* @param {object} options - Holds the notification data (see https://github.com/ttsvetko/HTML5-Desktop-Notifications.git for more info)
59+
* @param {string} [title] - The notification title text (defaulted to empty string if null is provided)
60+
* @param {object} [options] - Holds the notification data (web notification API spec for more info)
5361
* @param {function} callback - Called after the show is handled.
5462
* @example
5563
* webNotification.showNotification('Example Notification', {
@@ -65,22 +73,50 @@
6573
* }
6674
* });
6775
*/
68-
showNotification: function (title, options, callback) {
69-
var hideNotification = null;
70-
if (isEnabled()) {
71-
hideNotification = createAndDisplayNotification(title, options);
72-
callback(null, hideNotification);
73-
} else {
74-
notifyLib.requestPermission(function onRequestDone() {
75-
if (isEnabled()) {
76-
hideNotification = createAndDisplayNotification(title, options);
77-
callback(null, hideNotification);
76+
showNotification: function () {
77+
//convert to array to enable modifications
78+
var argumentsArray = Array.prototype.slice.call(arguments, 0);
79+
80+
if ((argumentsArray.length >= 1) && (argumentsArray.length <= 3)) {
81+
//callback is always the last argument
82+
var callback = argumentsArray.pop();
83+
84+
var title = null;
85+
var options = null;
86+
if (argumentsArray.length === 2) {
87+
title = argumentsArray[0];
88+
options = argumentsArray[1];
89+
} else if (argumentsArray.length === 1) {
90+
var value = argumentsArray.pop();
91+
if (typeof value === 'string') {
92+
title = value || '';
93+
options = {};
7894
} else {
79-
callback(new Error('Notification is not enabled.'), null);
95+
title = '';
96+
options = value;
8097
}
81-
});
98+
}
99+
100+
var hideNotification = null;
101+
if (isEnabled()) {
102+
hideNotification = createAndDisplayNotification(title, options);
103+
callback(null, hideNotification);
104+
} else if (service.allowRequest) {
105+
notifyLib.requestPermission(function onRequestDone() {
106+
if (isEnabled()) {
107+
hideNotification = createAndDisplayNotification(title, options);
108+
callback(null, hideNotification);
109+
} else {
110+
callback(new Error('Notifications are not enabled.'), null);
111+
}
112+
});
113+
} else {
114+
callback(new Error('Notifications are not enabled.'), null);
115+
}
82116
}
83117
}
84118
};
119+
120+
return service;
85121
});
86122
}(notify));

bower.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": "0.0.2",
3+
"version": "0.0.3",
44
"authors": [
55
"Sagie Gur-Ari <[email protected]>"
66
],

0 commit comments

Comments
 (0)