Opening images in modal windows

How It Works

To make viewing images more convenient for users, you can set up opening images in modal windows.

Who Can Use It

Partners who have already integrated Site Builder.

How to Get It

  1. Go to Publisher Account > Site Builder.
  2. Add the image to the needed block. Possible options are:
    • Description
    • Gallery
  3. Insert the following code to the Custom code block:

Full screen
Small screen
(function () {
  var blocks = ['.block--description', '.block--gallery'];

  var style = document.createElement('link');
  style.rel = 'stylesheet';
  style.href = '';

  var script = document.createElement('script');
  script.type = 'text/javascript';
  script.src = '';
  script.addEventListener('load', function () {
    var fancyBoxClass = 'image-fancybox';
    blocks.forEach(function (block) {
        .forEach(function (element) {
          var url = element.getAttribute('data-bg')
            .replace('url(', '')
            .replace(')', '')
            .replace('"', '')
          if (url === '') {
            .wrap('<a style="width: 100%; height: 100%;" class="' + fancyBoxClass + '" href="' + url + '"></a>');

    $('.' + fancyBoxClass)
  }, false);

  1. In the blocks parameter, specify the names of the CSS classes of the blocks to apply this modal window to. Use commas to separate the names. If there are several identical blocks in your site, these settings will be applied to all of them. Possible options are:
    • .block--description (the Description block)
    • .block--gallery (the Gallery block)
  2. Click Preview to see your changes.

Watch the tutorial video for this recipe: