File tree Expand file tree Collapse file tree 2 files changed +26
-15
lines changed Expand file tree Collapse file tree 2 files changed +26
-15
lines changed Original file line number Diff line number Diff line change 16
16
< polymer-element name ="cxx-clause " extends ="cxx-section ">
17
17
< script >
18
18
( function ( ) {
19
- var clause_num = 1 ;
19
+ function updateTocClauses ( ) {
20
+ this . super ( ) ;
21
+ var toc = document . querySelector ( 'cxx-toc' ) ;
22
+ if ( toc ) {
23
+ toc . clauses = document . querySelectorAll ( 'cxx-clause' ) ;
24
+ }
25
+ }
20
26
Polymer ( 'cxx-clause' , {
21
- attached : function ( ) {
22
- this . super ( ) ;
23
- var my_clause_num = clause_num ++ ;
24
-
25
- this . async ( function ( ) {
26
- // async() lets the descendant elements upgrade; after which we
27
- // need to traverse them to collect section numbers.
28
- this . update_sec_nums ( my_clause_num ) ;
29
- } ) ;
27
+ // Convenience function at the clause level, which gets called from <cxx-toc>.
28
+ set_clause_num : function ( clause_num ) {
29
+ this . update_sec_nums ( clause_num ) ;
30
30
} ,
31
+
32
+ attached : updateTocClauses ,
33
+ detached : updateTocClauses ,
31
34
} ) ;
32
35
} ) ( ) ;
33
36
</ script >
Original file line number Diff line number Diff line change @@ -15,10 +15,12 @@ limitations under the License.
15
15
16
16
( function ( ) {
17
17
Polymer ( 'cxx-toc' , {
18
- // Hierarchy :: [{ elem: Element, sections: Hierarchy }]
18
+ // Hierarchy :: [{ elem: Element, title: H1, sections: Hierarchy }]
19
19
sections : [ ] ,
20
20
21
- applyAuthorStyles : true ,
21
+ // Updated with the list of <cxx-clause> elements in the document each
22
+ // time such an element is attached or detached.
23
+ clauses : [ ] ,
22
24
23
25
collectSections : function ( root ) {
24
26
var sections = [ ] ;
@@ -33,9 +35,15 @@ limitations under the License.
33
35
sections : sections } ;
34
36
} ,
35
37
36
- created : function ( ) {
37
- var clauses = window . document . querySelectorAll ( 'cxx-clause' ) ;
38
- this . sections = clauses . array ( ) . map ( this . collectSections , this ) ;
38
+ clausesChanged : function ( ) {
39
+ this . sections = this . clauses . array ( ) . map ( function ( clause , index ) {
40
+ clause . set_clause_num ( index + 1 ) ;
41
+ return this . collectSections ( clause ) ;
42
+ } , this ) ;
43
+ } ,
44
+
45
+ attached : function ( ) {
46
+ this . clauses = document . querySelectorAll ( 'cxx-clause' ) ;
39
47
}
40
48
} )
41
49
} ) ( ) ;
You can’t perform that action at this time.
0 commit comments