Last active
December 21, 2015 00:19
-
-
Save thomasfr/6219352 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timers = {}; | |
var createGeocodeChangeWhateverFunction = function(timername, $scope) { | |
var timer = timers[timername]; | |
return function($event) { | |
if (timer != null) { | |
clearTimeout(timer); | |
} | |
timers[timername] = timer = setTimeout(function() { | |
timer = null; | |
if ($scope.shop.latitude && $scope.shop.longitude) { | |
$scope.$broadcast('positionChange', $scope.shop.latitude, $scope.shop.longitude); | |
} | |
}, 1500); | |
}; | |
} | |
// from within any controller: | |
$scope.geoCode = createGeocodeChangeWhateverFunction('positionChange', $scope); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment