mirror of
https://github.com/videojs/video.js.git
synced 2024-11-24 08:42:25 +02:00
Merge branch 'the-N-Zone' of github.com:gkatsev/video.js into gkatsev-the-N-Zone
This commit is contained in:
commit
a6fa0dcc80
@ -806,6 +806,9 @@ vjs.Component.prototype.dimensions = function(width, height){
|
||||
*/
|
||||
vjs.Component.prototype.dimension = function(widthOrHeight, num, skipListeners){
|
||||
if (num !== undefined) {
|
||||
if (num === null || vjs.isNaN(num)) {
|
||||
num = 0;
|
||||
}
|
||||
|
||||
// Check if using css width/height (% or px) and adjust
|
||||
if ((''+num).indexOf('%') !== -1 || (''+num).indexOf('px') !== -1) {
|
||||
|
@ -171,6 +171,17 @@ vjs.obj.isArray = Array.isArray || function(arr) {
|
||||
return Object.prototype.toString.call(arr) === '[object Array]';
|
||||
};
|
||||
|
||||
/**
|
||||
* Check to see whether the input is NaN or not.
|
||||
* NaN is the only JavaScript construct that isn't equal to itself
|
||||
* @param {Number} num Number to check
|
||||
* @return {Boolean} True if NaN, false otherwise
|
||||
* @private
|
||||
*/
|
||||
vjs.isNaN = function(num) {
|
||||
return num !== num;
|
||||
};
|
||||
|
||||
/**
|
||||
* Bind (a.k.a proxy or Context). A simple method for changing the context of a function
|
||||
It also stores a unique id on the function so it can be easily removed from events
|
||||
|
@ -199,6 +199,34 @@ test('should show and hide an element', function(){
|
||||
ok(comp.el().style.display === 'block');
|
||||
});
|
||||
|
||||
test('dimension() should treat NaN and null as zero', function() {
|
||||
var comp, width, height, newWidth, newHeight;
|
||||
width = 300;
|
||||
height = 150;
|
||||
|
||||
comp = new vjs.Component(getFakePlayer(), {}),
|
||||
// set component dimension
|
||||
|
||||
comp.dimensions(width, height);
|
||||
|
||||
newWidth = comp.dimension('width', null);
|
||||
|
||||
notEqual(newWidth, width, 'new width and old width are not the same');
|
||||
equal(newWidth, comp, 'we set a value, so, return value is component');
|
||||
equal(comp.width(), 0, 'the new width is zero');
|
||||
|
||||
newHeight = comp.dimension('height', NaN);
|
||||
|
||||
notEqual(newHeight, height, 'new height and old height are not the same');
|
||||
equal(newHeight, comp, 'we set a value, so, return value is component');
|
||||
equal(comp.height(), 0, 'the new height is zero');
|
||||
|
||||
comp.width(width);
|
||||
newWidth = comp.dimension('width', undefined);
|
||||
|
||||
equal(newWidth, width, 'we did not set the width with undefined');
|
||||
});
|
||||
|
||||
test('should change the width and height of a component', function(){
|
||||
var container = document.createElement('div');
|
||||
var comp = new vjs.Component(getFakePlayer(), {});
|
||||
|
Loading…
Reference in New Issue
Block a user