landers.angular
Version:
landers.angular
46 lines (45 loc) • 2.1 kB
JavaScript
;angular.module('Landers.angular')
.provider('Notification', function() {
var provider = this;
provider.icon = '';
this.$get = [function() {
return {
show: function(content, title, options){
if (Notification && Notification.requestPermission) {
options = options || {};
Notification.requestPermission(function (permission) {
if (permission == 'granted') {
var instance = new Notification(title || '', angular.extend({
// dir: 'auto',
// lang: 'hi',
// tag: 'testTag',
icon: provider.icon,
body: content,
}, options));
instance.onclick = function(){
if (options.click_to_location) {
window.open(options.click_to_location);
}
};
instance.onclose = function(){
if (options.close_to_location) {
window.open(options.close_to_location);
}
};
} else {
console.error('Notification have no permission');
}
});
} else {
console.error('系统不支持 Notification 对象');
}
},
message: function(message, options) {
this.show(message, '', options);
},
result: function(apiResult, options) {
this.show(apiResult.message, '', options);
}
}
}]
});