Created
September 21, 2016 19:10
-
-
Save johnny5th/58e2bc5296b62aaae218e7d14a35993a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Video Thing | |
$('.video-button').click(function() { | |
var video = $(this).data("video"); | |
var source = $(this).data("source"); | |
var iframe = $('<iframe scrolling="no" src="' + video + '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>'); | |
var wrapper = $('<div class="iframe-wrapper"></div>'); | |
var video_box = $(this).parents('.video-box'); | |
// Add iframe wrapper to main container | |
video_box.append(wrapper); | |
// Add iframe to wrapper | |
wrapper.append(iframe); | |
// Special logic for header videos | |
if(video_box.attr('id') == "title-area") { | |
$('#content').addClass('watching-video'); | |
} | |
function playerFinish() { | |
wrapper.remove(); | |
if(video_box.attr('id') == "title-area") { | |
$('#content').removeClass('watching-video'); | |
} | |
} | |
// Kill video when it's over | |
$(iframe).load(function() { | |
if(source == "vimeo") { | |
var player = $f(iframe[0]); | |
player.addEvent('ready', function() { | |
player.addEvent('finish', playerFinish); | |
}); | |
} else if(source == "youtube") { | |
player = new YT.Player(iframe[0], { | |
events: { | |
onReady: function(){ | |
player.addEventListener('onStateChange',function(){}); | |
}, | |
onStateChange: function(state){ | |
if(state.data == 0){ | |
playerFinish(); | |
} | |
} | |
} | |
}); | |
} | |
}); | |
}); | |
// End Video Thing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment