-
Notifications
You must be signed in to change notification settings - Fork 0
/
remote-videos.js
32 lines (24 loc) · 1.48 KB
/
remote-videos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function (Drupal, $) {
'use strict';
Drupal.behaviors.remote_video_lazyload = {
attach: function (context, settings) {
$(document).ready(function() {
var video_wrapper = $('.remote-video-embed', context);
// Check to see if video wrapper exists.
if (video_wrapper.length) {
// If user clicks on the video wrapper load the video in the iframe.
video_wrapper.on('click', function(){
// Pull the video ID and title from the data attributes on the wrapper element.
// Check to see if it's vimeo or youtube first, then construct iframes appropriately.
if ($(this).data('vid-src') == 'youtube') {
$(this).html('<div class="embed-container"><iframe width="640" height="360" src="https://www.youtube.com/embed/' + $(this).data('vid-id') + '?&autoplay=1?" title="' + $(this).data('vid-title') + '" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></div>');
}
else if ($(this).data('vid-src') == 'vimeo') {
$(this).html('<div class="embed-container"><iframe src="https://player.vimeo.com/video/' + $(this).data('vid-id') + '?&autoplay=1" title="' + $(this).data('vid-title') + '" width="640" height="360" frameborder="0" allow="autoplay; fullscreen; picture-in-picture" allowfullscreen></iframe></div>');
}
});
}
});
}
}
}(Drupal, jQuery));