Skip to content
Merged

Dev #2996

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
80 changes: 6 additions & 74 deletions resources/views/layout/video-player.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,83 +20,15 @@ class="block bg-[#FFD700] hover:bg-[#F95C22] rounded-full p-4 duration-300">
@php
preg_match('/(?:youtube\.com\/(?:[^\/]+\/.+\/|(?:v|e(?:mbed)?)\/|.*[?&]v=)|youtu\.be\/)([^"&?\/\s]{11})/', $src, $matches);
$videoId = $matches[1] ?? '';
// Use privacy-enhanced YouTube URL
$privacyEnhancedUrl = "https://www.youtube-nocookie.com/embed/{$videoId}?rel=0&modestbranding=1";
@endphp

<div id="youtube-container-{{ $id }}" class="w-full h-full">
<!-- This will be replaced when video loads -->
</div>

<script>
(function() {
let videoLoaded{{ str_replace('-', '_', $id) }} = false;

function checkConsent{{ str_replace('-', '_', $id) }}() {
if (typeof CookieScript !== 'undefined' && CookieScript.instance) {
try {
const state = CookieScript.instance.currentState();
return state && (state.targeting === true || state.marketing === true);
} catch (e) {
return false;
}
}
return false;
}

function loadVideo{{ str_replace('-', '_', $id) }}() {
if (videoLoaded{{ str_replace('-', '_', $id) }}) return;

const container = document.getElementById('youtube-container-{{ $id }}');
if (container) {
container.innerHTML = `
<iframe class="w-full h-full"
src="{{ $privacyEnhancedUrl }}"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
`;
videoLoaded{{ str_replace('-', '_', $id) }} = true;
}
}

function showPlaceholder{{ str_replace('-', '_', $id) }}() {
const container = document.getElementById('youtube-container-{{ $id }}');
if (container && !videoLoaded{{ str_replace('-', '_', $id) }}) {
container.innerHTML = `
<div class="flex flex-col justify-center items-center p-6 w-full h-full bg-gray-100 rounded-lg">
<svg class="mb-4 w-20 h-20" viewBox="0 0 68 48" fill="#FF0000">
<path d="M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.55 C3.97,2.33,2.27,4.81,1.48,7.74C0.06,13.05,0,24,0,24s0.06,10.95,1.48,16.26c0.78,2.93,2.49,5.41,5.42,6.19 C12.21,47.87,34,48,34,48s21.79-0.13,27.1-1.55c2.93-0.78,4.64-3.26,5.42-6.19C67.94,34.95,68,24,68,24S67.94,13.05,66.52,7.74z"/>
<path fill="#FFFFFF" d="M45,24L27,14v20L45,24z"/>
</svg>
<p class="mb-4 text-center text-gray-700">This video requires consent to load as it will share data with YouTube/Google.</p>
<button onclick="loadVideo{{ str_replace('-', '_', $id) }}()"
class="bg-[#f95c22] text-white px-6 py-3 rounded-lg hover:bg-[#e54c12] transition font-semibold">
Load Video Anyway
</button>
</div>
`;
}
}

// Check when modal opens
const showButton = document.querySelector('[data-targetId="video-modal-{{ $id }}"]');
if (showButton) {
showButton.addEventListener('click', function() {
setTimeout(function() {
if (checkConsent{{ str_replace('-', '_', $id) }}()) {
loadVideo{{ str_replace('-', '_', $id) }}();
} else {
showPlaceholder{{ str_replace('-', '_', $id) }}();
}
}, 100);
});
}

// Make functions globally available
window.loadVideo{{ str_replace('-', '_', $id) }} = loadVideo{{ str_replace('-', '_', $id) }};
})();
</script>
<!-- Always load the iframe directly for simplicity -->
<iframe class="w-full h-full"
src="{{ $privacyEnhancedUrl }}"
frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
allowfullscreen></iframe>
@else
<video id="video" class="max-w-full max-h-full" controls src="{{ $src }}">
<source src="{{ $src }}" type="video/mp4">
Expand Down
Loading