|
36 | 36 | },
|
37 | 37 |
|
38 | 38 | onAdd: function (map) {
|
39 |
| - this._map = map; |
40 |
| - var className = 'leaflet-control-geocoder'; |
41 |
| - |
42 |
| - var form = this._form = L.DomUtil.create('form', className + '-form'); |
| 39 | + var className = 'leaflet-control-geocoder', |
| 40 | + container = L.DomUtil.create('div', className), |
| 41 | + form = this._form = L.DomUtil.create('form', className + '-form', container), |
| 42 | + input, |
| 43 | + icon; |
43 | 44 |
|
44 |
| - var input = this._input = document.createElement('input'); |
| 45 | + this._map = map; |
| 46 | + input = this._input = document.createElement('input'); |
45 | 47 | input.type = 'text';
|
46 | 48 |
|
47 | 49 | L.DomEvent.addListener(input, 'keydown', this._keydown, this);
|
48 | 50 | //L.DomEvent.addListener(input, 'onpaste', this._clearResults, this);
|
49 | 51 | //L.DomEvent.addListener(input, 'oninput', this._clearResults, this);
|
50 | 52 |
|
| 53 | + icon = L.DomUtil.create('div', 'leaflet-control-geocoder-icon'); |
| 54 | + container.appendChild(icon); |
| 55 | + |
51 | 56 | this._errorElement = document.createElement('div');
|
52 | 57 | this._errorElement.className = className + '-form-no-error';
|
53 | 58 | this._errorElement.innerHTML = this.options.errorMessage;
|
54 | 59 |
|
55 |
| - this._alts = L.DomUtil.create('ul', className + '-alternatives'); |
56 |
| - this._alts.style.display = 'none'; |
| 60 | + this._alts = L.DomUtil.create('ul', className + '-alternatives leaflet-control-geocoder-alternatives-minimized'); |
57 | 61 |
|
58 | 62 | form.appendChild(input);
|
59 | 63 | form.appendChild(this._errorElement);
|
60 |
| - form.appendChild(this._alts); |
| 64 | + container.appendChild(this._alts); |
61 | 65 |
|
62 | 66 | L.DomEvent.addListener(form, 'submit', this._geocode, this);
|
63 | 67 |
|
64 | 68 | if (this.options.collapsed) {
|
65 | 69 | if (this.options.expand === 'click') {
|
66 |
| - L.DomEvent.addListener(input, 'click', function(e) { |
| 70 | + L.DomEvent.addListener(icon, 'click', function(e) { |
67 | 71 | // TODO: touch
|
68 | 72 | if (e.button === 0 && e.detail === 1) {
|
69 | 73 | this._toggle();
|
70 | 74 | }
|
71 | 75 | }, this);
|
72 | 76 | } else {
|
73 |
| - L.DomEvent.addListener(input, 'mouseover', this._expand, this); |
74 |
| - L.DomEvent.addListener(input, 'mouseout', this._collapse, this); |
| 77 | + L.DomEvent.addListener(icon, 'mouseover', this._expand, this); |
| 78 | + L.DomEvent.addListener(icon, 'mouseout', this._collapse, this); |
75 | 79 | this._map.on('movestart', this._collapse, this);
|
76 | 80 | }
|
77 | 81 | } else {
|
78 | 82 | this._expand();
|
79 | 83 | }
|
80 | 84 |
|
81 |
| - return form; |
| 85 | + return container; |
82 | 86 | },
|
83 | 87 |
|
84 | 88 | _geocodeResult: function (results) {
|
85 |
| - this._form.className = this._form.className.replace(' leaflet-control-geocoder-throbber', ''); |
| 89 | + L.DomUtil.removeClass(this._container, 'leaflet-control-geocoder-throbber'); |
86 | 90 | if (results.length === 1) {
|
87 | 91 | this._geocodeResultSelected(results[0]);
|
88 | 92 | } else if (results.length > 0) {
|
| 93 | + this._alts.innerHTML = ''; |
89 | 94 | this._results = results;
|
90 |
| - this._alts.style.display = 'block'; |
| 95 | + L.DomUtil.removeClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); |
91 | 96 | for (var i = 0; i < results.length; i++) {
|
92 | 97 | this._alts.appendChild(this._createAlt(results[i], i));
|
93 | 98 | }
|
|
114 | 119 | _geocode: function(event) {
|
115 | 120 | L.DomEvent.preventDefault(event);
|
116 | 121 |
|
117 |
| - this._form.className += ' leaflet-control-geocoder-throbber'; |
| 122 | + L.DomUtil.addClass(this._container, 'leaflet-control-geocoder-throbber'); |
118 | 123 | this._clearResults();
|
119 | 124 | this.options.geocoder.geocode(this._input.value, this._geocodeResult, this);
|
120 | 125 |
|
|
143 | 148 |
|
144 | 149 | _collapse: function () {
|
145 | 150 | this._container.className = this._container.className.replace(' leaflet-control-geocoder-expanded', '');
|
146 |
| - this._alts.style.display = 'none'; |
| 151 | + L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); |
147 | 152 | },
|
148 | 153 |
|
149 | 154 | _clearResults: function () {
|
150 |
| - this._alts.style.display = 'none'; |
151 |
| - this._alts.innerHTML = ''; |
| 155 | + L.DomUtil.addClass(this._alts, 'leaflet-control-geocoder-alternatives-minimized'); |
152 | 156 | this._selection = null;
|
153 | 157 | L.DomUtil.removeClass(this._errorElement, 'leaflet-control-geocoder-error');
|
154 | 158 | },
|
|
0 commit comments