mirror of
https://github.com/videojs/video.js.git
synced 2024-12-27 02:43:45 +02:00
Merge pull request #486 from heff/feature/no-controls
Make controls = false work as expected
This commit is contained in:
commit
997b327fcd
@ -11,6 +11,10 @@ vjs.BigPlayButton = vjs.Button.extend({
|
||||
init: function(player, options){
|
||||
vjs.Button.call(this, player, options);
|
||||
|
||||
if (!player.controls()) {
|
||||
this.hide();
|
||||
}
|
||||
|
||||
player.on('play', vjs.bind(this, this.hide));
|
||||
// player.on('ended', vjs.bind(this, this.show));
|
||||
}
|
||||
@ -31,4 +35,4 @@ vjs.BigPlayButton.prototype.onClick = function(){
|
||||
//this.player_.currentTime(0);
|
||||
//}
|
||||
this.player_.play();
|
||||
};
|
||||
};
|
||||
|
@ -575,6 +575,21 @@ vjs.Component.prototype.unlockShowing = function(){
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Disable component by making it unshowable
|
||||
*/
|
||||
vjs.Component.prototype.disable = function(){
|
||||
this.hide();
|
||||
this.show = function(){};
|
||||
this.fadeIn = function(){};
|
||||
};
|
||||
|
||||
// TODO: Get enable working
|
||||
// vjs.Component.prototype.enable = function(){
|
||||
// this.fadeIn = vjs.Component.prototype.fadeIn;
|
||||
// this.show = vjs.Component.prototype.show;
|
||||
// };
|
||||
|
||||
/**
|
||||
* If a value is provided it will change the width of the player to that value
|
||||
* otherwise the width is returned
|
||||
|
4
src/js/controls.js
vendored
4
src/js/controls.js
vendored
@ -15,6 +15,10 @@ vjs.ControlBar = vjs.Component.extend({
|
||||
init: function(player, options){
|
||||
vjs.Component.call(this, player, options);
|
||||
|
||||
if (!player.controls()) {
|
||||
this.disable();
|
||||
}
|
||||
|
||||
player.one('play', vjs.bind(this, function(){
|
||||
var touchstart,
|
||||
fadeIn = vjs.bind(this, this.fadeIn),
|
||||
|
@ -427,6 +427,7 @@ vjs.Player.prototype.techCall = function(method, arg){
|
||||
this.tech[method](arg);
|
||||
} catch(e) {
|
||||
vjs.log(e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -447,22 +448,19 @@ vjs.Player.prototype.techGet = function(method){
|
||||
try {
|
||||
return this.tech[method]();
|
||||
} catch(e) {
|
||||
|
||||
// When building additional tech libs, an expected method may not be defined yet
|
||||
if (this.tech[method] === undefined) {
|
||||
vjs.log('Video.js: ' + method + ' method not defined for '+this.techName+' playback technology.', e);
|
||||
|
||||
} else {
|
||||
|
||||
// When a method isn't available on the object it throws a TypeError
|
||||
if (e.name == 'TypeError') {
|
||||
vjs.log('Video.js: ' + method + ' unavailable on '+this.techName+' playback technology element.', e);
|
||||
this.tech.isReady_ = false;
|
||||
throw e;
|
||||
} else {
|
||||
vjs.log(e);
|
||||
}
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@ -877,7 +875,11 @@ vjs.Player.prototype.controls_;
|
||||
*/
|
||||
vjs.Player.prototype.controls = function(controls){
|
||||
if (controls !== undefined) {
|
||||
this.controls_ = controls;
|
||||
// Don't trigger a change event unless it actually changed
|
||||
if (this.controls_ !== controls) {
|
||||
this.controls_ = !!controls; // force boolean
|
||||
this.trigger('controlschange');
|
||||
}
|
||||
}
|
||||
return this.controls_;
|
||||
};
|
||||
|
@ -11,7 +11,7 @@ vjs.PosterImage = vjs.Button.extend({
|
||||
init: function(player, options){
|
||||
vjs.Button.call(this, player, options);
|
||||
|
||||
if (!player.poster()) {
|
||||
if (!player.poster() || !player.controls()) {
|
||||
this.hide();
|
||||
}
|
||||
|
||||
@ -41,4 +41,4 @@ vjs.PosterImage.prototype.createEl = function(){
|
||||
|
||||
vjs.PosterImage.prototype.onClick = function(){
|
||||
this.player_.play();
|
||||
};
|
||||
};
|
||||
|
3
test/unit/controls.js
vendored
3
test/unit/controls.js
vendored
@ -14,7 +14,8 @@ test('should hide volume control if it\'s not supported', function(){
|
||||
volumeControl: false
|
||||
}
|
||||
},
|
||||
volume: function(){}
|
||||
volume: function(){},
|
||||
muted: function(){}
|
||||
};
|
||||
|
||||
volumeControl = new vjs.VolumeControl(player);
|
||||
|
@ -32,6 +32,7 @@ vjs.MediaFaker.prototype.createEl = function(){
|
||||
|
||||
vjs.MediaFaker.prototype.currentTime = function(){ return 0; };
|
||||
vjs.MediaFaker.prototype.volume = function(){ return 0; };
|
||||
vjs.MediaFaker.prototype.muted = function(){ return false; };
|
||||
|
||||
// Export vars for Closure Compiler
|
||||
vjs['MediaFaker'] = vjs.MediaFaker;
|
||||
|
@ -231,3 +231,22 @@ test('should be able to initialize player twice on the same tag using string ref
|
||||
//here it triggers error, because player was destroyed already after first dispose
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
test('should set controls and trigger event', function() {
|
||||
expect(3);
|
||||
|
||||
var player = PlayerTest.makePlayer({ 'controls': false });
|
||||
ok(player.controls() === false, 'controls set through options');
|
||||
player.controls(true);
|
||||
ok(player.controls() === true, 'controls updated');
|
||||
|
||||
player.on('controlschange', function(){
|
||||
ok(true, 'controlschange fired once');
|
||||
});
|
||||
player.controls(false);
|
||||
// Check for unnecessary controlschange events
|
||||
player.controls(false);
|
||||
|
||||
player.dispose();
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user