-
Notifications
You must be signed in to change notification settings - Fork 805
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Slideshow block: Ensure max-width is defined when within the Stack bl…
…ock (#40383)
- Loading branch information
1 parent
cab5e22
commit b4e6eac
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/fix-slideshow-width-in-stack-block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: bugfix | ||
|
||
Slideshow block: Fix block display when added within a Stack block. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
projects/plugins/jetpack/extensions/blocks/slideshow/utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export default function applyPaddingForStackBlock() { | ||
// Helper function to apply styles | ||
const applyPaddingStyles = ( doc, isIframe ) => { | ||
const parentElement = doc.querySelector( '.wp-site-blocks' ); | ||
if ( ! parentElement ) return; | ||
|
||
const { paddingLeft, paddingRight } = window.getComputedStyle( parentElement ); | ||
const totalPadding = parseFloat( paddingLeft ) + parseFloat( paddingRight ); | ||
|
||
const targetElements = doc.querySelectorAll( | ||
isIframe | ||
? '.wp-block-group.is-vertical:not(.is-layout-constrained) .wp-block-jetpack-slideshow' | ||
: '.wp-block-group.is-vertical:not(.is-layout-constrained) .wp-block-jetpack-slideshow:not(.entry-content .wp-block-jetpack-slideshow)' | ||
); | ||
|
||
targetElements.forEach( element => { | ||
element.style.maxWidth = `calc(100vw - ${ totalPadding }px)`; | ||
} ); | ||
}; | ||
|
||
// Apply styles to the main document | ||
applyPaddingStyles( document, false ); | ||
|
||
// Find all iframes and apply styles to their content | ||
const iframes = document.querySelectorAll( 'iframe' ); | ||
iframes.forEach( iframe => { | ||
const iframeDoc = iframe.contentDocument; | ||
|
||
// Ensure iframe's parent is #editor before applying styles | ||
const iframeParent = iframe.closest( '#editor' ); | ||
if ( iframeDoc && iframeParent ) { | ||
const targetElements = iframeDoc.querySelectorAll( | ||
'.wp-block-group.is-vertical:not(.is-layout-constrained) .wp-block-jetpack-slideshow' | ||
); | ||
targetElements.forEach( element => { | ||
element.style.maxWidth = 'inherit'; // Explicit style for this case | ||
} ); | ||
} else if ( iframeDoc ) { | ||
// If the iframe is not in the editor, apply the styles to the iframe itself | ||
applyPaddingStyles( iframeDoc, true ); | ||
} | ||
} ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters