SquareSpace – An update

Further to my previous post I've been working with Chris to find a solution to display file names as captions in SquareSpace. We came up with a solution and have posted it at answers.squarespace.com, but here it is in full:

Basically it's a bit of Javascript that extracts the filename from the href of the thumbnail and renders it in a div underneath. You need to insert this at the bottom of your gallery page as a code block:

<script>

function getElementsByClass(searchClass,node,tag) {
var classElements = new Array();
if ( node == null ) node = document;
if ( tag == null ) tag = '*';
var els = node.getElementsByTagName(tag);
var elsLen = els.length; var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
for (i = 0, j = 0; i < elsLen; i++) { if ( pattern.test(els[i].className) ) { classElements[j] = els[i]; j++; } } return classElements; }

theslides = getElementsByClass("image-slide-anchor content-fit");

for(i=0; i < theslides.length; i++) { theimage = theslides[i]; where = theimage.getAttribute('href').lastIndexOf("/") + 1; what = theimage.getAttribute('href').slice(where,theimage.getAttribute('href').len); theimage.innerHTML = theimage.innerHTML + ' ' + what + '';
}

</script>

The resulting gallery page should look like this:

test

comments / improvements welcome