@@ -6,7 +6,7 @@ export default {
6
6
options : {
7
7
showResultIcons : false ,
8
8
collapsed : true ,
9
- expand : 'touch ' , // options: touch, click, anythingelse
9
+ expand : 'hover ' , // options: click or anything else (hover or touch)
10
10
position : 'topright' ,
11
11
placeholder : 'Search...' ,
12
12
errorMessage : 'Nothing found.' ,
@@ -69,54 +69,26 @@ export default {
69
69
this
70
70
) ;
71
71
72
+ // based on https://github.com/leaflet/leaflet/blob/2dbda53/src/control/Control.Layers.js#L187-L211
72
73
if ( this . options . collapsed ) {
74
+ this . _map . on ( 'click' , this . _collapse , this ) ;
75
+ this . _map . on ( 'movestart' , this . _collapse , this ) ;
73
76
if ( this . options . expand === 'click' ) {
74
- L . DomEvent . addListener (
75
- container ,
76
- 'click' ,
77
- function ( e ) {
78
- if ( e . button === 0 && e . detail !== 2 ) {
79
- this . _toggle ( ) ;
80
- }
81
- } ,
82
- this
83
- ) ;
84
- } else if ( L . Browser . touch && this . options . expand === 'touch' ) {
85
- L . DomEvent . addListener (
86
- container ,
87
- 'touchstart mousedown' ,
88
- function ( e ) {
89
- this . _toggle ( ) ;
90
- e . preventDefault ( ) ; // mobile: clicking focuses the icon, so UI expands and immediately collapses
91
- e . stopPropagation ( ) ;
92
- } ,
93
- this
94
- ) ;
95
- } else {
96
- L . DomEvent . addListener ( container , 'mouseover' , this . _expand , this ) ;
97
- L . DomEvent . addListener ( container , 'mouseout' , this . _collapse , this ) ;
98
- this . _map . on ( 'movestart' , this . _collapse , this ) ;
77
+ L . DomEvent . on ( container , 'click' , L . DomEvent . stop ) ;
78
+ L . DomEvent . on ( container , 'click' , this . _expand , this ) ;
79
+ } else if ( ! L . Browser . android ) {
80
+ L . DomEvent . addListener ( container , 'mouseenter' , this . _expand , this ) ;
81
+ L . DomEvent . addListener ( container , 'mouseleave' , this . _collapse , this ) ;
99
82
}
100
83
} else {
101
84
this . _expand ( ) ;
85
+ }
86
+ if ( this . options . expand !== 'click' ) {
102
87
if ( L . Browser . touch ) {
103
- L . DomEvent . addListener (
104
- container ,
105
- 'touchstart' ,
106
- function ( ) {
107
- this . _geocode ( ) ;
108
- } ,
109
- this
110
- ) ;
88
+ L . DomEvent . on ( container , 'click' , L . DomEvent . stop ) ;
89
+ L . DomEvent . on ( container , 'click' , this . _expand , this ) ;
111
90
} else {
112
- L . DomEvent . addListener (
113
- container ,
114
- 'click' ,
115
- function ( ) {
116
- this . _geocode ( ) ;
117
- } ,
118
- this
119
- ) ;
91
+ L . DomEvent . on ( container , 'focus' , this . _expand , this ) ;
120
92
}
121
93
}
122
94
0 commit comments