Jump to content

Eventlisteners Lost when added to Squarespace (custom js)

Recommended Posts

I've been working on custom code to programmatically populate a list of works page from a Firestore database. In VSCode/localhost everything works perfectly, but I am trying to add event listeners to every element in a class (downloadScore) and when the code is running on squarespace those event listeners don't work.

As other event listeners I create in a similar manner do work, and because it works in localhost (without Squarespace page around it), I am thinking it might be an interaction between my code and the squarespace code. 

I'm wondering if anybody else has hit this problem or a similar one when injecting event listeners?

My page is a 7.0 Wells site, there's no option to turn off AJAX in styles, and I have tried using a script I found on the forum to turn that off too, it seemed to make no difference. 

Update: I solved the problem myself. It was a combination of two things - I needed to chain a then to the promise made by the Firestore function to ensure the eventlisteners didn't run too early, and there was an undefined variable (actually probably caused by another bug in my code...) breaking the Firestore promise early. I think...not an expert at all....but hoping this could be helpful to nudge anybody else in the righr direction.

 

Edited by sebastianadams
Solved myself
Link to comment
12 hours ago, sebastianadams said:

I've been working on custom code to programmatically populate a list of works page from a Firestore database. In VSCode/localhost everything works perfectly, but I am trying to add event listeners to every element in a class (downloadScore) and when the code is running on squarespace those event listeners don't work.

As other event listeners I create in a similar manner do work, and because it works in localhost (without Squarespace page around it), I am thinking it might be an interaction between my code and the squarespace code. 

I'm wondering if anybody else has hit this problem or a similar one when injecting event listeners?

My page is a 7.0 Wells site, there's no option to turn off AJAX in styles, and I have tried using a script I found on the forum to turn that off too, it seemed to make no difference. 

Update: I solved the problem myself. It was a combination of two things - I needed to chain a then to the promise made by the Firestore function to ensure the eventlisteners didn't run too early, and there was an undefined variable (actually probably caused by another bug in my code...) breaking the Firestore promise early. I think...not an expert at all....but hoping this could be helpful to nudge anybody else in the righr direction.

 

It should be better if you can share your site with the protected password so we can take a look

Greeting, it's BeyondSpace, I am Squarespace dev focus on provide solutions to enhance feature that squarespace.com can't provide.
Feel free to check my current Squarespace Plugins Developement: Enable Pinch/Zoom on lightbox, Delivery Date Picker, Lightbox Studio plugin
If you find my answer fit your need, let's leave a like or upvote so others with the same issue can find their solution. Thank you

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.