mirror of
https://github.com/tabler/tabler.git
synced 2026-08-07 03:42:27 +04:00
575d68572f
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
39 lines
934 B
Plaintext
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>
|
|
)
|
|
}
|