Add delay for geocoder requests
authorMatthias Schmidt <gravatronics@live.com>
Fri, 24 Apr 2015 15:09:40 +0000 (17:09 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 24 Apr 2015 15:09:40 +0000 (17:09 +0200)
wcfsetup/install/files/js/WCF.Location.js

index 0c80227a9becbd5e59ddb8eb8975b00248c67128..75c2468f7344f041bd48685c94acd55e4f773a46 100644 (file)
@@ -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