Created
May 16, 2013 16:19
-
-
Save vladimir-ivanov/5592976 to your computer and use it in GitHub Desktop.
ngBlur
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 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