Skip to content

Instantly share code, notes, and snippets.

@lucasbrigida
Last active January 12, 2017 04:34
Show Gist options
  • Save lucasbrigida/075224221ba345d2f3a274e03b91b1dd to your computer and use it in GitHub Desktop.
Save lucasbrigida/075224221ba345d2f3a274e03b91b1dd to your computer and use it in GitHub Desktop.
(function($){
var createVideoSources = function (sources) {
var sourcesHTML = '';
for (var i in sources) {
var source = sources[i];
sourcesHTML += '<source src="'+ source.src +'" type="'+ source.type +'"></source>';
}
return sourcesHTML;
};
var createVideoElement = function(video) {
var videoTemplate = '<video width="' + video.width + '" height="' + video.height + '" ' +
'controls' + ' preload="'+ video.preload +'" ';
videoTemplate += video.poster ? ('poster="' + video.poster + '" ') : '';
videoTemplate += '>';
videoTemplate += createVideoSources(video.sources);
videoTemplate += 'Seu navegador não suporta recurso de vídeo';
videoTemplate += '</video>';
return videoTemplate;
};
var createVideoGallery = function(videos) {
var videoGalleryTemplate = '<div class="x-video-gallery">';
for (var i in videos) {
videoGalleryTemplate += '<div class="x-video video-'+ i +'">' + createVideoElement(videos[i]) + '</div>';
}
videoGalleryTemplate += '</div>';
return videoGalleryTemplate;
};
var loadCustomVideos = function() {
if (!window.XCustomVideos) return;
var parent = $(XCustomVideos.galleryElement);
parent.append(createVideoGallery(XCustomVideos.videos));
};
// Event Listener
$(loadCustomVideos);
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment