Last active
January 12, 2017 04:34
-
-
Save lucasbrigida/075224221ba345d2f3a274e03b91b1dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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