Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions __TEST__/hyperaudio-lite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,29 @@ test("setPlayHead updates currentTime and plays if playOnClick is true", () => {
expect(ht.myPlayer.play).toHaveBeenCalled();
});

test("setPlayHead tracks the clicked word when timestamps are duplicated (#269)", () => {
const spans = document.querySelectorAll("span[data-m]");
const lastWordInFirstParagraph = spans[4];
const firstWordInSecondParagraph = spans[5];
const originalTimestamp = lastWordInFirstParagraph.dataset.m;

lastWordInFirstParagraph.dataset.m = firstWordInSecondParagraph.dataset.m;
ht.wordArr = ht.createWordArray(spans);
ht.myPlayer = { setTime: jest.fn(), play: jest.fn(), paused: true };
ht.playOnClick = false;

ht.setPlayHead({ target: firstWordInSecondParagraph });

expect(lastWordInFirstParagraph.parentNode.classList.contains("active")).toBe(false);
expect(firstWordInSecondParagraph.parentNode.classList.contains("active")).toBe(true);
expect(ht.activeWordElement).toBe(firstWordInSecondParagraph);
expect(ht.activeParentElement).toBe(firstWordInSecondParagraph.parentNode);

lastWordInFirstParagraph.dataset.m = originalTimestamp;
ht.wordArr = ht.createWordArray(spans);
ht.clearActiveClasses();
});

test("preparePlayHead sets paused to false and calls checkPlayHead", () => {
ht.checkPlayHead = jest.fn();
ht.preparePlayHead();
Expand Down
8 changes: 8 additions & 0 deletions js/hyperaudio-lite.js
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,16 @@ class HyperaudioLite {
// the playback loop owns the active word; when paused, we explicitly mark
// the clicked word so the user sees what they clicked.
if (this.myPlayer.paused && target.dataset.m) {
if (this.activeWordElement && this.activeWordElement !== target) {
this.activeWordElement.classList.remove('active');
}
if (this.activeParentElement && this.activeParentElement !== target.parentNode) {
this.activeParentElement.classList.remove('active');
}
target.classList.add('active');
target.parentNode.classList.add('active');
this.activeWordElement = target;
this.activeParentElement = target.parentNode;
}

if (!isNaN(timeSecs)) {
Expand Down
8 changes: 8 additions & 0 deletions js/hyperaudio-lite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,16 @@ class HyperaudioLite {
// the playback loop owns the active word; when paused, we explicitly mark
// the clicked word so the user sees what they clicked.
if (this.myPlayer.paused && target.dataset.m) {
if (this.activeWordElement && this.activeWordElement !== target) {
this.activeWordElement.classList.remove('active');
}
if (this.activeParentElement && this.activeParentElement !== target.parentNode) {
this.activeParentElement.classList.remove('active');
}
target.classList.add('active');
target.parentNode.classList.add('active');
this.activeWordElement = target;
this.activeParentElement = target.parentNode;
}

if (!isNaN(timeSecs)) {
Expand Down
Loading