Skip to content

Commit 53ad003

Browse files
committed
Make YouTube embeds responsive and honor size attrs
Extract width/height attributes for YouTube blocks and wrap iframe in a responsive container with max-width styling. Update Gutenberg renderer to emit responsive classes and inline size attributes. Regenerate built CSS/JS and update related block components (document FileViewer, YouTube edit/save/style) and front-end assets. Also include a minor provider update (Flourish) and vendor changes. Built/static assets updated accordingly.
1 parent 1f25665 commit 53ad003

14 files changed

Lines changed: 111 additions & 8 deletions

File tree

EmbedPress/Gutenberg/EmbedPressBlockRenderer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,15 +1220,20 @@ public static function render_youtube_block($attributes, $content = '', $block =
12201220
// Build alignment class
12211221
$align_class = 'align' . $align;
12221222

1223+
// Extract width/height from attributes
1224+
$width = isset($attributes['width']) ? intval($attributes['width']) : 640;
1225+
$height = isset($attributes['height']) ? intval($attributes['height']) : 360;
1226+
12231227
// Generate YouTube block HTML
12241228
ob_start();
12251229
?>
1226-
<div class="ose-youtube wp-block-embed-youtube ose-youtube-single-video <?php echo esc_attr($align_class); ?>">
1230+
<div class="ose-youtube responsive wp-block-embed-youtube ose-youtube-single-video <?php echo esc_attr($align_class); ?>" style="max-width: 100%;">
12271231
<iframe src="<?php echo esc_url($processed_iframe_url); ?>"
12281232
allowtransparency="true"
12291233
allowfullscreen="true"
12301234
frameborder="0"
1231-
width="640" height="360">
1235+
style="max-width: 100%;"
1236+
width="<?php echo esc_attr($width); ?>" height="<?php echo esc_attr($height); ?>">
12321237
</iframe>
12331238
</div>
12341239
<?php

assets/css/blocks.build.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/css/embedpress.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@
174174
height: 100%;
175175
}
176176

177+
.ose-flourish iframe {
178+
border: none;
179+
}
180+
177181
.ose-deviantart img, .ose-deviantart a, .ose-deviantart div {
178182
width: 100%;
179183
height: 100%;
@@ -1604,6 +1608,7 @@ a.ep-social-icon.twitter:focus-visible {
16041608
right: 2px;
16051609
bottom: 8px;
16061610
opacity: 0;
1611+
pointer-events: none;
16071612
}
16081613

16091614
.cui-toolbar-button-right {
@@ -1671,6 +1676,18 @@ a.ep-social-icon.twitter:focus-visible {
16711676
height: 100% !important;
16721677
}
16731678

1679+
.ep-file-download-option-masked.fullscreen-enabled {
1680+
overflow: visible;
1681+
}
1682+
1683+
.ep-file-download-option-masked.fullscreen-enabled .embed-download-disabled {
1684+
display: none;
1685+
}
1686+
1687+
.ep-file-download-option-masked.fullscreen-enabled::after {
1688+
display: none;
1689+
}
1690+
16741691
.embedpress-document-embed {
16751692
position: relative;
16761693
}
@@ -1718,6 +1735,7 @@ a.ep-social-icon.twitter:focus-visible {
17181735
bottom: 0;
17191736
content: '';
17201737
left: 0;
1738+
pointer-events: none;
17211739
}
17221740

17231741
.ep-file-download-option-masked.ep-file-docx::after {

assets/js/blocks.build.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/front.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,24 @@ jQuery(window).on("elementor/frontend/init", function () {
11841184
elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_document.default", filterableGalleryHandler);
11851185
elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", adsHandler);
11861186
elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", epGlobals.handlePosterImageLoad);
1187+
1188+
// Re-initialize custom player when Elementor widget becomes ready
1189+
var customPlayerHandler = function ($scope, $) {
1190+
if (typeof initPlayer === 'function') {
1191+
var wrappers = $scope[0].querySelectorAll('.ep-embed-content-wraper');
1192+
wrappers.forEach(function (wrapper) {
1193+
if (!wrapper.classList.contains('plyr-initialized')) {
1194+
initPlayer(wrapper);
1195+
}
1196+
});
1197+
}
1198+
1199+
// Re-initialize lazy loaded iframes for this widget
1200+
if (typeof window.epReinitLazyLoad === 'function') {
1201+
window.epReinitLazyLoad();
1202+
}
1203+
};
1204+
elementorFrontend.hooks.addAction("frontend/element_ready/embedpres_elementor.default", customPlayerHandler);
11871205
});
11881206

11891207

src/Blocks/document/src/components/FileViewer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const FileViewer = ({
1616
title={title}
1717
src={sanitizeUrl(url)}
1818
style={{ height: height + 'px', width: width + unitoption }}
19+
allowFullScreen
1920
onLoad={() => setFetching(false)}
2021
onMouseUp={() => setShowOverlay(false)}
2122
/>

src/Blocks/document/src/editor.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
right: 2px;
7272
bottom: 8px;
7373
opacity: 0;
74+
pointer-events: none;
7475
}
7576

7677
.cui-toolbar-button-right {

src/Blocks/document/src/editor.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
right: 2px;
6969
bottom: 8px;
7070
opacity: 0;
71+
pointer-events: none;
7172
}
7273

7374
.cui-toolbar-button-right {

src/Blocks/youtube/src/components/edit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default function YouTubeEdit({ attributes, setAttributes, isSelected }) {
124124
return (
125125
<div {...blockProps}>
126126
<Inspector attributes={attributes} setAttributes={setAttributes} />
127-
<div className={`embedpress-youtube-embed ${width_class}`} style={{ width: `${width}px`, height: `${height}px` }}>
127+
<div className={`embedpress-youtube-embed ${width_class}`} style={{ maxWidth: '100%', width: `${width}px`, height: `${height}px` }}>
128128
{fetching ? <EmbedLoading /> : null}
129129

130130
<Iframe

src/Blocks/youtube/src/components/save.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const save = ({ attributes }) => {
3131
<div id={`ep-gutenberg-content-${_md5ClientId}`} className="ep-gutenberg-content">
3232
<div
3333
className={`embedpress-youtube-embed ${width_class}`}
34-
style={{ width: `${width}px`, height: `${height}px` }}
34+
style={{ maxWidth: '100%', width: `${width}px`, height: `${height}px` }}
3535
data-embed-type="YouTube"
3636
>
3737
{shouldLazyLoad ? (

0 commit comments

Comments
 (0)