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

Add ajax:merge and ajax:merged events #62

Merged
merged 4 commits into from
Mar 2, 2024
Merged

Add ajax:merge and ajax:merged events #62

merged 4 commits into from
Mar 2, 2024

Conversation

imacrayon
Copy link
Owner

This PR introduces two new events to the AJAX request lifecycle:

ajax:merge: Fired when new content is being merged into a target:

window.addEventListener('ajax:merge', (event) => {
  // Override the merge
  event.preventDefault()

  // Do stuff with the target, response, or content
  // event.target.id
  // event.detail.response.status
  // event.detail.content.querySelector(...)
  // You can even change the content being merged
  event.detail.content.innerHTML = '<p>This is kind of crazy</p>'
   
  // Complete the merge
  event.detail.merge()
})

ajax:merged: Fired after a target has been merged:

window.addEventListener('ajax:merged', (event) => {
  alert(`Target #${event.target.id} has been changed!`)
})

Resolves #55

@imacrayon imacrayon merged commit a07b81e into v0.5 Mar 2, 2024
1 check passed
@imacrayon imacrayon deleted the merge-event branch March 3, 2024 15:10
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.

None yet

1 participant