Putting this attribute here means if the user is not logged in, you will get an error on this line
` totalHits = mainGallery.getAttribute("data-total-hits"),`

EIther use jQuery or do a check