2
2
* @ngdoc module
3
3
* @name material.components.input
4
4
*/
5
- angular . module ( 'material.components.input' , [
5
+ var inputModule = angular . module ( 'material.components.input' , [
6
6
'material.core'
7
7
] )
8
8
. directive ( 'mdInputContainer' , mdInputContainerDirective )
@@ -18,12 +18,26 @@ angular.module('material.components.input', [
18
18
19
19
. animation ( '.md-input-invalid' , mdInputInvalidMessagesAnimation )
20
20
. animation ( '.md-input-messages-animation' , ngMessagesAnimation )
21
- . animation ( '.md-input-message-animation' , ngMessageAnimation )
21
+ . animation ( '.md-input-message-animation' , ngMessageAnimation ) ;
22
+
23
+ // If we are running inside of tests; expose some extra services so that we can test them
24
+ if ( window . _mdMocksIncluded ) {
25
+ inputModule . service ( '$$mdInput' , function ( ) {
26
+ return {
27
+ // special accessor to internals... useful for testing
28
+ messages : {
29
+ show : showInputMessages ,
30
+ hide : hideInputMessages ,
31
+ getElement : getMessagesElement
32
+ }
33
+ }
34
+ } )
22
35
23
36
// Register a service for each animation so that we can easily inject them into unit tests
24
37
. service ( 'mdInputInvalidAnimation' , mdInputInvalidMessagesAnimation )
25
38
. service ( 'mdInputMessagesAnimation' , ngMessagesAnimation )
26
39
. service ( 'mdInputMessageAnimation' , ngMessageAnimation ) ;
40
+ }
27
41
28
42
/**
29
43
* @ngdoc directive
@@ -890,10 +904,10 @@ function ngMessageDirective($mdUtil) {
890
904
}
891
905
}
892
906
893
- var $$AnimateRunner , $animateCss , $mdUtil ;
907
+ var $$AnimateRunner , $animateCss , $mdUtil , $log ;
894
908
895
- function mdInputInvalidMessagesAnimation ( $$AnimateRunner , $animateCss , $mdUtil ) {
896
- saveSharedServices ( $$AnimateRunner , $animateCss , $mdUtil ) ;
909
+ function mdInputInvalidMessagesAnimation ( $$AnimateRunner , $animateCss , $mdUtil , $log ) {
910
+ saveSharedServices ( $$AnimateRunner , $animateCss , $mdUtil , $log ) ;
897
911
898
912
return {
899
913
addClass : function ( element , className , done ) {
@@ -904,8 +918,8 @@ function mdInputInvalidMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil)
904
918
} ;
905
919
}
906
920
907
- function ngMessagesAnimation ( $$AnimateRunner , $animateCss , $mdUtil ) {
908
- saveSharedServices ( $$AnimateRunner , $animateCss , $mdUtil ) ;
921
+ function ngMessagesAnimation ( $$AnimateRunner , $animateCss , $mdUtil , $log ) {
922
+ saveSharedServices ( $$AnimateRunner , $animateCss , $mdUtil , $log ) ;
909
923
910
924
return {
911
925
enter : function ( element , done ) {
@@ -934,8 +948,8 @@ function ngMessagesAnimation($$AnimateRunner, $animateCss, $mdUtil) {
934
948
} ;
935
949
}
936
950
937
- function ngMessageAnimation ( $$AnimateRunner , $animateCss , $mdUtil ) {
938
- saveSharedServices ( $$AnimateRunner , $animateCss , $mdUtil ) ;
951
+ function ngMessageAnimation ( $$AnimateRunner , $animateCss , $mdUtil , $log ) {
952
+ saveSharedServices ( $$AnimateRunner , $animateCss , $mdUtil , $log ) ;
939
953
940
954
return {
941
955
enter : function ( element , done ) {
@@ -955,8 +969,15 @@ function ngMessageAnimation($$AnimateRunner, $animateCss, $mdUtil) {
955
969
function showInputMessages ( element , done ) {
956
970
var animators = [ ] , animator ;
957
971
var messages = getMessagesElement ( element ) ;
972
+ var children = messages . children ( ) ;
973
+
974
+ if ( messages . length == 0 || children . length == 0 ) {
975
+ $log . warn ( 'mdInput messages show animation called on invalid messages element: ' , element ) ;
976
+ done ( ) ;
977
+ return ;
978
+ }
958
979
959
- angular . forEach ( messages . children ( ) , function ( child ) {
980
+ angular . forEach ( children , function ( child ) {
960
981
animator = showMessage ( angular . element ( child ) ) ;
961
982
962
983
animators . push ( animator . start ( ) ) ;
@@ -968,8 +989,15 @@ function showInputMessages(element, done) {
968
989
function hideInputMessages ( element , done ) {
969
990
var animators = [ ] , animator ;
970
991
var messages = getMessagesElement ( element ) ;
992
+ var children = messages . children ( ) ;
971
993
972
- angular . forEach ( messages . children ( ) , function ( child ) {
994
+ if ( messages . length == 0 || children . length == 0 ) {
995
+ $log . warn ( 'mdInput messages hide animation called on invalid messages element: ' , element ) ;
996
+ done ( ) ;
997
+ return ;
998
+ }
999
+
1000
+ angular . forEach ( children , function ( child ) {
973
1001
animator = hideMessage ( angular . element ( child ) ) ;
974
1002
975
1003
animators . push ( animator . start ( ) ) ;
@@ -1028,6 +1056,11 @@ function getInputElement(element) {
1028
1056
}
1029
1057
1030
1058
function getMessagesElement ( element ) {
1059
+ // If we ARE the messages element, just return ourself
1060
+ if ( element . hasClass ( 'md-input-messages-animation' ) ) {
1061
+ return element ;
1062
+ }
1063
+
1031
1064
// If we are a ng-message element, we need to traverse up the DOM tree
1032
1065
if ( element . hasClass ( 'md-input-message-animation' ) ) {
1033
1066
return angular . element ( $mdUtil . getClosest ( element , function ( node ) {
@@ -1039,8 +1072,9 @@ function getMessagesElement(element) {
1039
1072
return angular . element ( element [ 0 ] . querySelector ( '.md-input-messages-animation' ) ) ;
1040
1073
}
1041
1074
1042
- function saveSharedServices ( _$$AnimateRunner_ , _$animateCss_ , _$mdUtil_ ) {
1075
+ function saveSharedServices ( _$$AnimateRunner_ , _$animateCss_ , _$mdUtil_ , _$log_ ) {
1043
1076
$$AnimateRunner = _$$AnimateRunner_ ;
1044
1077
$animateCss = _$animateCss_ ;
1045
1078
$mdUtil = _$mdUtil_ ;
1079
+ $log = _$log_ ;
1046
1080
}
0 commit comments