1- ( function ( ) {
1+ ( function ( ) {
22
33 initMobileMenu ( )
44 if ( PAGE_TYPE ) {
88 initLocationHashFuzzyMatching ( )
99 }
1010
11- function initApiSpecLinks ( ) {
11+ function initApiSpecLinks ( ) {
1212 var apiContent = document . querySelector ( '.content.api' )
1313 if ( apiContent ) {
1414 var apiTitles = [ ] . slice . call ( apiContent . querySelectorAll ( 'h3' ) )
15- apiTitles . forEach ( function ( titleNode ) {
15+ apiTitles . forEach ( function ( titleNode ) {
1616 var ulNode = titleNode . parentNode . nextSibling
1717 if ( ulNode . tagName !== 'UL' ) {
1818 ulNode = ulNode . nextSibling
3131 }
3232 }
3333
34- function initLocationHashFuzzyMatching ( ) {
34+ function initLocationHashFuzzyMatching ( ) {
3535 var hash = window . location . hash
3636 if ( ! hash ) return
3737 var hashTarget = document . getElementById ( hash )
3838 if ( ! hashTarget ) {
3939 var normalizedHash = normalizeHash ( hash )
4040 var possibleHashes = [ ] . slice . call ( document . querySelectorAll ( '[id]' ) )
41- . map ( function ( el ) { return el . id } )
42- possibleHashes . sort ( function ( hashA , hashB ) {
41+ . map ( function ( el ) {
42+ return el . id
43+ } )
44+ possibleHashes . sort ( function ( hashA , hashB ) {
4345 var distanceA = levenshteinDistance ( normalizedHash , normalizeHash ( hashA ) )
4446 var distanceB = levenshteinDistance ( normalizedHash , normalizeHash ( hashB ) )
4547 if ( distanceA < distanceB ) return - 1
4951 window . location . hash = possibleHashes [ 0 ]
5052 }
5153
52- function normalizeHash ( rawHash ) {
54+ function normalizeHash ( rawHash ) {
5355 return rawHash
5456 . toLowerCase ( )
5557 . replace ( / \- (?: d e p r e c a t e d | r e m o v e d | r e p l a c e d | c h a n g e d | o b s o l e t e ) $ / , '' )
5658 }
5759
58- function levenshteinDistance ( a , b ) {
60+ function levenshteinDistance ( a , b ) {
5961 var m = [ ]
6062 if ( ! ( a && b ) ) return ( b || a ) . length
6163 for ( let i = 0 ; i <= b . length ; m [ i ] = [ i ++ ] ) { }
6264 for ( let j = 0 ; j <= a . length ; m [ 0 ] [ j ] = j ++ ) { }
6365 for ( let i = 1 ; i <= b . length ; i ++ ) {
6466 for ( let j = 1 ; j <= a . length ; j ++ ) {
65- m [ i ] [ j ] = b . charAt ( i - 1 ) === a . charAt ( j - 1 )
66- ? m [ i - 1 ] [ j - 1 ]
67- : m [ i ] [ j ] = Math . min (
67+ m [ i ] [ j ] = b . charAt ( i - 1 ) === a . charAt ( j - 1 ) ?
68+ m [ i - 1 ] [ j - 1 ] :
69+ m [ i ] [ j ] = Math . min (
6870 m [ i - 1 ] [ j - 1 ] + 1 ,
6971 Math . min ( m [ i ] [ j - 1 ] + 1 , m [ i - 1 ] [ j ] + 1 ) )
7072 }
7779 * Mobile burger menu button for toggling sidebar
7880 */
7981
80- function initMobileMenu ( ) {
82+ function initMobileMenu ( ) {
8183 var mobileBar = document . getElementById ( 'mobile-bar' )
8284 var sidebar = document . querySelector ( '.sidebar' )
8385 var menuButton = mobileBar . querySelector ( '.menu-button' )
8486
85- menuButton . addEventListener ( 'click' , function ( ) {
87+ menuButton . addEventListener ( 'click' , function ( ) {
8688 sidebar . classList . toggle ( 'open' )
8789 } )
8890
89- document . body . addEventListener ( 'click' , function ( e ) {
91+ document . body . addEventListener ( 'click' , function ( e ) {
9092 if ( e . target !== menuButton && ! sidebar . contains ( e . target ) ) {
9193 sidebar . classList . remove ( 'open' )
9294 }
9799 * Doc version select
98100 */
99101
100- function initVersionSelect ( ) {
102+ function initVersionSelect ( ) {
101103 // version select
102- document . querySelector ( '.version-select' ) . addEventListener ( 'change' , function ( e ) {
104+ document . querySelector ( '.version-select' ) . addEventListener ( 'change' , function ( e ) {
103105 var version = e . target . value
104106 var section = window . location . pathname . match ( / \/ v \d \/ ( \w + ?) \/ / ) [ 1 ]
105107 if ( version === 'SELF' ) return
116118 * Sub headers in sidebar
117119 */
118120
119- function initSubHeaders ( ) {
121+ function initSubHeaders ( ) {
120122 var each = [ ] . forEach
121123 var main = document . getElementById ( 'main' )
122124 var header = document . getElementById ( 'header' )
138140 }
139141 var headers = content . querySelectorAll ( 'h2' )
140142 if ( headers . length ) {
141- each . call ( headers , function ( h ) {
143+ each . call ( headers , function ( h ) {
142144 sectionContainer . appendChild ( makeLink ( h ) )
143145 var h3s = collectH3s ( h )
144146 allHeaders . push ( h )
149151 } )
150152 } else {
151153 headers = content . querySelectorAll ( 'h3' )
152- each . call ( headers , function ( h ) {
154+ each . call ( headers , function ( h ) {
153155 sectionContainer . appendChild ( makeLink ( h ) )
154156 allHeaders . push ( h )
155157 } )
156158 }
157159
158160 var animating = false
159- sectionContainer . addEventListener ( 'click' , function ( e ) {
161+ sectionContainer . addEventListener ( 'click' , function ( e ) {
160162 e . preventDefault ( )
161163 if ( e . target . classList . contains ( 'section-link' ) ) {
162164 sidebar . classList . remove ( 'open' )
163165 setActive ( e . target )
164166 animating = true
165- setTimeout ( function ( ) {
167+ setTimeout ( function ( ) {
166168 animating = false
167169 } , 400 )
168170 }
178180 }
179181
180182 var hoveredOverSidebar = false
181- sidebar . addEventListener ( 'mouseover' , function ( ) {
183+ sidebar . addEventListener ( 'mouseover' , function ( ) {
182184 hoveredOverSidebar = true
183185 } )
184- sidebar . addEventListener ( 'mouseleave' , function ( ) {
186+ sidebar . addEventListener ( 'mouseleave' , function ( ) {
185187 hoveredOverSidebar = false
186188 } )
187189
188190 // listen for scroll event to do positioning & highlights
189191 window . addEventListener ( 'scroll' , updateSidebar )
190192 window . addEventListener ( 'resize' , updateSidebar )
191193
192- function updateSidebar ( ) {
194+ function updateSidebar ( ) {
193195 var doc = document . documentElement
194196 var top = doc && doc . scrollTop || document . body . scrollTop
195197 if ( animating || ! allHeaders ) return
204206 }
205207 }
206208 if ( last )
207- setActive ( last . id , ! hoveredOverSidebar )
209+ setActive ( last . id , ! hoveredOverSidebar )
208210 }
209211
210- function makeLink ( h ) {
212+ function makeLink ( h ) {
211213 var link = document . createElement ( 'li' )
212214 var text = h . textContent . replace ( / \( .* \) $ / , '' )
213215 link . innerHTML =
214216 '<a class="section-link" data-scroll href="#' + h . id + '">' +
215- text +
217+ text +
216218 '</a>'
217219 return link
218220 }
219221
220- function collectH3s ( h ) {
222+ function collectH3s ( h ) {
221223 var h3s = [ ]
222224 var next = h . nextSibling
223225 while ( next && next . tagName !== 'H2' ) {
229231 return h3s
230232 }
231233
232- function makeSubLinks ( h3s , small ) {
234+ function makeSubLinks ( h3s , small ) {
233235 var container = document . createElement ( 'ul' )
234236 if ( small ) {
235237 container . className = 'menu-sub'
236238 }
237- h3s . forEach ( function ( h ) {
239+ h3s . forEach ( function ( h ) {
238240 container . appendChild ( makeLink ( h ) )
239241 } )
240242 return container
241243 }
242244
243- function setActive ( id , shouldScrollIntoView ) {
245+ function setActive ( id , shouldScrollIntoView ) {
244246 var previousActive = sidebar . querySelector ( '.section-link.active' )
245- var currentActive = typeof id === 'string'
246- ? sidebar . querySelector ( '.section-link[href="#' + id + '"]' )
247- : id
247+ var currentActive = typeof id === 'string' ?
248+ sidebar . querySelector ( '.section-link[href="#' + id + '"]' ) :
249+ id
248250 if ( currentActive !== previousActive ) {
249251 if ( previousActive ) previousActive . classList . remove ( 'active' )
250252 currentActive . classList . add ( 'active' )
251253 if ( shouldScrollIntoView ) {
252- var currentPageOffset = currentPageAnchor
253- ? currentPageAnchor . offsetTop - 8
254- : 0
254+ var currentPageOffset = currentPageAnchor ?
255+ currentPageAnchor . offsetTop - 8 :
256+ 0
255257 var currentActiveOffset = currentActive . offsetTop + currentActive . parentNode . clientHeight
256258 var sidebarHeight = sidebar . clientHeight
257259 var currentActiveIsInView = (
258260 currentActive . offsetTop >= sidebar . scrollTop &&
259261 currentActiveOffset <= sidebar . scrollTop + sidebarHeight
260262 )
261263 var linkNotFurtherThanSidebarHeight = currentActiveOffset - currentPageOffset < sidebarHeight
262- var newScrollTop = currentActiveIsInView
263- ? sidebar . scrollTop
264- : linkNotFurtherThanSidebarHeight
265- ? currentPageOffset
266- : currentActiveOffset - sidebarHeight
264+ var newScrollTop = currentActiveIsInView ?
265+ sidebar . scrollTop :
266+ linkNotFurtherThanSidebarHeight ?
267+ currentPageOffset :
268+ currentActiveOffset - sidebarHeight
267269 sidebar . scrollTop = newScrollTop
268270 }
269271 }
270272 }
271273
272- function makeHeaderClickable ( link ) {
274+ function makeHeaderClickable ( link ) {
273275 var wrapper = document . createElement ( 'a' )
274276 wrapper . href = '#' + link . id
275277 wrapper . setAttribute ( 'data-scroll' , '' )
276278 link . parentNode . insertBefore ( wrapper , link )
277279 wrapper . appendChild ( link )
278280 }
279281 }
280- } ) ( )
282+ } ) ( )
0 commit comments