はじめのてcoffeescript、youtube javascript apiではまる by onYouTubePlayerReady
rails3.2はcoffeescriptデフォルトってことではじめて使ってみたらはまった
こう書いたら
onYouTubePlayerReady = (playerId) ->
alert "playerId: #{playerId}"こうなって
var onYouTubePlayerReady;
onYouTubePlayerReady = function(playerId) {
return alert("playerId: " + playerId);
};varいらないと思いグーグル先生に聞いたらwindowつけなさいと
window.onYouTubePlayerReady = (playerId) ->
alert "playerId: #{playerId}"先生ありがとう
最終的には、これが
function onYouTubePlayerReady(playerId) {
ytplayer = document.getElementById("myytplayer");
ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
}
function onytplayerStateChange(newState) {
alert("Player's new state: " + newState);
}
var params = { allowScriptAccess: "always" };
var atts = { id: "myytplayer" };
swfobject.embedSWF("http://www.youtube.com/v/4TQ-nY6EB5U?enablejsapi=1&playerapiid=ytplayer",
"ytapiplayer", "425", "356", "8", null, null, params, atts);こうなった
(function() {
$(function() {
var atts, params;
params = {
allowScriptAccess: "always"
};
atts = {
id: "myytplayer"
};
return swfobject.embedSWF("http://www.youtube.com/v/4TQ-nY6EB5U?enablejsapi=1&playerapiid=ytplayer", "ytapiplayer", "425", "356", "8", null, null, params, atts);
});
window.onYouTubePlayerReady = function(playerId) {
window.ytplayer = document.getElementById("myytplayer");
return ytplayer.addEventListener("onStateChange", "onytplayerStateChange");
};
window.onytplayerStateChange = function(newState) {
return alert("Player's new state: " + newState);
};
}).call(this);