@@ -10,7 +10,7 @@ EventDispatcher.prototype = {
10
10
const types = type . split ( '.' ) ;
11
11
const _type = types [ 0 ] ;
12
12
const namespaces = types [ 1 ] ;
13
- const listName = `${ _type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
13
+ const listName = `${ _type } ${ target ? `_ ${ target . getAttribute ( 'id' ) } ` : '' } ` ;
14
14
let list = this . _listeners [ listName ] ;
15
15
let index = 0 ;
16
16
let listener ;
@@ -28,14 +28,14 @@ EventDispatcher.prototype = {
28
28
index = i + 1 ;
29
29
}
30
30
}
31
-
31
+ const $target = target || this . _eventTarget ;
32
32
list . splice ( index , 0 , { c : callback , n : namespaces , t : _type } ) ;
33
33
if ( ! this . _listFun [ listName ] ) {
34
- this . _listFun [ listName ] = this . _listFun [ listName ] || this . dispatchEvent . bind ( this , _type , target ) ;
35
- if ( this . _eventTarget . addEventListener ) {
36
- ( target || this . _eventTarget ) . addEventListener ( _type , this . _listFun [ listName ] , false ) ;
37
- } else if ( this . _eventTarget . attachEvent ) {
38
- ( target || this . _eventTarget ) . attachEvent ( `on${ _type } ` , this . _listFun [ listName ] ) ;
34
+ this . _listFun [ listName ] = this . _listFun [ listName ] || this . dispatchEvent . bind ( this , _type ) ;
35
+ if ( $target . addEventListener ) {
36
+ $ target. addEventListener ( _type , this . _listFun [ listName ] , false ) ;
37
+ } else if ( $target . attachEvent ) {
38
+ $ target. attachEvent ( `on${ _type } ` , this . _listFun [ listName ] ) ;
39
39
}
40
40
}
41
41
} ,
@@ -44,7 +44,7 @@ EventDispatcher.prototype = {
44
44
const types = type . split ( '.' ) ;
45
45
const _type = types [ 0 ] ;
46
46
const namespaces = types [ 1 ] ;
47
- const listName = `${ _type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
47
+ const listName = `${ _type } ${ target ? `_ ${ target . getAttribute ( 'id' ) } ` : '' } ` ;
48
48
const list = this . _listeners [ listName ] ;
49
49
let i ;
50
50
let _force = force ;
@@ -53,17 +53,18 @@ EventDispatcher.prototype = {
53
53
}
54
54
if ( list ) {
55
55
i = list . length ;
56
+ const $target = target || this . _eventTarget ;
56
57
while ( -- i > - 1 ) {
57
58
if ( list [ i ] . c === callback && ( _force || list [ i ] . n === namespaces ) ) {
58
59
list . splice ( i , 1 ) ;
59
60
if ( ! list . length ) {
60
61
const func = this . _listFun [ listName ] ;
61
62
delete this . _listeners [ listName ] ;
62
63
delete this . _listFun [ listName ] ;
63
- if ( this . _eventTarget . removeEventListener ) {
64
- ( target || this . _eventTarget ) . removeEventListener ( _type , func ) ;
65
- } else if ( this . _eventTarget . detachEvent ) {
66
- ( target || this . _eventTarget ) . detachEvent ( `on${ _type } ` , func ) ;
64
+ if ( $target . removeEventListener ) {
65
+ $ target. removeEventListener ( _type , func ) ;
66
+ } else if ( $target . detachEvent ) {
67
+ $ target. detachEvent ( `on${ _type } ` , func ) ;
67
68
}
68
69
}
69
70
if ( ! _force ) {
@@ -74,8 +75,9 @@ EventDispatcher.prototype = {
74
75
}
75
76
} ,
76
77
77
- dispatchEvent ( type , target , e ) {
78
- const listName = `${ type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
78
+ dispatchEvent ( type , e ) {
79
+ const target = e . target ;
80
+ const listName = `${ type } ${ target . getAttribute ? `_${ target . getAttribute ( 'id' ) } ` : '' } ` ;
79
81
const list = this . _listeners [ listName ] ;
80
82
let i ;
81
83
let t ;
@@ -96,7 +98,7 @@ EventDispatcher.prototype = {
96
98
const types = type . split ( '.' ) ;
97
99
const _type = types [ 0 ] ;
98
100
const namespaces = types [ 1 ] ;
99
- const listName = `${ type } ${ target ? target . getAttribute ( 'id' ) : '' } ` ;
101
+ const listName = `${ _type } ${ target ? `_ ${ target . getAttribute ( 'id' ) } ` : '' } ` ;
100
102
const list = this . _listeners [ listName ] ;
101
103
this . recoverLists = this . recoverLists . concat ( dataToArray ( list ) . filter ( item =>
102
104
item . n && item . n . match ( namespaces )
0 commit comments