31
31
</example>
32
32
*/
33
33
/*
34
- * A directive that allows creation of custom onclick handlers that are defined as angular
34
+ * A directive that allows creation of custom event handlers that are defined as angular
35
35
* expressions and are compiled and executed within the current scope.
36
36
*
37
37
* Events that are handled via these handler are always configured not to propagate further.
38
38
*/
39
39
var ngEventDirectives = { } ;
40
40
forEach (
41
- 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit focus blur copy cut paste' . split ( ' ' ) ,
41
+ 'click dblclick mousedown mouseup mouseover mouseout mousemove mouseenter mouseleave keydown keyup keypress submit copy cut paste' . split ( ' ' ) ,
42
42
function ( name ) {
43
43
var directiveName = directiveNormalize ( 'ng-' + name ) ;
44
44
ngEventDirectives [ directiveName ] = [ '$parse' , function ( $parse ) {
@@ -58,6 +58,31 @@ forEach(
58
58
}
59
59
) ;
60
60
61
+ /*
62
+ * Focus and blur need to use $evalAsync to prevent $rootScope.inprog errors when focus() / blur() are triggered
63
+ * during a digest
64
+ */
65
+ forEach (
66
+ 'focus blur' . split ( ' ' ) ,
67
+ function ( name ) {
68
+ var directiveName = directiveNormalize ( 'ng-' + name ) ;
69
+ ngEventDirectives [ directiveName ] = [ '$parse' , function ( $parse ) {
70
+ return {
71
+ compile : function ( $element , attr ) {
72
+ var fn = $parse ( attr [ directiveName ] ) ;
73
+ return function ( scope , element , attr ) {
74
+ element . on ( lowercase ( name ) , function ( event ) {
75
+ scope . $evalAsync ( function ( ) {
76
+ fn ( scope , { $event :event } ) ;
77
+ } ) ;
78
+ } ) ;
79
+ } ;
80
+ }
81
+ } ;
82
+ } ] ;
83
+ }
84
+ ) ;
85
+
61
86
/**
62
87
* @ngdoc directive
63
88
* @name ngDblclick
0 commit comments