Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image block: Remove unnecessary variables on expand on click implementation #63290

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 4 additions & 22 deletions packages/block-library/src/image/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,6 @@ let isTouching = false;
*/
let lastTouchTime = 0;

/**
* Stores the image reference of the currently opened lightbox.
*
* @type {HTMLElement}
*/
let imageRef;

/**
* Stores the button reference of the currently opened lightbox.
*
* @type {HTMLElement}
*/
let buttonRef;

const { state, actions, callbacks } = store(
'core/image',
{
Expand Down Expand Up @@ -79,8 +65,6 @@ const { state, actions, callbacks } = store(

// Moves the information of the expaned image to the state.
ctx.currentSrc = ctx.imageRef.currentSrc;
imageRef = ctx.imageRef;
buttonRef = ctx.buttonRef;
state.currentImage = ctx;
state.overlayEnabled = true;

Expand All @@ -98,14 +82,12 @@ const { state, actions, callbacks } = store(
// Delays before changing the focus. Otherwise the focus ring will
// appear on Firefox before the image has finished animating, which
// looks broken.
buttonRef.focus( {
state.currentImage.buttonRef.focus( {
preventScroll: true,
} );

// Resets the current image to mark the overlay as closed.
state.currentImage = {};
imageRef = null;
buttonRef = null;
}, 450 );

// Starts the overlay closing animation. The showClosingAnimation
Expand Down Expand Up @@ -174,7 +156,7 @@ const { state, actions, callbacks } = store(
},
callbacks: {
setOverlayStyles() {
if ( ! imageRef ) {
if ( ! state.currentImage.imageRef ) {
return;
}

Expand All @@ -183,9 +165,9 @@ const { state, actions, callbacks } = store(
naturalHeight,
offsetWidth: originalWidth,
offsetHeight: originalHeight,
} = imageRef;
} = state.currentImage.imageRef;
let { x: screenPosX, y: screenPosY } =
imageRef.getBoundingClientRect();
state.currentImage.imageRef.getBoundingClientRect();

// Natural ratio of the image clicked to open the lightbox.
const naturalRatio = naturalWidth / naturalHeight;
Expand Down
Loading