@@ -2,9 +2,10 @@ $(function(){
2
2
3
3
buildToc ( ) ;
4
4
5
- // SnapSVG
6
- // Run once at startup to inject all SVGs
7
- loadAllSvg ( ) ;
5
+ $ ( document ) . scrollsnap ( {
6
+ snaps : 'section' ,
7
+ proximity : 250
8
+ } ) ;
8
9
9
10
function buildToc ( ) {
10
11
var headings = $ ( "h3" ) ,
@@ -26,85 +27,17 @@ $(function(){
26
27
27
28
item = $ ( '<li><a href="#' + headingSep + '">' + headings [ h ] . innerHTML + '</a></li>' ) ;
28
29
toc . append ( item ) ;
29
- headings [ h ] . setAttribute ( "id" , headingSep ) ;
30
- $ ( '.curriculum' ) . scrollspy ( { target : '#toc' } ) ;
31
- }
32
- }
33
-
34
- function loadAllSvg ( ) {
35
- var els = document . getElementsByTagName ( "svg" ) ,
36
- elCount = 0 ;
37
-
38
- for ( elCount = 0 ; elCount < els . length ; elCount ++ ) {
39
- injectSvg ( els [ elCount ] ) ;
40
- }
41
- }
42
-
43
- function injectSvg ( canvasTarget ) {
44
- if ( canvasTarget ) {
45
- Snap . load (
46
- canvasTarget . getAttribute ( "data-path" ) ,
47
- function ( frag ) {
48
- sCanvas = Snap ( "#" + canvasTarget . getAttribute ( "id" ) ) ;
49
- fCanvas = Snap ( ) ;
50
- sCanvas . clear ( ) ;
30
+ // console.log(headings[h].parentElement);
51
31
52
- //Determine if grouped build-steps present
53
- var buildStepBase = frag . select ( "#base" ) ;
54
- buildStepGroups = frag . selectAll ( "[id^=step-]" ) ,
55
- buildStepCount = buildStepGroups . length ,
56
- buildStep = 0 ;
32
+ // var hiddenTitle = document.createElement("h3");
33
+ // hiddenTitle.setAttribute("id", headingSep);
34
+ // console.log(hiddenTitle);
57
35
58
- //Setup the container canvas boundary sizing
59
- setCanvasBBox ( frag , canvasTarget ) ;
36
+ // $(headings[h].parentElement).prepend(hiddenTitle);
60
37
61
- // Show the first build step when available
62
- // Otherwise just show entire graphic
63
- if ( buildStepCount > 0 ) {
64
- // Include the non-fragment base layout/visuals
65
- fCanvas . append ( buildStepBase ) ;
66
- // fCanvas.append(buildStepGroups[buildStep]);
38
+ headings [ h ] . parentElement . setAttribute ( "id" , headingSep ) ;
67
39
68
- for ( ; buildStep < buildStepCount ; buildStep ++ ) {
69
-
70
- // Supports fragment in-out transitions by
71
- // wrapping in a group and applying a second
72
- // fragment class
73
- if ( buildStepGroups [ buildStep ] . node . id . match ( / i n - o u t / ) ) {
74
- var tG = fCanvas . g ( buildStepGroups [ buildStep ] ) ;
75
- buildStepGroups [ buildStep ] . attr ( "class" , "fragment fade-out" ) ;
76
- tG . attr ( "class" , "fragment" ) ;
77
- fCanvas . append ( tG ) ;
78
- }
79
- else {
80
- buildStepGroups [ buildStep ] . attr ( "class" , "fragment" ) ;
81
- fCanvas . append ( buildStepGroups [ buildStep ] ) ;
82
- }
83
- }
84
- } else {
85
- //No "steps" to build out, ensure boundary guide
86
- //is not rendered
87
- frag . select ( "#boundary" ) . remove ( ) ;
88
- fCanvas . append ( frag ) ;
89
- }
90
-
91
- sCanvas . append ( fCanvas ) ;
92
- }
93
- ) ;
40
+ $ ( '.curriculum' ) . scrollspy ( { target : '#toc' } ) ;
94
41
}
95
42
}
96
-
97
- function setCanvasBBox ( canvas , target ) {
98
- var boundary ,
99
- maxWidth ,
100
- maxHeight ;
101
-
102
- boundary = canvas . select ( "#boundary" ) . select ( ":first-child" ) . getBBox ( ) ;
103
- maxWidth = Math . ceil ( boundary . width ) ;
104
- maxHeight = Math . ceil ( boundary . height ) ;
105
-
106
- target . setAttribute ( "height" , ( ( ( maxHeight / maxWidth ) * 100 ) + "%" ) ) ;
107
- target . setAttribute ( "viewBox" , "0 0 " + maxWidth + " " + maxHeight ) ;
108
- return canvas ;
109
- }
110
43
} ) ;
0 commit comments