home.ejs 1.81 KB
<% include ./includes/header.ejs %>
    <div class="container" id="masonry_container">
        <% for (var i in videos) { %>
            <div id="<%=videos[i].id%>" vid="<%=videos[i].video_id%>">
            </div>
        <%};%>
    </div>
    
<style type="text/css">
.masonry-grid img { max-width: 260px; }
</style>
<script src="https://unpkg.com/masonry-layout@4/dist/masonry.pkgd.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/4.1.1/imagesloaded.pkgd.min.js"></script>
<script type="text/javascript">
    var $masonry_container = $('#masonry_container');
    $masonry_container.imagesLoaded(function(){
      $masonry_container.masonry({
        itemSelector : '.masonry-grid',
        columnWidth : 270
      });
    });
</script>
<script>
    var tag = document.createElement('script');

    tag.src = "https://www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

    var player;
    var players = [];
    var videoIds = [];
    for (var i = 0;i<10;i++) {
        players.push(String(i));
        videoIds.push($('#'+i).attr('vid'));
    }

    function onYouTubeIframeAPIReady() {
        for (var i = 0; i < videoIds.length; i++) {
            player = new YT.Player(players[i], {
                height: '360',
                width: '640',
                videoId: videoIds[i],
                events: {
                    // 'onReady': onPlayerReady,
                    // 'onStateChange': onPlayerStateChange
                }
            });
        }
    }

    //   function onPlayerReady(event) {
    //   }
    //   function onPlayerStateChange(event) {
    //   }
    //   function stopVideo() {
    //   }
</script>
<% include ./includes/footer.ejs %>