Add HTML5 notifications
Change-Id: I086ce9d7118e54e56bdac035925054fd627c337d
This commit is contained in:
parent
4df8197262
commit
614e1fd9ed
@ -1,23 +1,43 @@
|
|||||||
/*global PNotify */
|
/*global PNotify, window, Notification */
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('bansho.notifications', [])
|
angular.module('bansho.notifications', [])
|
||||||
.service('notifications', [
|
.service('notifications', [
|
||||||
function () {
|
function () {
|
||||||
var push = function (type, title, message) {
|
var sendNotification = function (type, title, message) {
|
||||||
|
new Notification(title, {body: message});
|
||||||
|
};
|
||||||
|
|
||||||
|
var sendPNotify = function (type, title, message) {
|
||||||
$(function(){
|
$(function(){
|
||||||
new PNotify({
|
new PNotify({
|
||||||
type: type,
|
type: type,
|
||||||
title: title,
|
title: title,
|
||||||
text: message,
|
text: message,
|
||||||
styling: {},
|
styling: {}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var push = function (type, title, message) {
|
||||||
|
if (window.Notification && Notification.permission === "granted") {
|
||||||
|
sendNotification(type, title, message);
|
||||||
|
} else if (window.Notification && Notification.permission !== "denied") {
|
||||||
|
sendPNotify(type, title, message);
|
||||||
|
|
||||||
|
// Ask permission for next time
|
||||||
|
Notification.requestPermission(function (status) {
|
||||||
|
if (Notification.permission !== status) {
|
||||||
|
Notification.permission = status;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
sendPNotify(type, title, message);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"push": push
|
"push": push
|
||||||
};
|
};
|
||||||
|
|
||||||
}]);
|
}]);
|
||||||
|
Loading…
Reference in New Issue
Block a user