1
- window . addEventListener ( "DOMContentLoaded" , ( ) => {
2
- var toggler = document . getElementById ( "leftToggler" ) ;
3
- if ( toggler ) {
4
- toggler . onclick = function ( ) {
5
- document . getElementById ( "leftColumn" ) . classList . toggle ( "open" ) ;
6
- } ;
1
+ let observer = null ;
2
+
3
+ function attachAllListeners ( ) {
4
+ if ( observer ) {
5
+ observer . disconnect ( )
7
6
}
8
7
9
8
var scrollPosition = sessionStorage . getItem ( "scroll_value" ) ;
@@ -54,24 +53,89 @@ window.addEventListener("DOMContentLoaded", () => {
54
53
}
55
54
}
56
55
}
57
-
58
- $ ( ".side-menu span" ) . on ( "click" , function ( ) {
59
- $ ( this ) . parent ( ) . toggleClass ( "expanded" ) ;
60
- } ) ;
56
+ $ ( ".side-menu span" ) . on ( "click" , function ( ) {
57
+ $ ( this ) . parent ( ) . toggleClass ( "expanded" ) ;
58
+ } ) ;
59
+ document . querySelectorAll ( 'a' ) . forEach ( el => {
60
+ const href = el . href
61
+ if ( href === "" ) { return }
62
+ const url = new URL ( href )
63
+ el . addEventListener ( 'click' , e => {
64
+ if ( url . href . replace ( "#" , "" ) === window . location . href . replace ( "#" , "" ) ) { return }
65
+ if ( url . origin !== window . location . origin ) { return }
66
+ if ( e . metaKey || e . ctrlKey || e . shiftKey || e . altKey || e . button !== 0 ) { return }
67
+ e . preventDefault ( )
68
+ e . stopPropagation ( )
69
+ $ . get ( href , function ( data ) {
70
+ const html = $ . parseHTML ( data )
71
+ const title = html . find ( node => node . nodeName === "TITLE" ) . innerText
72
+ const bodyDiv = html . find ( node => node . nodeName === "DIV" )
73
+ const { children } = document . body . firstChild
74
+ if ( window . history . state === null ) {
75
+ window . history . replaceState ( {
76
+ leftColumn : children [ 3 ] . innerHTML ,
77
+ mainDiv : children [ 6 ] . innerHTML ,
78
+ title : document . title ,
79
+ } , '' )
80
+ }
81
+ document . title = title
82
+ const leftColumn = bodyDiv . children [ 3 ] . innerHTML
83
+ const mainDiv = bodyDiv . children [ 6 ] . innerHTML
84
+ window . history . pushState ( { leftColumn, mainDiv, title } , '' , href )
85
+ children [ 3 ] . innerHTML = leftColumn
86
+ children [ 6 ] . innerHTML = mainDiv
87
+ attachAllListeners ( )
88
+ } )
89
+ } )
90
+ } )
91
+
92
+ document . querySelectorAll ( 'a' ) . forEach ( el => {
93
+ const href = el . href
94
+ if ( href === "" ) { return }
95
+ const url = new URL ( href )
96
+ el . addEventListener ( 'click' , e => {
97
+ if ( url . href . replace ( "#" , "" ) === window . location . href . replace ( "#" , "" ) ) { return }
98
+ if ( url . origin !== window . location . origin ) { return }
99
+ if ( e . metaKey || e . ctrlKey || e . shiftKey || e . altKey || e . button !== 0 ) { return }
100
+ e . preventDefault ( )
101
+ e . stopPropagation ( )
102
+ $ . get ( href , function ( data ) {
103
+ const html = $ . parseHTML ( data )
104
+ const title = html . find ( node => node . nodeName === "TITLE" ) . innerText
105
+ const bodyDiv = html . find ( node => node . nodeName === "DIV" )
106
+ const { children } = document . body . firstChild
107
+ if ( window . history . state === null ) {
108
+ window . history . replaceState ( {
109
+ leftColumn : children [ 3 ] . innerHTML ,
110
+ mainDiv : children [ 6 ] . innerHTML ,
111
+ title : document . title ,
112
+ } , '' )
113
+ }
114
+ document . title = title
115
+ const leftColumn = bodyDiv . children [ 3 ] . innerHTML
116
+ const mainDiv = bodyDiv . children [ 6 ] . innerHTML
117
+ window . history . pushState ( { leftColumn, mainDiv, title } , '' , href )
118
+ children [ 3 ] . innerHTML = leftColumn
119
+ children [ 6 ] . innerHTML = mainDiv
120
+ attachAllListeners ( )
121
+ } )
122
+ } )
123
+ } )
61
124
62
125
$ ( ".ar" ) . on ( "click" , function ( e ) {
63
126
$ ( this ) . parent ( ) . parent ( ) . toggleClass ( "expanded" ) ;
64
127
$ ( this ) . toggleClass ( "expanded" ) ;
65
128
e . stopPropagation ( ) ;
66
129
} ) ;
67
130
68
- document . querySelectorAll ( ".nh" ) . forEach ( ( el ) =>
69
- el . addEventListener ( "click" , ( ) => {
70
- el . lastChild . click ( ) ;
71
- el . first . addClass ( "expanded" ) ;
72
- el . parent . addClass ( "expanded" ) ;
73
- } ) ,
74
- ) ;
131
+ document . querySelectorAll ( ".nh" ) . forEach ( el => el . addEventListener ( 'click' , ( ) => {
132
+ if ( el . lastChild . href . replace ( "#" , "" ) === window . location . href . replace ( "#" , "" ) ) {
133
+ el . parentElement . classList . toggle ( "expanded" )
134
+ el . firstChild . classList . toggle ( "expanded" )
135
+ } else {
136
+ el . lastChild . click ( )
137
+ }
138
+ } ) )
75
139
76
140
document . querySelectorAll ( ".supertypes" ) . forEach ( ( el ) =>
77
141
el . firstChild . addEventListener ( "click" , ( ) => {
@@ -104,154 +168,128 @@ window.addEventListener("DOMContentLoaded", () => {
104
168
} ) ,
105
169
) ;
106
170
107
- const observer = new IntersectionObserver ( ( entries ) => {
108
- entries . forEach ( ( entry ) => {
109
- const id = entry . target . getAttribute ( "id" ) ;
171
+ const observer = new IntersectionObserver ( entries => {
172
+ entries . forEach ( entry => {
173
+ const id = entry . target . getAttribute ( 'id' ) ;
110
174
if ( entry . intersectionRatio > 0 ) {
111
- document
112
- . querySelector ( `#toc li a[href="#${ id } "]` )
113
- . parentElement . classList . add ( "active" ) ;
175
+ document . querySelector ( `#toc li a[href="#${ id } "]` ) . parentElement . classList . add ( 'active' ) ;
114
176
} else {
115
- document
116
- . querySelector ( `#toc li a[href="#${ id } "]` )
117
- . parentElement . classList . remove ( "active" ) ;
177
+ document . querySelector ( `#toc li a[href="#${ id } "]` ) . parentElement . classList . remove ( 'active' ) ;
118
178
}
119
179
} ) ;
120
180
} ) ;
121
181
122
- document . querySelectorAll ( " #content section[id]" ) . forEach ( ( section ) => {
182
+ document . querySelectorAll ( ' #content section[id]' ) . forEach ( ( section ) => {
123
183
observer . observe ( section ) ;
124
184
} ) ;
125
185
126
- document
127
- . querySelectorAll ( ".side-menu a" )
128
- . forEach ( ( elem ) =>
129
- elem . addEventListener ( "click" , ( e ) => e . stopPropagation ( ) ) ,
130
- ) ;
131
-
132
186
if ( location . hash ) {
133
187
var target = location . hash . substring ( 1 ) ;
134
188
// setting the 'expand' class on the top-level container causes undesireable styles
135
189
// to apply to the top-level docs, so we avoid this logic for that element.
136
- if ( target != " container" ) {
190
+ if ( target != ' container' ) {
137
191
var selected = document . getElementById ( location . hash . substring ( 1 ) ) ;
138
192
if ( selected ) {
139
193
selected . classList . toggle ( "expand" ) ;
140
194
}
141
195
}
142
196
}
143
197
144
- var logo = document . getElementById ( "logo" ) ;
145
- if ( logo ) {
146
- logo . onclick = function ( ) {
147
- window . location = pathToRoot ; // global variable pathToRoot is created by the html renderer
148
- } ;
149
- }
150
-
151
- document . querySelectorAll ( ".documentableAnchor" ) . forEach ( ( elem ) => {
152
- elem . addEventListener ( "click" , ( event ) => {
153
- var $temp = $ ( "<input>" ) ;
154
- $ ( "body" ) . append ( $temp ) ;
155
- var a = document . createElement ( "a" ) ;
156
- a . href = $ ( elem ) . attr ( "link" ) ;
157
- $temp . val ( a . href ) . select ( ) ;
158
- document . execCommand ( "copy" ) ;
159
- $temp . remove ( ) ;
160
- } ) ;
198
+ document . querySelectorAll ( 'pre code' ) . forEach ( el => {
199
+ hljs . highlightBlock ( el ) ;
161
200
} ) ;
162
201
163
- hljs . registerLanguage ( "scala" , highlightDotty ) ;
164
- hljs . registerAliases ( [ "dotty" , "scala3" ] , "scala" ) ;
165
- hljs . initHighlighting ( ) ;
166
-
167
202
/* listen for the `F` key to be pressed, to focus on the member filter input (if it's present) */
168
- document . body . addEventListener ( " keydown" , ( e ) => {
203
+ document . body . addEventListener ( ' keydown' , e => {
169
204
if ( e . key == "f" ) {
170
205
const tag = e . target . tagName ;
171
206
if ( tag != "INPUT" && tag != "TEXTAREA" ) {
172
- const filterInput = findRef (
173
- ".documentableFilter input.filterableInput" ,
174
- ) ;
207
+ const filterInput = findRef ( '.documentableFilter input.filterableInput' ) ;
175
208
if ( filterInput != null ) {
176
209
// if we focus during this event handler, the `f` key gets typed into the input
177
210
setTimeout ( ( ) => filterInput . focus ( ) , 1 ) ;
178
211
}
179
212
}
180
213
}
181
- } ) ;
182
-
183
- // show/hide side menu on mobile view
184
- const sideMenuToggler = document . getElementById ( "mobile-sidebar-toggle" ) ;
185
- sideMenuToggler . addEventListener ( "click" , ( _e ) => {
186
- document . getElementById ( "leftColumn" ) . classList . toggle ( "show" ) ;
187
- document . getElementById ( "content" ) . classList . toggle ( "sidebar-shown" ) ;
188
- const toc = document . getElementById ( "toc" ) ;
189
- if ( toc ) {
190
- toc . classList . toggle ( "sidebar-shown" ) ;
191
- }
192
- sideMenuToggler . classList . toggle ( "menu-shown" ) ;
193
- } ) ;
194
-
195
- // show/hide mobile menu on mobile view
196
- const mobileMenuOpenIcon = document . getElementById ( "mobile-menu-toggle" ) ;
197
- const mobileMenuCloseIcon = document . getElementById ( "mobile-menu-close" ) ;
198
- mobileMenuOpenIcon . addEventListener ( "click" , ( _e ) => {
199
- document . getElementById ( "mobile-menu" ) . classList . add ( "show" ) ;
200
- } ) ;
201
- mobileMenuCloseIcon . addEventListener ( "click" , ( _e ) => {
202
- document . getElementById ( "mobile-menu" ) . classList . remove ( "show" ) ;
203
- } ) ;
214
+ } )
204
215
205
216
// when document is loaded graph needs to be shown
217
+ }
218
+
219
+ window . addEventListener ( "DOMContentLoaded" , ( ) => {
220
+ hljs . registerLanguage ( "scala" , highlightDotty ) ;
221
+ hljs . registerAliases ( [ "dotty" , "scala3" ] , "scala" ) ;
222
+ attachAllListeners ( )
206
223
} ) ;
207
224
225
+ // show/hide side menu on mobile view
226
+ const sideMenuToggler = document . getElementById ( "mobile-sidebar-toggle" )
227
+ sideMenuToggler . addEventListener ( 'click' , _e => {
228
+ document . getElementById ( "leftColumn" ) . classList . toggle ( "show" )
229
+ document . getElementById ( "content" ) . classList . toggle ( "sidebar-shown" )
230
+ const toc = document . getElementById ( "toc" ) ;
231
+ if ( toc && toc . childElementCount > 0 ) {
232
+ toc . classList . toggle ( "sidebar-shown" )
233
+ }
234
+ sideMenuToggler . classList . toggle ( "menu-shown" )
235
+ } )
236
+
237
+ // show/hide mobile menu on mobile view
238
+ document . getElementById ( "mobile-menu-toggle" ) . addEventListener ( 'click' , _e => {
239
+ document . getElementById ( "mobile-menu" ) . classList . add ( "show" )
240
+ } )
241
+ document . getElementById ( "mobile-menu-close" ) . addEventListener ( 'click' , _e => {
242
+ document . getElementById ( "mobile-menu" ) . classList . remove ( "show" )
243
+ } )
244
+
245
+ window . addEventListener ( 'popstate' , e => {
246
+ const { leftColumn, mainDiv, title } = e . state
247
+ document . title = title
248
+ const { children } = document . body . firstChild
249
+ children [ 3 ] . innerHTML = leftColumn
250
+ children [ 6 ] . innerHTML = mainDiv
251
+ attachAllListeners ( )
252
+ } )
253
+
208
254
var zoom ;
209
255
var transform ;
210
256
211
257
function showGraph ( ) {
212
- document . getElementById ( "inheritance-diagram" ) . classList . add ( "shown" ) ;
258
+ document . getElementById ( "inheritance-diagram" ) . classList . add ( "shown" )
213
259
if ( $ ( "svg#graph" ) . children ( ) . length == 0 ) {
214
- var dotNode = document . querySelector ( "#dot" ) ;
260
+ var dotNode = document . querySelector ( "#dot" )
215
261
216
262
if ( dotNode ) {
217
263
var svg = d3 . select ( "#graph" ) ;
218
- var radialGradient = svg
219
- . append ( "defs" )
220
- . append ( "radialGradient" )
221
- . attr ( "id" , "Gradient" ) ;
222
- radialGradient
223
- . append ( "stop" )
224
- . attr ( "stop-color" , "var(--yellow9)" )
225
- . attr ( "offset" , "30%" ) ;
226
- radialGradient
227
- . append ( "stop" )
228
- . attr ( "stop-color" , "var(--background-default)" )
229
- . attr ( "offset" , "100%" ) ;
264
+ var radialGradient = svg . append ( "defs" ) . append ( "radialGradient" ) . attr ( "id" , "Gradient" ) ;
265
+ radialGradient . append ( "stop" ) . attr ( "stop-color" , "var(--yellow9)" ) . attr ( "offset" , "30%" ) ;
266
+ radialGradient . append ( "stop" ) . attr ( "stop-color" , "var(--background-default)" ) . attr ( "offset" , "100%" ) ;
230
267
231
268
var inner = svg . append ( "g" ) ;
232
269
233
270
// Set up zoom support
234
- zoom = d3 . zoom ( ) . on ( "zoom" , function ( { transform } ) {
235
- inner . attr ( "transform" , transform ) ;
236
- } ) ;
271
+ zoom = d3 . zoom ( )
272
+ . on ( "zoom" , function ( { transform } ) {
273
+ inner . attr ( "transform" , transform ) ;
274
+ } ) ;
237
275
svg . call ( zoom ) ;
238
276
239
277
var render = new dagreD3 . render ( ) ;
240
278
var g = graphlibDot . read ( dotNode . text ) ;
241
- g . graph ( ) . rankDir = "BT" ;
279
+ g . graph ( ) . rankDir = 'BT' ;
242
280
g . nodes ( ) . forEach ( function ( v ) {
243
281
g . setNode ( v , {
244
282
labelType : "html" ,
245
283
label : g . node ( v ) . label ,
246
284
class : g . node ( v ) . class ,
247
285
id : g . node ( v ) . id ,
248
286
rx : "4px" ,
249
- ry : "4px" ,
287
+ ry : "4px"
250
288
} ) ;
251
289
} ) ;
252
290
g . setNode ( "node0Cluster" , {
253
291
style : "fill: url(#Gradient);" ,
254
- id : "node0Cluster" ,
292
+ id : "node0Cluster"
255
293
} ) ;
256
294
g . setParent ( "node0" , "node0Cluster" ) ;
257
295
@@ -262,8 +300,7 @@ function showGraph() {
262
300
} ) ;
263
301
264
302
render . arrows ( ) . hollowPoint = function normal ( parent , id , edge , type ) {
265
- var marker = parent
266
- . append ( "marker" )
303
+ var marker = parent . append ( "marker" )
267
304
. attr ( "id" , id )
268
305
. attr ( "viewBox" , "0 0 10 10" )
269
306
. attr ( "refX" , 9 )
@@ -273,8 +310,7 @@ function showGraph() {
273
310
. attr ( "markerHeight" , 12 )
274
311
. attr ( "orient" , "auto" ) ;
275
312
276
- var path = marker
277
- . append ( "path" )
313
+ var path = marker . append ( "path" )
278
314
. attr ( "d" , "M 0 0 L 10 5 L 0 10 z" )
279
315
. style ( "stroke-width" , 1 )
280
316
. style ( "stroke-dasharray" , "1,0" )
@@ -296,10 +332,7 @@ function showGraph() {
296
332
midY = bounds . y + height / 2 ;
297
333
if ( width == 0 || height == 0 ) return ; // nothing to fit
298
334
var scale = Math . min ( fullWidth / width , fullHeight / height ) * 0.99 ; // 0.99 to make a little padding
299
- var translate = [
300
- fullWidth / 2 - scale * midX ,
301
- fullHeight / 2 - scale * midY ,
302
- ] ;
335
+ var translate = [ fullWidth / 2 - scale * midX , fullHeight / 2 - scale * midY ] ;
303
336
304
337
transform = d3 . zoomIdentity
305
338
. translate ( translate [ 0 ] , translate [ 1 ] )
@@ -313,25 +346,22 @@ function showGraph() {
313
346
var node0Cluster = d3 . select ( "g#node0Cluster" ) . _groups [ 0 ] [ 0 ] ;
314
347
var node0ClusterRect = node0Cluster . children [ 0 ] ;
315
348
node0Cluster . setAttribute ( "transform" , node0 . getAttribute ( "transform" ) ) ;
316
- node0ClusterRect . setAttribute (
317
- "width" ,
318
- + node0Rect . getAttribute ( "width" ) + 80 ,
319
- ) ;
320
- node0ClusterRect . setAttribute (
321
- "height" ,
322
- + node0Rect . getAttribute ( "height" ) + 80 ,
323
- ) ;
349
+ node0ClusterRect . setAttribute ( "width" , + node0Rect . getAttribute ( "width" ) + 80 ) ;
350
+ node0ClusterRect . setAttribute ( "height" , + node0Rect . getAttribute ( "height" ) + 80 ) ;
324
351
node0ClusterRect . setAttribute ( "x" , node0Rect . getAttribute ( "x" ) - 40 ) ;
325
352
node0ClusterRect . setAttribute ( "y" , node0Rect . getAttribute ( "y" ) - 40 ) ;
326
353
}
327
354
}
328
355
}
329
356
330
357
function hideGraph ( ) {
331
- document . getElementById ( "inheritance-diagram" ) . classList . remove ( "shown" ) ;
358
+ document . getElementById ( "inheritance-diagram" ) . classList . remove ( "shown" )
332
359
}
333
360
334
361
function zoomOut ( ) {
335
362
var svg = d3 . select ( "#graph" ) ;
336
- svg . transition ( ) . duration ( 2000 ) . call ( zoom . transform , transform ) ;
363
+ svg
364
+ . transition ( )
365
+ . duration ( 2000 )
366
+ . call ( zoom . transform , transform ) ;
337
367
}
0 commit comments