@@ -10,7 +10,7 @@ $(function() {
1010 $ ( '#js-sidebar .js-topic a' ) . each ( function ( ) {
1111 if ( $ ( this ) . parent ( 'li' ) . hasClass ( 'disable' ) )
1212 $ ( this ) . parent ( 'li' ) . removeClass ( 'disable' )
13-
13+
1414 var url = $ ( this ) . attr ( 'href' ) . toString ( )
1515 var cleanDocUrl = docUrl [ 1 ]
1616 if ( url . indexOf ( cleanDocUrl ) >= 0 && url . length == cleanDocUrl . length ) {
@@ -99,44 +99,44 @@ $(function() {
9999 $ ( '.api-status' ) . html ( link ) ;
100100 }
101101 } ) ;
102-
102+
103103 // Add link anchors for headers with IDs
104104 $ ( ".content h1, .content h2, .content h3, .content h4" ) . each ( function ( e ) {
105105 var id = $ ( this ) . attr ( "id" ) ;
106106 if ( ! id ) return ;
107-
107+
108108 $ ( this ) . prepend ( "<a class='header-anchor' href='#" + id + "'></a>" ) ;
109109 } ) ;
110-
110+
111111 // #### Search ####
112112 var searchIndex ,
113113 searchHits ;
114-
114+
115115 // Load the JSON containing all pages
116116 // Has it been loaded before (and stored with localstorage)?
117117 if ( localStorage [ 'searchIndex' ] ) {
118118 searchIndex = JSON . parse ( localStorage [ 'searchIndex' ] ) ;
119-
119+
120120 if ( localStorageHasExpired ( ) )
121121 loadSearchIndex ( ) ;
122122 } else {
123123 loadSearchIndex ( ) ;
124124 }
125-
125+
126126 function loadSearchIndex ( ) {
127127 $ . getJSON ( '/search-index.json' , function ( data ) {
128128 searchIndex = data [ "pages" ] ;
129129 localStorage [ 'searchIndex' ] = JSON . stringify ( searchIndex ) ;
130130 localStorage [ 'updated' ] = new Date ( ) . getTime ( ) ;
131131 } ) ;
132132 }
133-
133+
134134 function localStorageHasExpired ( ) {
135135 // Expires in one day (86400000 ms)
136136 if ( new Date ( ) . getTime ( ) - parseInt ( localStorage [ 'updated' ] , 10 ) > 86400000 ) {
137137 return true ;
138138 }
139-
139+
140140 return false ;
141141 }
142142
@@ -145,26 +145,26 @@ $(function() {
145145 $ ( "#search-container" ) . addClass ( "active" ) ;
146146 searchForString ( $ ( "#searchfield" ) . val ( ) ) ;
147147 }
148-
148+
149149 // On input change, update the search results
150150 $ ( "#searchfield" ) . on ( "input" , function ( e ) {
151151 $ ( this ) . val ( ) . length > 0 ? $ ( "#search-container" ) . addClass ( "active" ) : $ ( "#search-container" ) . removeClass ( "active" ) ;
152152
153153 searchForString ( $ ( this ) . val ( ) ) ;
154154 } ) ;
155-
155+
156156 // Global keyboard shortcuts
157157 $ ( "body" ) . keyup ( function ( e ) {
158158 if ( e . keyCode == 83 ) {
159159 // S key
160160 if ( $ ( "#searchfield" ) . is ( ":focus" ) )
161161 return ;
162-
162+
163163 e . preventDefault ( ) ;
164164 $ ( "#searchfield" ) . focus ( ) ;
165165 }
166166 } ) ;
167-
167+
168168 // Keyboard support for the search field
169169 $ ( "#searchfield" ) . keyup ( function ( e ) {
170170 if ( e . keyCode == 27 ) {
@@ -205,82 +205,89 @@ $(function() {
205205 $ ( "#search-container .search-placeholder" ) . click ( function ( e ) {
206206 $ ( "#searchfield" ) . focus ( ) ;
207207 } ) ;
208-
208+
209209 $ ( ".cancel-search" ) . click ( function ( e ) {
210210 cancelSearch ( ) ;
211211 } ) ;
212-
212+
213213 function cancelSearch ( ) {
214214 $ ( "#searchfield" ) . val ( "" ) ;
215215 $ ( "#search-container" ) . removeClass ( "active" ) ;
216216 }
217-
217+
218218 function searchForString ( searchString ) {
219219 searchHits = [ ] ;
220220 searchString = searchString . toLowerCase ( ) ;
221-
221+
222222 // Search for string in all pages
223223 for ( var i = 0 ; i < searchIndex . length ; i ++ ) {
224224 var page = searchIndex [ i ] ;
225-
225+
226226 // Add the page to the array of hits if there's a match
227227 if ( page . title . toLowerCase ( ) . indexOf ( searchString ) !== - 1 ) {
228228 searchHits . push ( page ) ;
229229 }
230230 }
231-
231+
232232 renderResultsForSearch ( searchString ) ;
233233 }
234-
234+
235235 // Update the UI representation of the search hits
236236 function renderResultsForSearch ( searchString ) {
237237 $ ( "#search-results" ) . empty ( ) ;
238-
238+
239239 // Check if there are any results. If not, show placeholder and exit
240240 if ( searchHits . length < 1 ) {
241241 $ ( '<li class="placeholder">No results for <em></em></li>' ) . appendTo ( "#search-results" ) . find ( "em" ) . text ( searchString ) ;
242242 return ;
243243 }
244-
244+
245245 // Render results (max 8)
246246 for ( var i = 0 ; i < Math . min ( searchHits . length , 8 ) ; i ++ ) {
247247 var page = searchHits [ i ] ;
248-
248+
249249 $ ( '<li class="result"><a href="' + page . url + '"><em>' + page . title + '</em><small>' + page . section + '</small></a></li>' ) . appendTo ( "#search-results" ) ;
250250 }
251-
251+
252252 // Select the first alternative
253253 $ ( "#search-results li:first-child" ) . addClass ( "selected" ) ;
254254 }
255-
255+
256256 // Move the selected list item when hovering
257257 $ ( "#search-results" ) . on ( "mouseenter" , "li" , function ( e ) {
258258 $ ( this ) . parent ( ) . find ( ".selected" ) . removeClass ( "selected" ) . end ( ) . end ( )
259259 . addClass ( "selected" ) ;
260260 } ) ;
261-
261+
262262 function moveSearchSelectionUp ( ) {
263263 $prev = $ ( "#search-results .selected" ) . prev ( ) ;
264264 if ( $prev . length < 1 )
265265 return ;
266-
266+
267267 $ ( "#search-results .selected" ) . removeClass ( "selected" ) ;
268268 $prev . addClass ( "selected" ) ;
269269 }
270-
270+
271271 function moveSearchSelectionDown ( ) {
272272 $next = $ ( "#search-results .selected" ) . next ( ) ;
273273 if ( $next . length < 1 )
274274 return ;
275-
275+
276276 $ ( "#search-results .selected" ) . removeClass ( "selected" ) ;
277277 $next . addClass ( "selected" ) ;
278278 }
279-
279+
280280 function goToSelectedSearchResult ( ) {
281281 var href = $ ( "#search-results .selected a" ) . attr ( "href" ) ;
282282 if ( href )
283283 window . location . href = href ;
284284 }
285285
286+ // Earth animation
287+ if $ ( '.dev-program' ) . length {
288+ setTimeout ( function ( ) {
289+ $ ( '.earth' ) . fadeOut ( ) ;
290+ $ ( '.earth-short-loop' ) . show ( ) ;
291+ } , 19 * 1000 ) ; // Let first loop run through 19 seconds
292+ }
286293} ) ;
0 commit comments