I have built a Squarespace site using a template that has a unique masonry type gallery - https://wexley-demo.squarespace.com/ . This template was chosen almost exclusively because of this gallery layout, but otherwise has several drawbacks, and I have essentially rebuilt the site from scratch. I am not in developper mode, so keep in mind I have limited access to the code - I can only add code to the header, on the page (however, not in the case of the gallery), and in the footer but only sitewide as a code block. I am ideally looking for a solution to this problem that works with only adding code in the header.
The gallery that you'll see previewed at the URL above has an unfortunate problem in that the default action for clicking on a thumbnail is to open a lightbox of sorts - you cannot, as opposed to most Squarespace "Gallery" type pages, assign a hyperlink to each thumbnail. Note that you can set this "Clickthrough URL" attribute through the sqs panels, but by default, this will be ignored and only open a lightbox.
For our site, it is critical that these thumbnails send you to the projects page on click. To achieve this, the following script (found from another sqs user, ghostcat) is included in the header:
<script>
var currentPageBaseURL=window.location.href.split("?")[0];
Y.on("domready",function(e){
Y.io(currentPageBaseURL+"?page=1&format=json-pretty", {
on:{success: jsonLoaded}
});
function jsonLoaded(err,data){
try{
var jsonResponse = Y.JSON.parse(data.responseText);
var items=jsonResponse.items
Y.all("#thumbList .thumb, #galleryWrapper .slide").each(function(e){
var thumbId=this.getAttribute("data-slide-id");
for(var i=0;i<items.length;i++){
if(thumbId==items[i].id && items[i].clickthroughUrl){
this.setAttribute("data-clickthrough-url",items[i].clickthroughUrl).on("click",function(e){
e.preventDefault();
e.stopPropagation();
window.open(this.getAttribute("data-clickthrough-url"),'_self');
})
}
}
})
}catch(e){}
}
});
</script>
This code works well - according to the author (ghostcat), it "does an ajax load on the gallery json to get the clickthrough urls and then some DOM manipulation to change the thumb click event" - except that, it requires the website visitor to clear their cache if they have visited the website previously to work properly. So, if a visitor has come to the website project page previously and we added thumbnails since their last visit, these thumbnails will have their default action of opening a lightbox, and only the old thumbnails will work.
I have tried inserting this code into the footer to no avail. I have also tried uploading the script as a .js file, and calling it up on page load. After updating the gallery, I changed the scripts filename and called up a version with the new filename - this did not resolve the issue.
Strangely, the script is not being cached by either Chrome or Safari (on inspection of the resources loading), but clearing the cache before visiting the page always makes it function as intended.
Currently, I have a redirect approach in place where I add the date to the gallery versions URL (i.e. www.website.com/work -> www.website.com/work-041718) and setup a 301 redirect, that works, but appending the galleries URL with a date feels clunky.
Is there any modifications I could make the script / other tactic I can use to resolve this issue?
Happy to clarify in any way possible.
EDIT - I took another look at the inspector, and noticed that an XHR file is being cached. This 'file' contains all of the image attributes that I would set in the panel, including the Clickthrough URL.
It is also found at www.website.com/galery-page?page=1&format=json-pretty
This makes me think that this is the issue as the script is running the functions on this XHR URL.
Maybe this helps find a solution?