开发者

reaching global scope from a jQuery plugin

Long time listener, first time caller...

I'm modifying a jquery plugin from this tutorial and I'm up against a concept I don't fully understand. The plugin embeds a chromeless YouTube player and in order to use functions defined in the plugin, they are added to the global scope like this:

window['myString'] = function(event){ //if event=whatever, do something };

Then at the end of the enclosure it calls the function like this:

if(!window.onY开发者_StackOverflow中文版ouTubePlayerReady)
{               
    window.onYouTubePlayerReady = function('element'){
        document.getElementById('element').addEventListener('event','myString');
    }
}

My question is simply- Can anyone tell me what concepts or keywords I should learn more about to better understand the finer points of this move?

And how is he allowed to use that final if statement? -kc

EDIT: The if statement is testing whether there's an object on the window object called onYouTubeReady. That works because we know the API call will add that object when it's ready. But if I want to add just some plain old click listeners to the window from within the plugin do I use the same technique?


The function you are refering to is a youtube custom function it listens for when the embeded youtube players are ready then runs the function.

the final if statement is basically saying. if the players are not ready listen for when they are then preform the function.

you can learn more about it here -> http://code.google.com/apis/youtube/getting_started.html#custom_player

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜