fix: YouTube-Elementor-widget zeigt video auch nach reload (v1.4.7)

Nach reload mit bereits erteilter einwilligung blieb das e-youtube-base-video
leer: ich kehrte frueh zurueck und ueberliess es Elementors eigenem render
(unzuverlaessig). Die anderen blocker haben einen server-platzhalter, den
loadPreConsented direkt laedt - das JS-gebaute YouTube-element nicht.

Jetzt verwalte ich das widget mit embed-URL komplett selbst:
- nicht eingewilligt -> platzhalter (eingeklappt, kein weissraum)
- eingewilligt (auch nach reload) -> iframe wird sofort direkt gebaut (16:9),
  unabhaengig von Elementor/iframe_api.
Reload-fallback nur noch ohne URL.

+ version 1.4.7.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
s4luorth
2026-06-08 13:46:17 +02:00
parent 6c034ed714
commit 3c93027253
2 changed files with 26 additions and 19 deletions

View File

@@ -415,28 +415,35 @@
}
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' );
// With an embed URL we build the iframe ourselves on consent (reliable,
// independent of Elementor/iframe_api). The iframe gets a responsive
// 16:9 aspect so it loads full-width at its original proportions.
// Without a URL we fall back to reloading so Elementor renders it.
const placeholder = buildPlaceholder( svc, embed, {} );
if ( embed ) {
placeholder.dataset.cbAspect = '16 / 9';
} else {
placeholder.setAttribute( 'data-cb-reload', '1' );
const remember = placeholder.querySelector( '.cb-blocker__remember' );
if ( remember ) remember.remove();
// We fully manage this widget — independent of Elementor's own JS
// build (which is unreliable and needs the blocked iframe_api).
// This also means it works the same on a fresh load AND after a
// reload when consent is already stored.
widget.removeAttribute( 'data-settings' );
container.innerHTML = '';
const placeholder = buildPlaceholder( svc, embed, {} );
placeholder.dataset.cbAspect = '16 / 9'; // responsive, original proportions
container.appendChild( placeholder );
if ( hasConsent( svc.id ) ) {
loadContent( placeholder ); // already consented → show the video now
} else {
collapseAncestors( placeholder ); // no whitespace while blocked
}
return;
}
// No URL found in the DOM → we can't build the iframe ourselves. Fall
// back to a reload so Elementor renders the player. If already
// consented, leave the widget untouched for Elementor.
if ( hasConsent( svc.id ) ) return;
widget.removeAttribute( 'data-settings' );
container.innerHTML = '';
const placeholder = buildPlaceholder( svc, embed, {} );
placeholder.setAttribute( 'data-cb-reload', '1' );
const remember = placeholder.querySelector( '.cb-blocker__remember' );
if ( remember ) remember.remove();
container.appendChild( placeholder );
// Collapse the wrapper's reserved aspect height so there is no
// whitespace while the (small) placeholder is shown.
collapseAncestors( placeholder );
} );
}