Skip to content

Instantly share code, notes, and snippets.

@vladimir-ivanov
Created May 16, 2013 16:19
Show Gist options
  • Save vladimir-ivanov/5592976 to your computer and use it in GitHub Desktop.
Save vladimir-ivanov/5592976 to your computer and use it in GitHub Desktop.
ngBlur
var BlurDirective = function () {
return {
restrict: 'A',
link: function (scope, elm, attrs) {
elm.bind('blur', function () {
console.log(attrs);
var blurArgs = attrs.blur,
functionName = blurArgs.match(/([^\(]*)/),
functionArgsString = blurArgs.match(/\(([^\)]*)\)/);
if (functionName.length && functionArgsString.length) {
var args = functionArgsString[1].indexOf(',') !== -1 ? functionArgsString.split(',') : [functionArgsString[1]];
scope[functionName[1]].apply(scope, args);
scope.$apply();
}
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment