Skip to content

Commit

Permalink
Extend player status check for add to playlist to iPad Safari (#5799)
Browse files Browse the repository at this point in the history
* Extend player status check for add to playlist to iPad Safari

* Add IS_MOBILE check back in
  • Loading branch information
Dananji authored Apr 23, 2024
1 parent 8373b84 commit 5471ec1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/views/media_objects/_add_to_playlist.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,11 @@ Unless required by applicable law or agreed to in writing, software distributed
let addToPlaylistBtn = document.getElementById('addToPlaylistBtn');
if(addToPlaylistBtn && addToPlaylistBtn.disabled) {
const USER_AGENT = window.navigator.userAgent;
// Identify both iPad and iPhone devices
const IS_MOBILE = (/Mobi/i).test(USER_AGENT);
const IS_IPHONE = (/iPhone/i).test(USER_AGENT);
const IS_TOUCH_ONLY = navigator.maxTouchPoints && navigator.maxTouchPoints > 2 && !window.matchMedia("(pointer: fine").matches;
// Identify browser is Safari
const IS_SAFARI = (/Safari/i).test(USER_AGENT);
/*
For iOS Safari, player.readyState() never gets to 4 until media playback is
Expand All @@ -215,7 +219,7 @@ Unless required by applicable law or agreed to in writing, software distributed
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() != '')
if(((IS_TOUCH_ONLY || IS_IPHONE || IS_MOBILE) && IS_SAFARI && player?.player.src() != '')
|| player?.player.readyState() === 4) {
addToPlaylistBtn.disabled = false;
}
Expand Down

0 comments on commit 5471ec1

Please sign in to comment.