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,32 @@ forEach(
58
58
}
59
59
) ;
60
60
61
+ /*
62
+ * Focus and blur need to use $evalAsync to prevent $rootScope.inprog errors caused by other event directives triggering
63
+ * focus() and blur() respectively
64
+ *
65
+ */
66
+ forEach (
67
+ 'focus blur' . split ( ' ' ) ,
68
+ function ( name ) {
69
+ var directiveName = directiveNormalize ( 'ng-' + name ) ;
70
+ ngEventDirectives [ directiveName ] = [ '$parse' , function ( $parse ) {
71
+ return {
72
+ compile : function ( $element , attr ) {
73
+ var fn = $parse ( attr [ directiveName ] ) ;
74
+ return function ( scope , element , attr ) {
75
+ element . on ( lowercase ( name ) , function ( event ) {
76
+ scope . $evalAsync ( function ( ) {
77
+ fn ( scope , { $event :event } ) ;
78
+ } ) ;
79
+ } ) ;
80
+ } ;
81
+ }
82
+ } ;
83
+ } ] ;
84
+ }
85
+ ) ;
86
+
61
87
/**
62
88
* @ngdoc directive
63
89
* @name ngDblclick
0 commit comments