From a47da70e70887960d7ce0034f14db4a69c006aa0 Mon Sep 17 00:00:00 2001 From: Mark Boas Date: Mon, 16 Sep 2024 16:24:59 +0200 Subject: [PATCH 1/2] fix for scrolling issue --- js/hyperaudio-lite.js | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/js/hyperaudio-lite.js b/js/hyperaudio-lite.js index fbef82f..40ec0e6 100644 --- a/js/hyperaudio-lite.js +++ b/js/hyperaudio-lite.js @@ -1,5 +1,5 @@ /*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */ -/*! Version 2.3.1 */ +/*! Version 2.3.2 */ 'use strict'; @@ -305,9 +305,11 @@ class HyperaudioLite { this.setupTranscriptWords(); this.setupEventListeners(doubleClick, playOnClick); this.setupInitialPlayHead(); + this.setupAutoScroll(autoscroll); this.minimizedMode = minimizedMode; this.autoscroll = autoscroll; this.webMonetization = webMonetization; + this.scrollerContainer = this.transcript; } // Setup hash for transcript selection @@ -389,10 +391,31 @@ class HyperaudioLite { setupTranscriptWords() { const words = this.transcript.querySelectorAll('[data-m]'); this.wordArr = this.createWordArray(words); - this.parentTag = words[0].parentElement.tagName; + + // check for elements with data-m attributes that are not directly below
+ // these will contain

or similar that we can scroll to + + for (const word of words) { + let parentTagName = word.parentElement.tagName; + if (parentTagName !== "SECTION") { + this.parentTag = parentTagName; + break; + } + } + this.parentElements = this.transcript.getElementsByTagName(this.parentTag); } + setupAutoScroll(autoscroll) { + if (autoscroll) { + if (window.jQuery) { + this.scroller = window.jQuery.Velocity; + } else { + this.scroller = window.Velocity; + } + } + } + // Setup event listeners for interactions setupEventListeners(doubleClick, playOnClick) { this.minimizedMode = false; @@ -403,10 +426,6 @@ class HyperaudioLite { this.highlightedText = false; this.start = null; - if (this.autoscroll) { - this.scroller = window.Velocity || window.jQuery.Velocity; - } - const playHeadEvent = doubleClick ? 'dblclick' : 'click'; this.transcript.addEventListener(playHeadEvent, this.setPlayHead.bind(this), false); this.transcript.addEventListener(playHeadEvent, this.checkPlayHead.bind(this), false); @@ -418,7 +437,7 @@ class HyperaudioLite { if (!isNaN(parseFloat(this.start))) { this.highlightedText = true; let indices = this.updateTranscriptVisualState(this.start); - if (indices.currentWordIndex > 0) { + if (indices.currentWordIndex > 0 && this.autoscroll) { this.scrollToParagraph(indices.currentParentElementIndex, indices.currentWordIndex); } } @@ -591,6 +610,7 @@ class HyperaudioLite { // Scroll to the paragraph containing the current word scrollToParagraph(currentParentElementIndex, index) { + const scrollNode = this.wordArr[index - 1].n.closest('p') || this.wordArr[index - 1].n; if (currentParentElementIndex !== this.parentElementIndex) { @@ -620,7 +640,8 @@ class HyperaudioLite { } else { const indices = this.updateTranscriptVisualState(this.currentTime); const index = indices.currentWordIndex; - if (index > 0) { + + if (index > 0 && this.autoscroll) { this.scrollToParagraph(indices.currentParentElementIndex, index); } @@ -739,7 +760,7 @@ class HyperaudioLite { } this.wordArr[index - 1].n.parentNode.classList.add('active'); } - + const currentParentElementIndex = Array.from(this.parentElements).findIndex(el => el.classList.contains('active')); return { From 11f0fa40b7fbb2d12e8ab213dfc7ba6666efad34 Mon Sep 17 00:00:00 2001 From: Mark Boas Date: Mon, 16 Sep 2024 16:50:53 +0200 Subject: [PATCH 2/2] fix for this.scroller --- js/hyperaudio-lite.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/js/hyperaudio-lite.js b/js/hyperaudio-lite.js index 40ec0e6..e7e026b 100644 --- a/js/hyperaudio-lite.js +++ b/js/hyperaudio-lite.js @@ -408,10 +408,10 @@ class HyperaudioLite { setupAutoScroll(autoscroll) { if (autoscroll) { - if (window.jQuery) { - this.scroller = window.jQuery.Velocity; - } else { + if (window.Velocity) { this.scroller = window.Velocity; + } else if (window.jQuery && window.jQuery.Velocity) { + this.scroller = window.jQuery.Velocity; } } }