@@ -11,48 +11,60 @@ function DependsHandler($el, expression) {
11
11
12
12
DependsHandler . prototype = {
13
13
_findInputs : function ( name ) {
14
- var $input = this . $context . find ( ":input[name='" + name + "']" ) ;
15
- if ( ! $input . length ) $input = $ ( "#" + name ) ;
14
+ let $input = this . $context . find ( ":input[name='" + name + "']" ) ; // TODO input outside form
15
+ if ( ! $input . length ) {
16
+ $input = $ ( "#" + name ) ;
17
+ }
16
18
return $input ;
17
19
} ,
18
20
19
21
_getValue : function ( name ) {
20
- var $input = this . _findInputs ( name ) ;
21
- if ( ! $input . length ) return null ;
22
-
23
- if ( $input . attr ( "type" ) === "radio" || $input . attr ( "type" ) === "checkbox" )
22
+ const $input = this . _findInputs ( name ) ;
23
+ if ( ! $input . length ) {
24
+ return null ;
25
+ }
26
+ if ( $input . attr ( "type" ) === "radio" || $input . attr ( "type" ) === "checkbox" ) {
24
27
return $input . filter ( ":checked" ) . val ( ) || null ;
25
- else return $input . val ( ) ;
28
+ }
29
+ return $input . val ( ) ;
26
30
} ,
27
31
28
32
getAllInputs : function ( ) {
29
- var todo = [ this . ast ] ,
30
- $inputs = $ ( ) ,
31
- node ;
33
+ const todo = [ this . ast ] ;
34
+ let $inputs = $ ( ) ;
35
+ let node ;
32
36
33
37
while ( todo . length ) {
34
38
node = todo . shift ( ) ;
35
- if ( node . input ) $inputs = $inputs . add ( this . _findInputs ( node . input ) ) ;
36
- if ( node . children && node . children . length )
39
+ if ( node . input ) {
40
+ $inputs = $inputs . add ( this . _findInputs ( node . input ) ) ;
41
+ }
42
+ if ( node . children && node . children . length ) {
37
43
todo . push . apply ( todo , node . children ) ;
44
+ }
38
45
}
39
46
return $inputs ;
40
47
} ,
41
48
42
49
_evaluate : function ( node ) {
43
- var value = node . input ? this . _getValue ( node . input ) : null ,
44
- i ;
50
+ const value = node . input ? this . _getValue ( node . input ) : null ;
45
51
46
52
switch ( node . type ) {
47
53
case "NOT" :
48
54
return ! this . _evaluate ( node . children [ 0 ] ) ;
49
55
case "AND" :
50
- for ( i = 0 ; i < node . children . length ; i ++ )
51
- if ( ! this . _evaluate ( node . children [ i ] ) ) return false ;
56
+ for ( const child of node . children . length ) {
57
+ if ( ! this . _evaluate ( child ) ) {
58
+ return false ;
59
+ }
60
+ }
52
61
return true ;
53
62
case "OR" :
54
- for ( i = 0 ; i < node . children . length ; i ++ )
55
- if ( this . _evaluate ( node . children [ i ] ) ) return true ;
63
+ for ( const child of node . children ) {
64
+ if ( this . _evaluate ( child ) ) {
65
+ return true ;
66
+ }
67
+ }
56
68
return false ;
57
69
case "comparison" :
58
70
switch ( node . operator ) {
@@ -69,10 +81,14 @@ DependsHandler.prototype = {
69
81
case ">=" :
70
82
return value >= node . value ;
71
83
case "~=" :
72
- if ( value === null ) return false ;
84
+ if ( value === null ) {
85
+ return false ;
86
+ }
73
87
return value . indexOf ( node . value ) != - 1 ;
74
88
case "=~" :
75
- if ( value === null || ! node . value ) return false ;
89
+ if ( value === null || ! node . value ) {
90
+ return false ;
91
+ }
76
92
return node . value . indexOf ( value ) != - 1 ;
77
93
}
78
94
break ;
0 commit comments