fix: leerer elementor-video-platzhalter wenn URL nicht auslesbar (v1.4.1)

Wenn ein Elementor-video per JS gebaut wird und im DOM weder URL noch
Thumbnail steht (nur {"video_type":"youtube"}), konnte mein handler keinen
platzhalter bauen -> Elementor baut nichts (API blockiert) -> leere box.

Fallback: dienst ueber den video_type erkennen und trotzdem einen
einwilligungs-platzhalter zeigen. Da keine embed-URL bekannt ist, gibt dessen
button die einwilligung und laedt die seite neu - danach rendert Elementor das
video normal (scripts sind dann freigegeben). "Einmal laden" entfaellt dort.

+ version 1.4.1 (assets cache-busting fuer die JS-aenderung).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
s4luorth
2026-06-08 12:58:28 +02:00
parent 2361228c14
commit 1ce9f8121b
2 changed files with 35 additions and 7 deletions

View File

@@ -93,6 +93,15 @@
const wrapper = btn.closest( '.cb-blocker' );
// Placeholder without its own embed URL (e.g. an Elementor widget we
// couldn't read the URL from): persist consent and reload so the
// original embed renders normally.
if ( wrapper && wrapper.getAttribute( 'data-cb-reload' ) === '1' ) {
grantConsent( serviceId );
window.location.reload();
return;
}
// "Remember" checkbox (default checked): persist consent only when
// ticked; otherwise load this embed once without storing consent.
const remember = wrapper
@@ -315,19 +324,38 @@
// catching a rendered iframe) → leave it.
if ( container.querySelector( '.cb-blocker' ) ) return;
const raw = videoUrlForWidget( widget );
if ( ! raw ) return;
const raw = videoUrlForWidget( widget );
const embed = raw ? toEmbedUrl( raw ) : '';
let svc = raw ? ( findService( raw ) || findService( embed ) ) : null;
const embed = toEmbedUrl( raw );
const svc = findService( raw ) || findService( embed );
// Fallback: no URL in the DOM (Elementor only kept {"video_type":"…"}).
// Identify the service by the video type so we can still show consent.
if ( ! svc ) {
const vt = ( widget.getAttribute( 'data-settings' ) || '' )
.match( /"video_type"\s*:\s*"(youtube|vimeo|dailymotion)"/i );
if ( vt ) {
svc = findService( vt[ 1 ] + '.com' );
}
}
if ( ! svc ) return;
if ( hasConsent( svc.id ) ) return; // consented → let Elementor build it
// Neutralise Elementor so it won't build the player / load the overlay.
widget.removeAttribute( 'data-settings' );
const placeholder = buildPlaceholder( svc, embed, {} );
// No embed URL → we can't build the iframe ourselves. Make the button
// grant consent and reload; Elementor then renders the video normally
// (scripts are released after consent). Drop the "load once" option.
if ( ! embed ) {
placeholder.setAttribute( 'data-cb-reload', '1' );
const remember = placeholder.querySelector( '.cb-blocker__remember' );
if ( remember ) remember.remove();
}
container.innerHTML = '';
container.appendChild( buildPlaceholder( svc, embed, {} ) );
container.appendChild( placeholder );
} );
}