Advertisement
Guest User

Untitled

a guest
May 31st, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. var tag = document.createElement('script');
  2. tag.src = "//www.youtube.com/iframe_api";
  3. var firstScriptTag = document.getElementsByTagName('script')[0];
  4. firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  5.  
  6.  
  7. jQuery(document).ready(function ($) {
  8. var setupVideo = function () {
  9.  
  10. var videoId = $(this).attr('data-video-id');
  11.  
  12. $('html, body').animate({
  13. scrollTop: $(".entry-content").offset().top
  14. }, 900, function () {
  15. $('.main-video-wrapper').hide();
  16. $('#player').show();
  17. playerObject.setVideo(videoId);
  18. playerObject.playVideo();
  19. });
  20.  
  21.  
  22. };
  23.  
  24. $('.video-outer-wrap').on('click', '.video-wrapper', function () {
  25.  
  26. setupVideo.bind(this)();
  27.  
  28. });
  29.  
  30.  
  31. });
  32.  
  33. var playerObject = {
  34. videosPlayer: null,
  35. ready: false,
  36. onYouTubeIframeAPIReady: function () {
  37. this.videosPlayer = new YT.Player('yt-player', {
  38. width: '682',
  39. height: '383',
  40. videoId: jQuery('.main-video-wrapper').attr('data-video-id'),
  41. events: {
  42. 'onReady': this.onPlayerReady,
  43. 'onStateChange': this.onPlayerStateChange
  44. }
  45. })
  46. },
  47. onPlayerReady: function (event) {
  48. this.ready = true;
  49. },
  50. onPlayerStateChange: function (event) {
  51.  
  52. },
  53.  
  54. stopVideo: function () {
  55. this.videosPlayer.stopVideo();
  56. },
  57. playVideo: function () {
  58. if (this.ready) this.videosPlayer.playVideo();
  59. else setTimeout(function () {
  60. this.playVideo()
  61. }.bind(this), 1000);
  62. },
  63. setVideo: function (id) {
  64. this.videosPlayer.loadVideoById(id);
  65. },
  66.  
  67.  
  68. getVars: function () {
  69. return {
  70. videosPlayer: this.videosPlayer
  71. }
  72. }
  73. };
  74.  
  75. function onYouTubeIframeAPIReady() {
  76. playerObject.onYouTubeIframeAPIReady();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement