Subversion Repositories eFlore/Applications.cel

Rev

Rev 3845 | Rev 3866 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3845 Rev 3849
Line 38... Line 38...
38
TbPlaces.prototype.initEvts = function() {
38
TbPlaces.prototype.initEvts = function() {
39
    if (0 < this.places.length) {
39
    if (0 < this.places.length) {
Line 40... Line 40...
40
 
40
 
41
        this.toggleCloseButton(false);
41
        this.toggleCloseButton(false);
42
        this.places.off('input').on('input', debounce(this.launchSearch.bind(this), 500));
42
        this.places.off('input').on('input', debounce(this.launchSearch.bind(this), 500));
43
        this.places.off('keydown').on('keydown', evt => {
-
 
-
 
43
        this.places.off('keydown').on('keydown', debounce(this.handlePlacesKeydown.bind(this), 500));
-
 
44
    }
Line -... Line 45...
-
 
45
};
-
 
46
 
44
            const suggestionEl = $('.tb-places-suggestion');
47
TbPlaces.prototype.handlePlacesKeydown = function(evt) {
-
 
48
    const suggestionEl = $('.tb-places-suggestion'),
45
 
49
        isEscape = 27 === evt.keyCode || ESC_KEY_STRING.test(evt.key),
Line 46... Line -...
46
            if (27 === evt.keyCode || ESC_KEY_STRING.test(evt.key)) {
-
 
47
                evt.preventDefault();
50
        isArrowDown = 40 === evt.keyCode || 'ArrowDown' === evt.key,
48
 
-
 
49
                this.placesCloseButton.trigger('click');
51
        isEnter = 13 === evt.keyCode || 'Enter' === evt.key;
Line -... Line 52...
-
 
52
 
-
 
53
    if (isEscape || isArrowDown || isEnter) {
-
 
54
        evt.preventDefault();
-
 
55
 
-
 
56
        if (isEscape) {
50
                this.places.focus();
57
            this.placesCloseButton.trigger('click');
-
 
58
            this.places.focus();
-
 
59
        } else if(isArrowDown || isEnter) {
51
            } else if((40 === evt.keyCode || 'ArrowDown' === evt.key) && 0 <  suggestionEl.length) {
60
            if ( 0 <  suggestionEl.length) {
52
                evt.preventDefault();
61
                suggestionEl.first().focus();
53
 
62
            } else {
54
                suggestionEl.first().focus();
63
                this.launchSearch();
Line 55... Line 64...
55
            }
64
            }
56
        });
65
        }
57
    }
66
    }
58
};
67
};
Line 59... Line 68...
59
 
68
 
Line 68... Line 77...
68
            url: url,
77
            url: url,
69
            data: {...NOMINATIM_OSM_DEFAULT_PARAMS, ...params},
78
            data: {...NOMINATIM_OSM_DEFAULT_PARAMS, ...params},
70
            success: this.nominatimOsmResponseCallback.bind(this),
79
            success: this.nominatimOsmResponseCallback.bind(this),
71
            error: () => {
80
            error: () => {
72
                this.placeLabel.removeClass('loading');
81
                this.placeLabel.removeClass('loading');
-
 
82
                this.handleSearchError();
73
            }
83
            }
74
        });
84
        });
75
    }
85
    }
76
};
86
};
Line 81... Line 91...
81
        this.searchResults = data;
91
        this.searchResults = data;
82
        this.setSuggestions();
92
        this.setSuggestions();
83
        this.toggleCloseButton();
93
        this.toggleCloseButton();
84
        this.resetOnClick();
94
        this.resetOnClick();
85
        this.onSuggestionSelected();
95
        this.onSuggestionSelected();
-
 
96
    } else {
-
 
97
        this.handleSearchError();
86
    }
98
    }
87
};
99
};
Line 88... Line 100...
88
 
100
 
89
TbPlaces.prototype.setSuggestions = function() {
101
TbPlaces.prototype.setSuggestions = function() {
Line 163... Line 175...
163
TbPlaces.prototype.toggleCloseButton = function(isShow = true) {
175
TbPlaces.prototype.toggleCloseButton = function(isShow = true) {
164
    this.placesCloseButton.toggleClass('hidden', !isShow);
176
    this.placesCloseButton.toggleClass('hidden', !isShow);
165
    $('.tb-places-search-icon').toggleClass('hidden', isShow);
177
    $('.tb-places-search-icon').toggleClass('hidden', isShow);
166
};
178
};
Line -... Line 179...
-
 
179
 
-
 
180
TbPlaces.prototype.handleSearchError = function() {
-
 
181
    this.resetPlacesSearch();
-
 
182
    if (0 === $('#tb-places-error').length) {
-
 
183
        this.places.closest('#tb-places-zone').after(
-
 
184
            `<span id="tb-places-error" class="error mb-3 mt-3">
-
 
185
                Votre recherche n’a rien donné.<br>veuillez modifier votre recherche ou rechercher votre station directement sur la carte.
-
 
186
            </span>`
-
 
187
        );
-
 
188
        setTimeout(function() {
-
 
189
            $('#tb-places-error').remove();
-
 
190
        }, 5000);
-
 
191
    }
-
 
192
};
167
 
193
 
168
TbPlaces.prototype.resetPlacesSearch = function() {
-
 
169
    this.places.val('');
194
TbPlaces.prototype.resetPlacesSearch = function() {
170
    this.toggleCloseButton(false);
195
    this.toggleCloseButton(false);
171
    this.placesResultsContainer.addClass('hidden');
196
    this.placesResultsContainer.addClass('hidden');
172
    this.placesResults.empty();
197
    this.placesResults.empty();