Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions dist/leaflet-geocoder-mapzen.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,16 @@
}

if (results && results.features) {
// Ignore requests if input is currently blank, it is stale
if (this._input.value === '') {
return;
}

// Ignore requests that started before a request which has already
// been successfully rendered on to the UI.
if (this.maxReqTimestampRendered < reqStartedAt) {
this.maxReqTimestampRendered = reqStartedAt;
this.showResults(results.features);
this.showResults(results.features, params.text);
this.fire('results', {
results: results,
endpoint: endpoint,
Expand Down Expand Up @@ -307,7 +312,7 @@
}
},

showResults: function (features) {
showResults: function (features, input) {
// Exit function if there are no features
if (features.length === 0) {
this.showMessage('No results were found.');
Expand Down Expand Up @@ -353,9 +358,7 @@
layerIcon.title = 'layer: ' + feature.properties.layer;
}

if (this._input.value.length > 0) {
resultItem.innerHTML += this.highlight(feature.properties.label, this._input.value);
}
resultItem.innerHTML += this.highlight(feature.properties.label, input);
}
},

Expand Down
2 changes: 1 addition & 1 deletion spec/suites/InterfaceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe('Interface', function () {
geocoder = new L.Control.Geocoder();
geocoder.addTo(map);
geocoder.expand();
geocoder.showResults(results.features);
geocoder.showResults(results.features, 'foo');
});

it('has no highlighted result at first', function () {
Expand Down
7 changes: 3 additions & 4 deletions spec/suites/ResultsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ describe('Results', function () {
describe('#showResults', function () {
it('displays a message if there are no results', function () {
// Empty features array. (is response guaranteed to be an array?)
geocoder.showResults([]);
geocoder.showResults([], 'foo');

expect(el.querySelector('.leaflet-pelias-message').textContent).to.be.a('string');
});

it('displays results', function () {
geocoder.showResults(results.features);
geocoder.showResults(results.features, 'foo');

// No message should be shown
expect(el.querySelector('.leaflet-pelias-message')).to.not.be.ok();
Expand All @@ -67,7 +67,6 @@ describe('Results', function () {

it('highlights snippets of the text label with the query text', function () {
// Test case insensitive matching
geocoder._input.value = 'foo';
geocoder.showResults([{
'properties': {
'layer': 'region',
Expand All @@ -76,7 +75,7 @@ describe('Results', function () {
'geometry': {
'coordinates': [0, 0]
}
}]);
}], 'foo');

expect(el.querySelector('.leaflet-pelias-result').innerHTML).to.contain('<strong>Foo</strong>');
});
Expand Down