Skip to content

Commit 0c9d586

Browse files
author
zhenshuai
committed
wt-notify
1 parent 90fb423 commit 0c9d586

File tree

1 file changed

+36
-31
lines changed

1 file changed

+36
-31
lines changed

dist/angular-wt-genius.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -32,52 +32,57 @@ angular.module('wt.genius', []);
3232
};
3333
this.$get = ['$http', '$document', '$compile', '$rootScope', '$controller', '$templateCache', '$q', '$injector', '$position', '$timeout',
3434
function ($http, $document, $compile, $rootScope, $controller, $templateCache, $q, $injector, $position, $timeout) {
35+
var result;
36+
3537
function _notify(p) {
3638
var options = this.options = angular.extend({}, defaults, configOptions, p);
3739
var myNotify = new Notify(options.title, options);
38-
myNotify.show();
40+
if (Notify.needsPermission) {
41+
Notify.requestPermission(function () {
42+
myNotify.show();
43+
});
44+
} else {
45+
myNotify.show();
46+
}
3947
}
4048

41-
return {
49+
result = {
4250
notify : function (p) {
51+
//初始化,默认去验证权限
4352
return new _notify(p);
4453
},
45-
needsPermission : Notify.needsPermission,
46-
requestPermission: Notify.requestPermission,
47-
isSupported : Notify.isSupported,
48-
permissionLevel : Notify.permissionLevel,
49-
checkPermission : function () {
50-
var self = this;
51-
self.hasPermission = true;
52-
self.sucess = function (_fun) {
53-
_fun ? _fun() : null;
54-
return self;
55-
};
56-
self.error = function (_fun) {
57-
_fun ? _fun() : null;
58-
return self;
59-
};
60-
self.then = function (_fun) {
61-
_fun ? _fun() : null;
62-
return self;
63-
};
64-
54+
notSetPermission : Notify.permissionLevel == 'default',
55+
checkPermission : function (onSuccess, onError, onThen) {
56+
//验证权限,设置开启与禁止
57+
var onSuccess = onSuccess || function () {
58+
};
59+
var onError = onError || function () {
60+
};
61+
var onThen = onThen || function () {
62+
};
6563
if (Notify.needsPermission) {
6664
Notify.requestPermission(function () {
67-
self.hasPermission = true;
68-
self.sucess();
65+
result.permissionLevel = 'granted';
66+
result.needsPermission = false;
67+
onSuccess();
6968
}, function () {
70-
self.hasPermission = false;
71-
self.error();
69+
result.permissionLevel = 'denied';
70+
result.needsPermission = true;
71+
onError();
7272
});
7373
} else {
74-
self.sucess();
74+
result.permissionLevel = 'granted';
75+
onSuccess();
7576
}
76-
self.then();
77-
78-
return self;
79-
}
77+
result.notSetPermission = false;
78+
onThen();
79+
},
80+
needsPermission : Notify.needsPermission,
81+
requestPermission: Notify.requestPermission,
82+
isSupported : Notify.isSupported,
83+
permissionLevel : Notify.permissionLevel
8084
};
85+
return result;
8186
}
8287
];
8388
}]);

0 commit comments

Comments
 (0)