Skip to content

Commit

Permalink
Improve dropcap resizing
Browse files Browse the repository at this point in the history
  • Loading branch information
razwan committed May 18, 2022
1 parent 28d9061 commit 94a5f00
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/blocks/supernova/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ const debouncedResizeAllDropcaps = debounce( resizeAllDropcaps, 100 );
domReady( resizeAllDropcaps );

window.addEventListener( 'resize', debouncedResizeAllDropcaps );
window.addEventListener( 'nb:layout', resizeAllDropcaps );
4 changes: 4 additions & 0 deletions packages/collection/src/frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ const handleParametricGrid = ( $grid, $block, attributes ) => {
}

const handleGrids = ( selector ) => {

$( selector ).each( function( i, grid ) {
const $grid = $( grid );
const $block = $grid.closest( '[data-layout-style]' );
Expand All @@ -210,4 +211,7 @@ const handleGrids = ( selector ) => {
handleMasonryGrid( $grid, $block, attributes );
}
} );

const resize = new CustomEvent( 'nb:layout' );
window.dispatchEvent( resize );
}
4 changes: 2 additions & 2 deletions packages/utils/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,10 @@ export const resizeDropcap = dropcap => {
const wrapper = dropcap.parentElement;

const dropcapWidth = dropcap.offsetWidth;
const wrapperWidth = wrapper.offsetWidth;
const wrapperWidth = wrapper.offsetWidth * 0.9;
const widthRatio = wrapperWidth / dropcapWidth;
const dropcapHeight = dropcap.offsetHeight;
const wrapperHeight = wrapper.offsetHeight;
const wrapperHeight = wrapper.offsetHeight * 0.9;
const heightRatio = wrapperHeight / dropcapHeight;
const ratio = Math.min( widthRatio, heightRatio );

Expand Down

0 comments on commit 94a5f00

Please sign in to comment.