File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -323,6 +323,50 @@ $(document).ready(function () {
323
323
}
324
324
} ) ;
325
325
326
+ $ ( document ) . ready ( function ( ) {
327
+ // set up automatic switching of code carousel
328
+ $ ( ".code-carousel" ) . each ( function ( ) {
329
+ var carousel = this ;
330
+ var inputs = [ ] ;
331
+ $ ( carousel ) . children ( "input.code-carousel_control" ) . each ( function ( ) {
332
+ inputs . push ( this ) ;
333
+ } ) ;
334
+
335
+ // if there is more than one section, set up automatic switching
336
+ if ( inputs . length > 1 ) {
337
+
338
+ // at every timeout, switch to the next section if the page is visible
339
+ const Ticker = ( timeout ) => {
340
+ var cancelled = false ;
341
+
342
+ var index = inputs . findIndex ( input => input . checked ) ;
343
+
344
+ const interval = setInterval ( ( ) => {
345
+ if ( ! document . hidden && ! cancelled ) {
346
+ const nextIndex = ( index + 1 ) % inputs . length ;
347
+ inputs [ nextIndex ] . checked = true ;
348
+ index = nextIndex ;
349
+ }
350
+ } , timeout ) ;
351
+
352
+ const cancel = ( ) => {
353
+ cancelled = true ;
354
+ clearInterval ( interval ) ;
355
+ } ;
356
+
357
+ return { cancel } ;
358
+ } ;
359
+
360
+ const ticker = Ticker ( 8000 ) ; // switch every 8 seconds
361
+
362
+ carousel . addEventListener ( "click" , function cancelTicker ( ) {
363
+ carousel . removeEventListener ( "click" , cancelTicker ) ;
364
+ ticker . cancel ( ) ;
365
+ } ) ;
366
+ }
367
+ } ) ;
368
+ } ) ;
369
+
326
370
var image = { width : 1680 , height : 1100 } ;
327
371
var target = { x : 1028 , y : 290 } ;
328
372
You can’t perform that action at this time.
0 commit comments