Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created May 18, 2012 21:17
Show Gist options
  • Select an option

  • Save buzzedword/2727642 to your computer and use it in GitHub Desktop.

Select an option

Save buzzedword/2727642 to your computer and use it in GitHub Desktop.
Youtube player snippet
var player = function(selector, dimensions) {
var $yt = $(selector);
$yt.each(function() {
var $this = $(this);
var _data = $this.data();
var params = {
allowScriptAccess: "always",
wmode: 'opaque',
controls: 0,
rel: 0,
showinfo: 0,
modestbranding: 1
}
var atts = {
id: [$this.attr('id'), '-', 'generated'].join('')
};
var flashVars = {
wmode: 'opaque'
};
// API call for SWF object. Broken into array joins to make sense of each block.
swfobject.embedSWF(['http://www.youtube.com/v/', _data.youtubeId, // Extracted from data stored in DOM for video post.
'?', ['enablejsapi=1', // Enables JS api.
['playerapiid=ytplayer-', $this.attr('id')].join(''), // Sets the API ID.
'version=3', // API version 3.
'rel=0', 'modestbranding=1', 'controls=0', 'showinfo=0'].join('&'), ].join(''), $this.attr('id'), // Use the ID of the currently looped container
dimensions.x, // Set the width
dimensions.y, // Set the height
"8", // Flash version
null, flashVars, params, atts);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment