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 reinitialize callback for ajax loaded page content #871

Open
lukedagnall opened this issue Jan 20, 2021 · 3 comments
Open

Add reinitialize callback for ajax loaded page content #871

lukedagnall opened this issue Jan 20, 2021 · 3 comments

Comments

@lukedagnall
Copy link

No callback function to reinitialize the plugin if loaded in via ajax (e.g. barba.js) causes the page to reload on submission, please add or advise how this can be achieved. Cheers!

@jpowersdev
Copy link
Contributor

Hey @lukedagnall,

Just to clarify - you are using barba.js to perform a transition when the form is submitted, but after the transition the page reloads?

Can you provide an example page?

@lukedagnall
Copy link
Author

Hey @jpowersdev

Not quite - I have the plugin installed and working correctly if the user performs the initial load on the page where the form is embedded. However, if a user loads the site from a page that does not contain the form and then navigates to a page that does, the form will trigger a refresh on submission, i've attempted to reload the scripts on page enter from barba but it doesn't get it working correctly. So I was looking for some sort of initialize function to call.

Here's the example site (scroll down towards the footer and you will see a newsletter section)

Cheers

@jpowersdev
Copy link
Contributor

I see what you're saying. The two scripts our plugin provides are not loading when using barba to transition to a page containing the form.

The easy solution would be to inject the two script tags on pages that contain the form. You should probably also check to make sure that window.Yikes_Mailchimp_Ajax isn't already defined.

I'd probably drop a function in my js bundle that manages adding the scripts and just trigger it after checking the window.location.pathname against a predefined list.

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

No branches or pull requests

2 participants