video-embed-loader.js
var VideoEmbedLoader = {
flashSupported: function()
{
return navigator.mimeTypes
&& navigator.mimeTypes["application/x-shockwave-flash"];
},
loadAll: function(elem)
{
if(!elem)elem = document.body;
var divElements = elem.getElementsByTagName("div");
for(var i=0; i<divElements.length; i++)
{
var div = divElements;
if(div.className != "youtube-embed") continue;
VideoEmbedLoader.appendPlayerIn(div.getAttribute("video"), div);
}
},
appendPlayerIn: function(vidcode, elem)
{
if(VideoEmbedLoader.flashSupported())
{
var iframe = document.createElement("iframe");
iframe.src = "http://www.youtube.com/watch_popup?v="
+vidcode+"&vq=large";
iframe.className = "youtube-embed-player";
iframe.setAttribute("frameborder", "0");
elem.appendChild(iframe);
}
else
{
var embed = document.createElement("embed");
embed.src = "http://www.youtube.com/v/"+vidcode+"?fs=1";
embed.className = "youtube-embed-player";
embed.setAttribute("type", "application/x-shockwave-flash");
embed.setAttribute("allowscriptaccess", "always");
embed.setAttribute("allowfullscreen", "true");
elem.appendChild(embed);
}
}
};
window.onload = function()
{
VideoEmbedLoader.loadAll();
};