Guest User

Untitled

a guest
Nov 13th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. var tag = document.createElement('script');
  2.  
  3. tag.src = "https://www.youtube.com/iframe_api";
  4. var firstScriptTag = document.getElementsByTagName('script')[0];
  5. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  6.  
  7. var player;
  8. function onYouTubeIframeAPIReady() {
  9. player = new YT.Player('player', {
  10. height: '390',
  11. width: '640',
  12. videoId: 'novideoid',
  13. events: {
  14. 'onReady': onPlayerReady,
  15. 'onStateChange': onPlayerStateChange
  16. }
  17. });
  18. }
  19.  
  20.  
  21. // 4. The API will call this function when the video player is ready.
  22.  
  23. function onPlayerReady(event) {
  24.  
  25. $('.open-popup').click(function() {
  26. event.target.playVideo();
  27. });
  28.  
  29. $('.close-popup').click(function(e) {
  30. player.stopVideo();
  31. });
  32.  
  33. }
  34.  
  35. // 5. The API calls this function when the player's state changes.
  36. // The function indicates that when playing a video (state=1),
  37. // the player should play for six seconds and then stop.
  38. var done = false;
  39. function onPlayerStateChange(event) {
  40. if(event.data === 0) {
  41. $('.close.close-popup').click();
  42. }
  43. }
  44. function stopVideo() {
  45. player.stopVideo();
  46. }
  47.  
  48. $(function () {
  49. onYouTubeIframeAPIReady();
  50. $('#myModal').on('show.bs.modal', function(e) {
  51.  
  52. var videoId = $(e.relatedTarget).data('video-id');
  53. var x = new String(videoId);
  54. player.loadVideoById(x);
  55.  
  56. });
  57.  
  58. });
Add Comment
Please, Sign In to add comment