Skip to content

Commit

Permalink
Merge pull request #5796 from avalonmediasystem/v7.7.x
Browse files Browse the repository at this point in the history
Cherry-pick additional fix for v7.7.2
  • Loading branch information
cjcolvar authored Apr 19, 2024
2 parents 7899877 + cd8816a commit 59d6c8a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions app/views/media_objects/_add_to_playlist.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,23 @@ Unless required by applicable law or agreed to in writing, software distributed
function enableAddToPlaylist() {
let player = document.getElementById('iiif-media-player');
let addToPlaylistBtn = document.getElementById('addToPlaylistBtn');
if(addToPlaylistBtn && addToPlaylistBtn.disabled && player?.player.readyState() === 4) {
addToPlaylistBtn.disabled = false;
if(addToPlaylistBtn && addToPlaylistBtn.disabled) {
const USER_AGENT = window.navigator.userAgent;
const IS_MOBILE = (/Mobi/i).test(USER_AGENT);
const IS_SAFARI = (/Safari/i).test(USER_AGENT);
/*
For iOS Safari, player.readyState() never gets to 4 until media playback is
started. Therefore, use player.src() to check whether there's a playable media
loaded into the player instead of player.readyState().
Keep the player.readyState() === 4 check for desktop browsers, because without
that check the add to playlist form populates NaN values for time fields when user
clicks the 'Add to Playlist' button immediately on page load, which does not
happen in mobile context.
*/
if((IS_MOBILE && IS_SAFARI && player?.player.src() != '')
|| player?.player.readyState() === 4) {
addToPlaylistBtn.disabled = false;
}
}
if(!listenersAdded) {
// Add 'Add new playlist' option to dropdown
Expand Down

0 comments on commit 59d6c8a

Please sign in to comment.