Skip to content

Fix modal event handling for ACF block version 3#156

Open
adambichler wants to merge 1 commit into
joppuyo:masterfrom
adambichler:crop-fix-block-version-3
Open

Fix modal event handling for ACF block version 3#156
adambichler wants to merge 1 commit into
joppuyo:masterfrom
adambichler:crop-fix-block-version-3

Conversation

@adambichler

Copy link
Copy Markdown

Restructured the event listener attachment to fix compatibility issues with blockVersion3:

  • Created new attachCropModalEvents() method that attaches event listeners directly to modal buttons after they're created in the DOM
  • Moved all button event logic from initialize() into this new method
  • Called attachCropModalEvents() in openModal() after modal DOM is rendered
  • Added proper cleanup in closeModal() to remove event listeners and prevent memory leaks
  • Added null check for cropper in closeModal()

Benefits:

  • More reliable - listeners attached when needed, not during init
  • Better memory management with proper cleanup
  • Maintains backward compatibility
  • Uses namespaced event handlers (.aiarc) for clean unbinding

Notice:

  • Tested within repeater fields, flexible content fields and simple field setup.
  • Tested backward compatibility when not using blockVersion: 3

Fixes #154

Restructured the event listener attachment to fix compatibility issues:

- Created new attachCropModalEvents() method that attaches event listeners
  directly to modal buttons after they're created in the DOM
- Moved all button event logic from initialize() into this new method
- Called attachCropModalEvents() in openModal() after modal DOM is rendered
- Added proper cleanup in closeModal() to remove event listeners and
  prevent memory leaks
- Added null check for cropper in closeModal()

Benefits:
- More reliable - listeners attached when needed, not during init
- Better memory management with proper cleanup
- Maintains backward compatibility
- Uses namespaced event handlers (.aiarc) for clean unbinding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ACF BlockVersion 3 compatibility

1 participant