Commit 353fd286 authored by Julian Pustkuchen's avatar Julian Pustkuchen
Browse files

Issue #3322867 by Anybody, Grevil: Blazy videos not blocked properly (src vs. data-src)

parent 1b73b90d
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -105,6 +105,23 @@ function _cookies_video_preprocess_field_item_blazy_oembed(&$item) {
  $item["content"]["#build"]['attributes']["class"][] = 'cookies-video-blazy-oembed';
}

/**
 * Implements hook_preprocess_blazy().
 */
function cookies_video_preprocess_blazy(&$variables) {
  // Blazy elements need additional blocking by COOKiES, as they already use
  // data-src, but Blazy unblocks that itself by lazy-loading and doesn't
  // respect COOKiES consent.
  // So we have to add an extra layer of blocking by moving the data-src
  // attribute to data-cookies-video-blazy-src
  // And unblocking it in cookies_media.js
  // See https://www.drupal.org/project/cookies/issues/3322867 for details.
  if (!empty($variables['iframe']['#attributes']['data-src'])) {
    $variables['iframe']['#attributes']['data-cookies-video-blazy-src'] = $variables['iframe']['#attributes']['data-src'];
    unset($variables['iframe']['#attributes']['data-src']);
  }
}

/**
 * Handling videos embed with "Video Embed Field (video_embed_field)" module.
 *
+9 −2
Original line number Diff line number Diff line
@@ -17,9 +17,16 @@
        }
      });

      // Blazy handling: Show the blazy image preview
      // Blazy module handling:
      $('.cookies-video-blazy-oembed', context).each(function (i, element) {
        var $element = $(element);
        // Unblock blazy iframes, which had additional COOKiES blocking.
        // See cookies_video_preprocess_blazy() for details.
        var $iframe = $element.children('iframe.b-lazy');
        if ($iframe.attr('src') !== $iframe.data('cookies-video-blazy-src')) {
          $iframe.attr('src', $iframe.data('cookies-video-blazy-src'));
        }
        // Show  the hidden container:
        if ($element.hasClass('hidden')) {
          $element.removeClass('hidden');
        }