0

i'm working with squarespace developer mode, i create some javascript code to get my blog articles or events, the problem i have is that when i use ajax call to get my events to display them in a page i've created, the data is loaded correctly except blocks having audios and videos, i had the same issue with images, but SQS gives a solution for images :

var images = document.querySelectorAll('img[data-src]' ); for (var i = 0; i < images.length; i++) { ImageLoader.load(images[i], {load: true}); }

But this do not solve the audio and videos blocks, i've tested every single code part existing on SQS forums but none of them work, ive also tested what suggested here but no solution.

Here is my code to get events:

$(document).ready(function(){
var url = '/test-blog?format=json';
$.getJSON(url).done(function(data) {
  var items = data.items;

  var $_container = $('#events-container-concert');
  var result = "";
  var appendText = [];
  items.forEach(function(elm) {
    var body = elm.body;
    var $_body = $(body);

    appendText.push("<div class='blog-item'><div id='body'>"+body+"</div>");
  });   

  appendText.join(" ");
  $_container.html(appendText);

  var images = document.querySelectorAll('img[data-src]' );
    for (var i = 0; i < images.length; i++) {
    ImageLoader.load(images[i], {load: true});
  }
 });
});

Please is there anyone who had this issue on SQS? no one answered my question on SQS forums Thanks

RedaZZ
  • 25
  • 4
  • I think this is solvable. Is it possible for you to provide a link to the page in question with the code working? – Brandon Nov 13 '17 at 15:22
  • hi @Brandon here is the [link](https://davids-developer.squarespace.com/events/), the code is updated look above, i appreciate your answer, thanks – RedaZZ Nov 13 '17 at 17:15

1 Answers1

0

You may use this to automatically load all the blocks (I believe even the image blocks, but if not then pair it with your call to ImageLoader):

window.Squarespace.AFTER_BODY_LOADED = false;
window.Squarespace.afterBodyLoad();

Of course, you'll want to wait until the content is on the page. You can pull up the page you linked-to and then run those two lines via console as a quick test. Worked well for me in that context.

Reference: https://github.com/Squarespace/squarespace-core/blob/master/src/Lifecycle.js

Brandon
  • 3,572
  • 2
  • 12
  • 27
  • Thanks a lot Brandon, i've been looking for this solution months ago on SQS forums none of the folks mention this solution. I appreciate your dedication – RedaZZ Nov 14 '17 at 08:30