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
11 changes: 3 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion src/visual/songSliderElements.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ let SongSliderElements = (function() {
*/
if (playlist == null && song == null) {
mainSongSliders[i].value = location;
if (window.Event) {
mainSongSliders[i].dispatchEvent(new Event("change"));
}
}
}
}
Expand Down Expand Up @@ -105,6 +108,9 @@ let SongSliderElements = (function() {
*/
if (playlistAttribute == playlist && songAttribute == null) {
playlistSongSliders[i].value = location;
if (window.Event) {
playlistSongSliders[i].dispatchEvent(new Event("change"));
}
}
}
}
Expand Down Expand Up @@ -155,6 +161,9 @@ let SongSliderElements = (function() {
*/
if (playlistAttribute == null && songAttribute == songIndex) {
songSliders[i].value = location;
if (window.Event) {
songSliders[i].dispatchEvent(new Event("change"));
}
}
}
}
Expand Down Expand Up @@ -195,6 +204,9 @@ let SongSliderElements = (function() {
*/
for (let i = 0; i < songInPlaylistSliders.length; i++) {
songInPlaylistSliders[i].value = location;
if (window.Event) {
songInPlaylistSliders[i].dispatchEvent(new Event("change"));
}
}
}

Expand All @@ -213,6 +225,9 @@ let SongSliderElements = (function() {
*/
for (let i = 0; i < songSliders.length; i++) {
songSliders[i].value = 0;
if (window.Event) {
songSliders[i].dispatchEvent(new Event("change"));
}
}
}

Expand All @@ -225,7 +240,7 @@ let SongSliderElements = (function() {
syncPlaylist: syncPlaylist,
syncSong: syncSong,
syncSongInPlaylist: syncSongInPlaylist,
resetElements: resetElements
resetElements: resetElements,
};
})();

Expand Down
23 changes: 23 additions & 0 deletions tests/visual/songSliderElements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,26 @@ test("AmplitudeJS Song Slider Elements adjust current Time For Song", () => {
);
expect(document.getElementById("individual-song-slider").value).toBe("45");
});

test("AmplitudeJS Song Slider Elements trigger change event when value changed", () => {
Amplitude.playSongAtIndex(2);

const songSliderEl = document.getElementById("global-song-slider");

let onChangeCalled = false;
function onChangeCallback() {
onChangeCalled = true;
}
songSliderEl.addEventListener("change", onChangeCallback);
config.audio.currentTime = 45;
SongSliderElements.sync(
config.audio.currentTime,
config.active_playlist,
config.active_playlist != "" && config.active_playlist != null
? config.playlists[config.active_playlist].active_index
: config.active_index
);

expect(document.getElementById("individual-song-slider").value).toBe("45");
expect(onChangeCalled).toBe(true);
});