Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3848 → Rev 3849

/trunk/widget/modules/saisie/squelettes/js/tb-geoloc/js/modules/Locality.js
40,24 → 40,33
 
this.toggleCloseButton(false);
this.places.off('input').on('input', debounce(this.launchSearch.bind(this), 500));
this.places.off('keydown').on('keydown', evt => {
const suggestionEl = $('.tb-places-suggestion');
this.places.off('keydown').on('keydown', debounce(this.handlePlacesKeydown.bind(this), 500));
}
};
 
if (27 === evt.keyCode || ESC_KEY_STRING.test(evt.key)) {
evt.preventDefault();
TbPlaces.prototype.handlePlacesKeydown = function(evt) {
const suggestionEl = $('.tb-places-suggestion'),
isEscape = 27 === evt.keyCode || ESC_KEY_STRING.test(evt.key),
isArrowDown = 40 === evt.keyCode || 'ArrowDown' === evt.key,
isEnter = 13 === evt.keyCode || 'Enter' === evt.key;
 
this.placesCloseButton.trigger('click');
this.places.focus();
} else if((40 === evt.keyCode || 'ArrowDown' === evt.key) && 0 < suggestionEl.length) {
evt.preventDefault();
if (isEscape || isArrowDown || isEnter) {
evt.preventDefault();
 
if (isEscape) {
this.placesCloseButton.trigger('click');
this.places.focus();
} else if(isArrowDown || isEnter) {
if ( 0 < suggestionEl.length) {
suggestionEl.first().focus();
} else {
this.launchSearch();
}
});
}
}
};
 
TbPlaces.prototype.launchSearch = function (evt) {
TbPlaces.prototype.launchSearch = function () {
if (!!this.places.val()) {
const url = NOMINATIM_OSM_URL+'search',
params = {'q': this.places.val()};
70,6 → 79,7
success: this.nominatimOsmResponseCallback.bind(this),
error: () => {
this.placeLabel.removeClass('loading');
this.handleSearchError();
}
});
}
83,6 → 93,8
this.toggleCloseButton();
this.resetOnClick();
this.onSuggestionSelected();
} else {
this.handleSearchError();
}
};
 
165,8 → 177,21
$('.tb-places-search-icon').toggleClass('hidden', isShow);
};
 
TbPlaces.prototype.handleSearchError = function() {
this.resetPlacesSearch();
if (0 === $('#tb-places-error').length) {
this.places.closest('#tb-places-zone').after(
`<span id="tb-places-error" class="error mb-3 mt-3">
Votre recherche n’a rien donné.<br>veuillez modifier votre recherche ou rechercher votre station directement sur la carte.
</span>`
);
setTimeout(function() {
$('#tb-places-error').remove();
}, 5000);
}
};
 
TbPlaces.prototype.resetPlacesSearch = function() {
this.places.val('');
this.toggleCloseButton(false);
this.placesResultsContainer.addClass('hidden');
this.placesResults.empty();