Skip to content

Instantly share code, notes, and snippets.

@DrMabuse23
Created September 28, 2014 11:01
Show Gist options
  • Save DrMabuse23/48322a156b6061d6d40a to your computer and use it in GitHub Desktop.
Save DrMabuse23/48322a156b6061d6d40a to your computer and use it in GitHub Desktop.
load youtube js
function onYouTubeIframeAPIReady() {
console.log( 'youtube api loaded' );
$( document ).trigger('youtube-ready');
}
requirejs( [
'jquery' ,
] ,
function ( $ ) {
/**
* try to use this https://github.com/millermedeiros/requirejs-plugins/pull/39
* but failed
*/
function getYT() {
console.log('started');
var tag = document.createElement( 'script' );
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName( 'script' )[ 0 ];
firstScriptTag.parentNode.insertBefore( tag , firstScriptTag );
}
$(function(){
getYT();
});
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment