Skip to content

Instantly share code, notes, and snippets.

@thomasfr
Last active December 21, 2015 00:19
Show Gist options
  • Save thomasfr/6219352 to your computer and use it in GitHub Desktop.
Save thomasfr/6219352 to your computer and use it in GitHub Desktop.
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