1+ ; ( function ( root , factory ) {
2+ if ( typeof define === 'function' && define . amd ) {
3+ define ( [ 'Notify' ] , factory ) ;
4+ } else if ( typeof exports === 'object' ) {
5+ module . exports = factory ( require ( 'Notify' ) ) ;
6+ } else {
7+ root . $wtNotify = factory ( root . Notify ) ;
8+ }
9+ } ( this , function ( Notify ) {
110angular . module ( 'wt.genius' , [ ] ) ;
211/**
312 * $wtNotify
@@ -6,85 +15,82 @@ angular.module('wt.genius', []);
615 * Version: 1.0.0 - 2015-08-25
716 * Anthor: zhenshuai
817 */
9- ( function ( ) {
10- 'use strict' ;
11- angular . module ( 'wt.genius' )
12- . provider ( '$wtNotify' , [ function ( ) {
13- var defaults = {
14- title : 'Hey, 我在这里!' ,
15- body : '' ,
16- icon : '' ,
17- tag : '' ,
18- lang : 'en' ,
19- timeout : 2 ,
20- notifyShow : function ( ) {
21- } ,
22- notifyClose : function ( ) {
23- } ,
24- notifyClick : function ( ) {
25- } ,
26- notifyError : function ( ) {
18+ angular . module ( 'wt.genius' )
19+ . provider ( '$wtNotify' , [ function ( ) {
20+ var defaults = {
21+ title : 'Hey, 我在这里!' ,
22+ body : '' ,
23+ icon : '' ,
24+ tag : '' ,
25+ lang : 'en' ,
26+ timeout : 2 ,
27+ notifyShow : function ( ) {
28+ } ,
29+ notifyClose : function ( ) {
30+ } ,
31+ notifyClick : function ( ) {
32+ } ,
33+ notifyError : function ( ) {
34+ }
35+ } ;
36+ var configOptions = { } ;
37+ this . config = function ( value ) {
38+ configOptions = value ;
39+ } ;
40+ this . $get = [ function ( ) {
41+ var result ;
42+ var notify = Notify . default ;
43+
44+ function _notify ( p ) {
45+ var options = this . options = angular . extend ( { } , defaults , configOptions , p ) ;
46+ var myNotify = new Notify . default ( options . title , options ) ;
47+ if ( notify . needsPermission ) {
48+ notify . requestPermission ( function ( ) {
49+ myNotify . show ( ) ;
50+ } ) ;
51+ } else {
52+ myNotify . show ( ) ;
2753 }
28- } ;
29- var configOptions = { } ;
30- this . config = function ( value ) {
31- configOptions = value ;
32- } ;
33- this . $get = [ function ( ) {
34- var result ;
35- var notify = Notify . default ;
54+ }
3655
37- function _notify ( p ) {
38- var options = this . options = angular . extend ( { } , defaults , configOptions , p ) ;
39- var myNotify = new Notify . default ( options . title , options ) ;
56+ result = {
57+ notify : function ( p ) {
58+ //初始化,默认去验证权限
59+ return new _notify ( p ) ;
60+ } ,
61+ notSetPermission : notify . permissionLevel == 'default' ,
62+ checkPermission : function ( onSuccess , onError , onThen ) {
63+ //验证权限,设置开启与禁止
4064 if ( notify . needsPermission ) {
65+ if ( ! notify . isSupported ( ) ) {
66+ return ;
67+ }
4168 notify . requestPermission ( function ( ) {
42- myNotify . show ( ) ;
69+ result . permissionLevel = 'granted' ;
70+ result . needsPermission = false ;
71+ onSuccess && onSuccess ( ) ;
72+ } , function ( ) {
73+ result . permissionLevel = 'denied' ;
74+ result . needsPermission = true ;
75+ onError && onError ( ) ;
76+ } , function ( ) {
77+ result . notSetPermission = true ;
4378 } ) ;
4479 } else {
45- myNotify . show ( ) ;
80+ result . permissionLevel = 'granted' ;
81+ onSuccess && onSuccess ( ) ;
4682 }
47- }
48-
49- result = {
50- notify : function ( p ) {
51- //初始化,默认去验证权限
52- return new _notify ( p ) ;
53- } ,
54- notSetPermission : notify . permissionLevel == 'default' ,
55- checkPermission : function ( onSuccess , onError , onThen ) {
56- //验证权限,设置开启与禁止
57- if ( notify . needsPermission ) {
58- if ( ! notify . isSupported ( ) ) {
59- return ;
60- }
61- notify . requestPermission ( function ( ) {
62- result . permissionLevel = 'granted' ;
63- result . needsPermission = false ;
64- onSuccess && onSuccess ( ) ;
65- } , function ( ) {
66- result . permissionLevel = 'denied' ;
67- result . needsPermission = true ;
68- onError && onError ( ) ;
69- } , function ( ) {
70- result . notSetPermission = true ;
71- } ) ;
72- } else {
73- result . permissionLevel = 'granted' ;
74- onSuccess && onSuccess ( ) ;
75- }
76- result . notSetPermission = false ;
77- onThen && onThen ( ) ;
78- } ,
79- needsPermission : notify . needsPermission ,
80- requestPermission : notify . requestPermission ,
81- isSupported : notify . isSupported ,
82- permissionLevel : notify . permissionLevel
83- } ;
84- return result ;
85- } ] ;
86- } ] ) ;
87- } ) ( ) ;
83+ result . notSetPermission = false ;
84+ onThen && onThen ( ) ;
85+ } ,
86+ needsPermission : notify . needsPermission ,
87+ requestPermission : notify . requestPermission ,
88+ isSupported : notify . isSupported ,
89+ permissionLevel : notify . permissionLevel
90+ } ;
91+ return result ;
92+ } ] ;
93+ } ] ) ;
8894/**
8995 * $wtRetina
9096 *
@@ -121,4 +127,6 @@ angular.module('wt.genius', []);
121127 }
122128 ] ;
123129 } ] ) ;
124- } ) ( ) ;
130+ } ) ( ) ;
131+ return $wtNotify ;
132+ } ) ) ;
0 commit comments