@@ -9,76 +9,77 @@ function batScopeTreeDirective($compile) {
9
9
scope : {
10
10
batModel : '='
11
11
} ,
12
- link : function ( scope , element , attrs ) {
13
-
14
- // scope.$id –> DOM node
15
- var map = { } ;
16
- var selectedElt = angular . element ( ) ;
17
-
18
- // init
19
- var scopes = scope . batModel ;
20
- if ( scopes ) {
21
- Object . keys ( scopes ) . forEach ( function ( scopeId ) {
22
- var parentId = scopes [ scopeId ] . parent ;
23
- renderScopeElement ( scopeId , parentId ) ;
24
- renderScopeDescriptorElement ( scopeId , scopes [ scopeId ] . descriptor ) ;
25
- } ) ;
26
- }
12
+ link : batScopeTreeLink
13
+ } ;
27
14
28
- scope . $on ( 'scope:new' , function ( ev , data ) {
29
- renderScopeElement ( data . child , data . parent ) ;
15
+ function batScopeTreeLink ( scope , element , attrs ) {
16
+ // scope.$id –> DOM node
17
+ var map = { } ;
18
+ var selectedElt = angular . element ( ) ;
19
+
20
+ // init
21
+ var scopes = scope . batModel ;
22
+ if ( scopes ) {
23
+ Object . keys ( scopes ) . forEach ( function ( scopeId ) {
24
+ var parentId = scopes [ scopeId ] . parent ;
25
+ renderScopeElement ( scopeId , parentId ) ;
26
+ renderScopeDescriptorElement ( scopeId , scopes [ scopeId ] . descriptor ) ;
30
27
} ) ;
28
+ }
31
29
32
- // when a scope is linked, we can apply the descriptor info
33
- scope . $on ( 'scope:link' , function ( ev , data ) {
34
- renderScopeDescriptorElement ( data . id , data . descriptor ) ;
35
- } ) ;
30
+ scope . $on ( 'scope:new' , function ( ev , data ) {
31
+ renderScopeElement ( data . child , data . parent ) ;
32
+ } ) ;
36
33
37
- function renderScopeElement ( id , parentId ) {
38
- if ( map [ id ] ) {
39
- return ;
40
- }
41
- var elt = map [ id ] = newBranchElement ( id ) ;
42
- var parentElt = map [ parentId ] || element ;
43
-
44
- elt . children ( ) . eq ( 1 ) . on ( 'click' , function ( ) {
45
- scope . $apply ( function ( ) {
46
- scope . $emit ( 'inspected-scope:change' , {
47
- id : id
48
- } ) ;
49
- selectedElt . children ( ) . eq ( 0 ) . removeClass ( 'selected' ) ;
50
- selectedElt . children ( ) . eq ( 1 ) . removeClass ( 'selected' ) ;
51
-
52
- selectedElt = elt ;
53
-
54
- selectedElt . children ( ) . eq ( 0 ) . addClass ( 'selected' ) ;
55
- selectedElt . children ( ) . eq ( 1 ) . addClass ( 'selected' ) ;
56
- } ) ;
57
- } ) ;
34
+ // when a scope is linked, we can apply the descriptor info
35
+ scope . $on ( 'scope:link' , function ( ev , data ) {
36
+ renderScopeDescriptorElement ( data . id , data . descriptor ) ;
37
+ } ) ;
58
38
59
- parentElt . append ( elt ) ;
39
+ function renderScopeElement ( id , parentId ) {
40
+ if ( map [ id ] ) {
41
+ return ;
60
42
}
43
+ var elt = map [ id ] = newBranchElement ( id ) ;
44
+ var parentElt = map [ parentId ] || element ;
61
45
62
- function renderScopeDescriptorElement ( id , descriptor ) {
63
- var elt = map [ id ] ;
64
- if ( ! elt ) {
65
- return ;
66
- }
67
- elt . children ( ) . eq ( 1 ) . children ( ) . eq ( 1 ) . html ( descriptor ) ;
68
- }
46
+ elt . children ( ) . eq ( 1 ) . on ( 'click' , function ( ) {
47
+ scope . $apply ( function ( ) {
48
+ scope . $emit ( 'inspected-scope:change' , {
49
+ id : id
50
+ } ) ;
51
+ selectedElt . children ( ) . eq ( 0 ) . removeClass ( 'selected' ) ;
52
+ selectedElt . children ( ) . eq ( 1 ) . removeClass ( 'selected' ) ;
53
+
54
+ selectedElt = elt ;
69
55
70
- // TODO: also destroy elements corresponding to descendant scopes
71
- scope . $on ( 'scope:destroy' , function ( ev , data ) {
72
- var id = data . id ;
73
- var elt = map [ id ] ;
74
- if ( elt ) {
75
- elt . remove ( ) ;
76
- }
77
- delete map [ id ] ;
56
+ selectedElt . children ( ) . eq ( 0 ) . addClass ( 'selected' ) ;
57
+ selectedElt . children ( ) . eq ( 1 ) . addClass ( 'selected' ) ;
58
+ } ) ;
78
59
} ) ;
79
60
61
+ parentElt . append ( elt ) ;
80
62
}
81
- } ;
63
+
64
+ function renderScopeDescriptorElement ( id , descriptor ) {
65
+ var elt = map [ id ] ;
66
+ if ( ! elt ) {
67
+ return ;
68
+ }
69
+ elt . children ( ) . eq ( 1 ) . children ( ) . eq ( 1 ) . html ( descriptor ) ;
70
+ }
71
+
72
+ // TODO: also destroy elements corresponding to descendant scopes
73
+ scope . $on ( 'scope:destroy' , function ( ev , data ) {
74
+ var id = data . id ;
75
+ var elt = map [ id ] ;
76
+ if ( elt ) {
77
+ elt . remove ( ) ;
78
+ }
79
+ delete map [ id ] ;
80
+ } ) ;
81
+
82
+ }
82
83
}
83
84
84
85
@@ -94,4 +95,3 @@ function newBranchElement(descriptor) {
94
95
'</span>' ,
95
96
'</ol>' ] . join ( '' ) ) ;
96
97
}
97
-
0 commit comments