Skip to content

Commit c1eb9cf

Browse files
committed
Configurable expand mode, click is now default
1 parent 1525058 commit c1eb9cf

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

Control.Geocoder.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
L.Control.Geocoder = L.Control.extend({
2020
options: {
2121
collapsed: true,
22+
expand: 'click',
2223
position: 'topright',
2324
placeholder: 'Search...',
2425
errorMessage: 'Nothing found.'
@@ -60,10 +61,13 @@
6061
L.DomEvent.addListener(form, 'submit', this._geocode, this);
6162

6263
if (this.options.collapsed) {
63-
L.DomEvent.addListener(input, 'mouseover', this._expand, this);
64-
L.DomEvent.addListener(input, 'mouseout', this._collapse, this);
65-
66-
this._map.on('movestart', this._collapse, this);
64+
if (this.options.expand === 'click') {
65+
L.DomEvent.addListener(input, 'click', this._toggle, this);
66+
} else {
67+
L.DomEvent.addListener(input, 'mouseover', this._expand, this);
68+
L.DomEvent.addListener(input, 'mouseout', this._collapse, this);
69+
this._map.on('movestart', this._collapse, this);
70+
}
6771
} else {
6872
this._expand();
6973
}
@@ -111,12 +115,21 @@
111115
return false;
112116
},
113117

118+
_toggle: function() {
119+
if (this._container.className.indexOf('leaflet-control-geocoder-expanded') >= 0) {
120+
this._collapse();
121+
} else {
122+
this._expand();
123+
}
124+
},
125+
114126
_expand: function () {
115127
L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-expanded');
116128
},
117129

118130
_collapse: function () {
119131
this._container.className = this._container.className.replace(' leaflet-control-geocoder-expanded', '');
132+
this._alts.style.display = 'none';
120133
},
121134

122135
_clearResults: function () {

0 commit comments

Comments
 (0)