Skip to content

Commit

Permalink
Cleaner handling of player init params and added a new ytcontrols par…
Browse files Browse the repository at this point in the history
…am to use the native YouTube player controls
  • Loading branch information
jhurliman committed Mar 21, 2012
1 parent 03efd3d commit ca916fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build/release-files/youtube.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<body>

<video id="example_video_1" class="video-js vjs-default-skin" controls preload="none" width="640" height="360"
data-setup='{"techOrder":["youtube","html5"]}'>
data-setup='{"techOrder":["youtube","html5"],"ytcontrols":false}'>
<source src="http://www.youtube.com/watch?v=qWjzVHG9T1I" type='video/youtube' />
</video>

Expand Down
20 changes: 13 additions & 7 deletions src/tech.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,11 @@ _V_.youtube = _V_.PlaybackTech.extend({
_V_.youtube.loadingEls = _V_.youtube.loadingEls || [];
_V_.youtube.loadingEls.push(parentEl);

// Store player options in local var for optimization
var playerOptions = player.options;
var optionsParams = options.params || {};

// Merge default player parameters with init params
var params = _V_.merge({
controls: 0,
var params = {
disablekb: 1,
enablejsapi: 1,
iv_load_policy: 3,
Expand All @@ -743,10 +742,13 @@ _V_.youtube = _V_.PlaybackTech.extend({
rel: 0,
showinfo: 0,
showsearch: 0,
autoplay: playerOptions.autoplay ? 1 : 0,
loop: playerOptions.loop ? 1 : 0,
hd: 0,
}, options.params);
};

// Make sure the configurable params are 1 or 0
params.controls = this.toBoolInt(optionsParams.ytcontrols || playerOptions.ytcontrols);
params.autoplay = this.toBoolInt(optionsParams.autoplay || playerOptions.autoplay);
params.loop = this.toBoolInt(optionsParams.loop || playerOptions.loop);
params.hd = this.toBoolInt(optionsParams.hd || playerOptions.hd);

var p = (document.location.protocol == 'https:') ? 'https:' : 'http:';

Expand Down Expand Up @@ -876,6 +878,10 @@ _V_.youtube = _V_.PlaybackTech.extend({
return url.match(/v=([^&]+)/)[1];
},

toBoolInt: function(val) {
return val ? 1 : 0;
},

loadApi: function() {
// Check if the YouTube JS API has already been loaded
var js, id = "youtube-jssdk", ref = document.getElementsByTagName("script")[0];
Expand Down

0 comments on commit ca916fb

Please sign in to comment.