Skip to content

Instantly share code, notes, and snippets.

@shockwaves
Created July 10, 2017 23:01
Show Gist options
  • Save shockwaves/e946be3566a27c68625d098495295de8 to your computer and use it in GitHub Desktop.
Save shockwaves/e946be3566a27c68625d098495295de8 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Bare - Start Bootstrap Template</title>
<!-- Bootstrap Core CSS -->
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<style>
body {
padding-top: 70px;
/* Required padding for .navbar-fixed-top. Remove if using .navbar-static-top. Change if height of navigation changes. */
}
</style>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<!-- Page Content -->
<div class="container">
<div class="row">
<img class="js-poster_video" data-toggle="modal" data-target="#myModal">
</div>
<!-- /.row -->
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<iframe width="560" height="315" src="" frameborder="0" allowfullscreen></iframe>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!-- /.container -->
<!-- jQuery Version 1.11.1 -->
<script src="node_modules/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script>
<script src="node_modules/urijs/src/URI.min.js"></script>
<script>
var posterHost = 'https://img.youtube.com/vi/';
var videoHost = 'https://www.youtube.com/embed/';
var posterImage = '/0.jpg';
var videoId = URI.parseQuery(window.location.search).videoId;
var posterUrl = posterHost + videoId + posterImage;
$('.js-poster_video')
.attr('src', posterUrl)
.data('youtubeId', videoId);
$('#myModal').on('show.bs.modal', function (event) {
var posterVideo = $(event.relatedTarget);
var youtubeId = posterVideo.data('youtubeId');
var modal = $(this);
var videoUrl = videoHost + youtubeId;
modal.find('.modal-body iframe').attr('src', videoUrl);
});
$('#myModal').on('hide.bs.modal', function (event) {
var modal = $(this);
modal.find('.modal-body iframe').attr('src', '');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment