From: Matthias Schmidt Date: Fri, 24 Apr 2015 15:09:40 +0000 (+0200) Subject: Add delay for geocoder requests X-Git-Tag: 2.1.4~55 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f67fb4e076afd37b7423b3b5dc7580c68d361e68;p=GitHub%2FWoltLab%2FWCF.git Add delay for geocoder requests --- diff --git a/wcfsetup/install/files/js/WCF.Location.js b/wcfsetup/install/files/js/WCF.Location.js index 0c80227a9b..75c2468f73 100644 --- a/wcfsetup/install/files/js/WCF.Location.js +++ b/wcfsetup/install/files/js/WCF.Location.js @@ -713,6 +713,7 @@ WCF.Location.GoogleMaps.LocationSearch = WCF.Search.Base.extend({ init: function(searchInput, callback, excludedSearchValues, commaSeperated, showLoadingOverlay) { this._super(searchInput, callback, excludedSearchValues, commaSeperated, showLoadingOverlay); + this.setDelay(500); this._geocoder = new google.maps.Geocoder(); }, @@ -759,9 +760,25 @@ WCF.Location.GoogleMaps.LocationSearch = WCF.Search.Base.extend({ this._clearList(true); } else if ($content.length >= this._triggerLength) { - this._geocoder.geocode({ - address: $content - }, $.proxy(this._success, this)); + if (this._delay) { + if (this._timer !== null) { + this._timer.stop(); + } + + this._timer = new WCF.PeriodicalExecuter($.proxy(function() { + this._geocoder.geocode({ + address: $content + }, $.proxy(this._success, this)); + + this._timer.stop(); + this._timer = null; + }, this), this._delay); + } + else { + this._geocoder.geocode({ + address: $content + }, $.proxy(this._success, this)); + } } else { // input below trigger length