1
0
mirror of https://github.com/tabler/tabler.git synced 2026-08-07 03:42:27 +04:00
Files
tabler/shared/ui/InlinePlayer.astro
2026-08-03 00:55:32 +02:00

39 lines
934 B
Plaintext

---
// Renders nothing unless both id and embedId are provided.
import CaptureScript from '../components/CaptureScript.astro';
interface Props {
id?: string;
type?: string;
embedId?: string | number;
}
const { id, type = 'youtube', embedId } = Astro.props;
const enabled = Boolean(id && embedId);
const playerId = `player-${id}`;
const playerSelector = `#player-${id}`;
---
{
enabled && (
<div id={playerId} data-plyr-provider={type} data-plyr-embed-id={embedId} />
)
}
{
enabled && (
<CaptureScript>
<!-- BEGIN PLAYER -->
<script define:vars={{ playerId, playerSelector }}>
window.tabler_player ??= {};
function initPlayer() {
window.Plyr && (window.tabler_player[playerId] = new Plyr(playerSelector));
}
document.readyState !== 'loading' ? initPlayer() : document.addEventListener('DOMContentLoaded', initPlayer, { once: true });
</script>
<!-- END PLAYER -->
</CaptureScript>
)
}