-
-
Save gregorynicholas/9100580 to your computer and use it in GitHub Desktop.
This file contains 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
Meteor.startup(function () { | |
Session.set('YTApiReady', false); | |
Session.set('channelRendered', false); | |
}); | |
onYouTubeIframeAPIReady = function() { | |
Session.set('YTApiReady', true); | |
}; | |
Template.channel.created = function () { | |
if (typeof player === 'undefined') | |
$.getScript('https://www.youtube.com/iframe_api', function () {}); | |
}; | |
Template.channel.rendered = function() { | |
Session.set('channelRendered', true); | |
}; | |
Template.channel.destroyed = function () { | |
Session.set('channelRendered', false); | |
}; | |
Deps.autorun(function (c) { | |
if (Session.equals('YTApiReady', false) || | |
Session.equals('channelRendered', false)) { | |
return; | |
} | |
var interval = Meteor.setInterval(function () { | |
if(!document.getElementById('player-div')) { | |
return; | |
} | |
var playerDiv = document.createElement('div'), | |
channel = Template.channel.getChannel(); | |
playerDiv.id = 'player-div'; | |
document.getElementById('player-parent').innerHTML = ''; | |
document.getElementById('player-parent').appendChild(playerDiv); | |
player = null; | |
player = new YT.Player('player-div', { | |
videoId: channel.URL, | |
events: { | |
'onReady': onPlayerReady | |
} | |
}); | |
Meteor.clearInterval(interval); | |
}, 100); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment