From f67fb4e076afd37b7423b3b5dc7580c68d361e68 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Fri, 24 Apr 2015 17:09:40 +0200 Subject: [PATCH] Add delay for geocoder requests --- wcfsetup/install/files/js/WCF.Location.js | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) 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 -- 2.20.1