2
2
3
3
import { noop } from './utilities'
4
4
5
- export default function ( Vue ) {
6
- let Directives = function ( ) { }
7
5
8
- Directives . prototype . init = function ( Vue ) {
9
- this . Vue = Vue
10
- this . registerConfirm ( )
11
- }
6
+ let Directives = function ( Vue ) {
7
+ this . Vue = Vue
8
+ this . confirmDefinition = this . defineConfirm ( )
9
+ this . alertDefinition = this . defineAlert ( )
10
+ }
12
11
13
- Directives . prototype . registerConfirm = function ( ) {
14
- const _this = this
12
+ Directives . prototype . defineConfirm = function ( ) {
13
+ const _this = this
14
+ const DirectiveDefinition = { }
15
15
16
- const clickHandler = function ( event , el , binding ) {
17
- event . preventDefault ( )
18
- event . stopImmediatePropagation ( )
16
+ const clickHandler = function ( event , el , binding ) {
17
+ event . preventDefault ( )
18
+ event . stopImmediatePropagation ( )
19
19
20
- let confirmMessage = ( function ( ) {
21
- if ( binding . value && binding . value . message ) {
22
- return binding . value . message
23
- }
24
- return typeof binding . value === 'string' ? binding . value : null
25
- } ) ( )
26
-
27
- let thenCallback = ( function ( ) {
28
- if ( binding . value && binding . value . ok ) {
29
- return binding . value . ok
30
- } else {
31
- return ( ) => {
32
- el . removeEventListener ( 'click' , el . VuejsDialog . confirmHandler , true )
33
-
34
- _this . Vue . nextTick ( ( ) => {
35
- ( function ( node ) {
36
- if ( document . createEvent ) {
37
- let evt = document . createEvent ( 'MouseEvents' ) ;
38
- evt . initEvent ( 'click' , true , false ) ;
39
- node . dispatchEvent ( evt ) ;
40
- } else if ( document . createEventObject ) {
41
- node . fireEvent ( 'onclick' ) ;
42
- } else if ( typeof node . onclick === 'function' ) {
43
- node . onclick ( ) ;
44
- }
45
- } ) ( el )
46
-
47
- el . addEventListener ( 'click' , el . VuejsDialog . confirmHandler , true )
48
- } )
49
- }
20
+ let confirmMessage = ( function ( ) {
21
+ if ( binding . value && binding . value . message ) {
22
+ return binding . value . message
23
+ }
24
+ return typeof binding . value === 'string' ? binding . value : null
25
+ } ) ( )
26
+
27
+ let thenCallback = ( function ( ) {
28
+ if ( binding . value && binding . value . ok ) {
29
+ return binding . value . ok
30
+ } else {
31
+ return ( ) => {
32
+ el . removeEventListener ( 'click' , el . VuejsDialog . clickHandler , true )
33
+
34
+ _this . Vue . nextTick ( ( ) => {
35
+ ( function ( node ) {
36
+ if ( document . createEvent ) {
37
+ let evt = document . createEvent ( 'MouseEvents' ) ;
38
+ evt . initEvent ( 'click' , true , false ) ;
39
+ node . dispatchEvent ( evt ) ;
40
+ } else if ( document . createEventObject ) {
41
+ node . fireEvent ( 'onclick' ) ;
42
+ } else if ( typeof node . onclick === 'function' ) {
43
+ node . onclick ( ) ;
44
+ }
45
+ } ) ( el )
46
+
47
+ el . addEventListener ( 'click' , el . VuejsDialog . clickHandler , true )
48
+ } )
50
49
}
51
- } ) ( )
50
+ }
51
+ } ) ( )
52
52
53
- let catchCallback = ( function ( ) {
54
- if ( binding . value && binding . value . cancel ) {
55
- return binding . value . cancel
56
- }
57
- return noop
58
- } ) ( )
53
+ let catchCallback = ( function ( ) {
54
+ if ( binding . value && binding . value . cancel ) {
55
+ return binding . value . cancel
56
+ }
57
+ return noop
58
+ } ) ( )
59
+
60
+ _this . Vue . dialog . confirm ( confirmMessage ) . then ( thenCallback ) . catch ( catchCallback )
61
+ }
59
62
60
- _this . Vue . dialog . confirm ( confirmMessage ) . then ( thenCallback ) . catch ( catchCallback )
63
+ DirectiveDefinition . bind = ( el , binding ) => {
64
+ if ( el . VuejsDialog === undefined ) {
65
+ el . VuejsDialog = { }
61
66
}
62
67
63
- this . Vue . directive ( 'confirm' , {
64
- bind ( el , binding ) {
65
- if ( el . VuejsDialog === undefined ) {
66
- el . VuejsDialog = { }
67
- }
68
+ el . VuejsDialog . clickHandler = function clickEventHandler ( event ) {
69
+ clickHandler ( event , el , binding )
70
+ }
68
71
69
- el . VuejsDialog . confirmHandler = function clickEventHandler ( event ) {
70
- clickHandler ( event , el , binding )
71
- }
72
+ el . addEventListener ( 'click' , el . VuejsDialog . clickHandler , true )
73
+ }
72
74
73
- el . addEventListener ( 'click' , el . VuejsDialog . confirmHandler , true )
74
- } ,
75
- unbind ( el ) {
76
- el . removeEventListener ( 'click' , el . VuejsDialog . confirmHandler , true )
77
- }
78
- } )
75
+ DirectiveDefinition . unbind = ( el ) => {
76
+ el . removeEventListener ( 'click' , el . VuejsDialog . clickHandler , true )
77
+ }
79
78
79
+ return DirectiveDefinition
80
+ }
80
81
81
- }
82
+ Directives . prototype . defineAlert = function ( ) {
83
+ //
84
+ }
82
85
83
- let D = new Directives ( )
84
- D . init ( Vue )
85
- }
86
+ export default Directives
0 commit comments