私は Youtube の API や Vimeo に精通していません。 、両方が true の場合、次のように実行します。
//Let's createa a couple of custome events to simulate the real ones, comming from Youtube and Vimeo.
var youtube = document.createEvent('Event'),
vimeo = document.createEvent('Event');
youtube.initEvent('youtubeReady');
vimeo.initEvent('vimeoReady');
/*
* This function will be use to run YOUR code, ONCE BOTH events are triggered.
* As said, functions are objects so, as any object in JS, you can add fields at any time you want.
* Check this page in Mozilla's Developer Network for more detail: http://goo.gl/Pdvpk */
function sourcesReady(){
if(sourcesReady.youtube && sourcesReady.vimeo){
alert('Both sources ready!');
}
else if(sourcesReady.youtube){
alert('Only Youtube ready!');
}
else if(sourcesReady.vimeo){
alert('Only Vimeo ready!');
}
}
//Let's set a couple of event handlers for the 'ready' events, these handlers will set the flags that we need.
document.addEventListener('youtubeReady', function youtubeReadyHandler(){
sourcesReady.youtube = true; //We set/create the field in the function, that is, the function ITSELF has the field, not the 'this'.
sourcesReady(); //We call it to evaluate the condition.
}, true);
document.addEventListener('vimeoReady', function vimeoReadyHandler(){
sourcesReady.vimeo = true; //same as before.
sourcesReady(); //We call it to evaluate the condition.
}, true);
document.dispatchEvent(youtube);
document.dispatchEvent(vimeo);
この提案が役立つことを願っています。=)