1
1
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
2
- /*! Version 2.3.1 */
2
+ /*! Version 2.3.2 */
3
3
4
4
'use strict' ;
5
5
@@ -305,9 +305,11 @@ class HyperaudioLite {
305
305
this . setupTranscriptWords ( ) ;
306
306
this . setupEventListeners ( doubleClick , playOnClick ) ;
307
307
this . setupInitialPlayHead ( ) ;
308
+ this . setupAutoScroll ( autoscroll ) ;
308
309
this . minimizedMode = minimizedMode ;
309
310
this . autoscroll = autoscroll ;
310
311
this . webMonetization = webMonetization ;
312
+ this . scrollerContainer = this . transcript ;
311
313
}
312
314
313
315
// Setup hash for transcript selection
@@ -389,10 +391,31 @@ class HyperaudioLite {
389
391
setupTranscriptWords ( ) {
390
392
const words = this . transcript . querySelectorAll ( '[data-m]' ) ;
391
393
this . wordArr = this . createWordArray ( words ) ;
392
- this . parentTag = words [ 0 ] . parentElement . tagName ;
394
+
395
+ // check for elements with data-m attributes that are not directly below <section>
396
+ // these will contain <p> or similar that we can scroll to
397
+
398
+ for ( const word of words ) {
399
+ let parentTagName = word . parentElement . tagName ;
400
+ if ( parentTagName !== "SECTION" ) {
401
+ this . parentTag = parentTagName ;
402
+ break ;
403
+ }
404
+ }
405
+
393
406
this . parentElements = this . transcript . getElementsByTagName ( this . parentTag ) ;
394
407
}
395
408
409
+ setupAutoScroll ( autoscroll ) {
410
+ if ( autoscroll ) {
411
+ if ( window . Velocity ) {
412
+ this . scroller = window . Velocity ;
413
+ } else if ( window . jQuery && window . jQuery . Velocity ) {
414
+ this . scroller = window . jQuery . Velocity ;
415
+ }
416
+ }
417
+ }
418
+
396
419
// Setup event listeners for interactions
397
420
setupEventListeners ( doubleClick , playOnClick ) {
398
421
this . minimizedMode = false ;
@@ -403,10 +426,6 @@ class HyperaudioLite {
403
426
this . highlightedText = false ;
404
427
this . start = null ;
405
428
406
- if ( this . autoscroll ) {
407
- this . scroller = window . Velocity || window . jQuery . Velocity ;
408
- }
409
-
410
429
const playHeadEvent = doubleClick ? 'dblclick' : 'click' ;
411
430
this . transcript . addEventListener ( playHeadEvent , this . setPlayHead . bind ( this ) , false ) ;
412
431
this . transcript . addEventListener ( playHeadEvent , this . checkPlayHead . bind ( this ) , false ) ;
@@ -418,7 +437,7 @@ class HyperaudioLite {
418
437
if ( ! isNaN ( parseFloat ( this . start ) ) ) {
419
438
this . highlightedText = true ;
420
439
let indices = this . updateTranscriptVisualState ( this . start ) ;
421
- if ( indices . currentWordIndex > 0 ) {
440
+ if ( indices . currentWordIndex > 0 && this . autoscroll ) {
422
441
this . scrollToParagraph ( indices . currentParentElementIndex , indices . currentWordIndex ) ;
423
442
}
424
443
}
@@ -591,6 +610,7 @@ class HyperaudioLite {
591
610
592
611
// Scroll to the paragraph containing the current word
593
612
scrollToParagraph ( currentParentElementIndex , index ) {
613
+
594
614
const scrollNode = this . wordArr [ index - 1 ] . n . closest ( 'p' ) || this . wordArr [ index - 1 ] . n ;
595
615
596
616
if ( currentParentElementIndex !== this . parentElementIndex ) {
@@ -620,7 +640,8 @@ class HyperaudioLite {
620
640
} else {
621
641
const indices = this . updateTranscriptVisualState ( this . currentTime ) ;
622
642
const index = indices . currentWordIndex ;
623
- if ( index > 0 ) {
643
+
644
+ if ( index > 0 && this . autoscroll ) {
624
645
this . scrollToParagraph ( indices . currentParentElementIndex , index ) ;
625
646
}
626
647
@@ -739,7 +760,7 @@ class HyperaudioLite {
739
760
}
740
761
this . wordArr [ index - 1 ] . n . parentNode . classList . add ( 'active' ) ;
741
762
}
742
-
763
+
743
764
const currentParentElementIndex = Array . from ( this . parentElements ) . findIndex ( el => el . classList . contains ( 'active' ) ) ;
744
765
745
766
return {
0 commit comments