mirror of
https://github.com/videojs/video.js.git
synced 2024-12-27 02:43:45 +02:00
NaN & null should be treated as 0 in dimension()
When dimension() receives a NaN or null value for the number, it will treat it as zero. Updated tests to reflect that as well.
This commit is contained in:
parent
68ad48d8e8
commit
df1944e9ff
@ -805,7 +805,10 @@ vjs.Component.prototype.dimensions = function(width, height){
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.dimension = function(widthOrHeight, num, skipListeners){
|
||||
if (num !== undefined && num !== null && !vjs.isNaN(num)) {
|
||||
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) {
|
||||
|
@ -199,7 +199,7 @@ test('should show and hide an element', function(){
|
||||
ok(comp.el().style.display === 'block');
|
||||
});
|
||||
|
||||
test('dimension() should ignore undefined, null, and NaN values', function() {
|
||||
test('dimension() should treat NaN and null as zero', function() {
|
||||
var comp, width, height, newWidth, newHeight;
|
||||
width = 300;
|
||||
height = 150;
|
||||
@ -211,12 +211,17 @@ test('dimension() should ignore undefined, null, and NaN values', function() {
|
||||
|
||||
newWidth = comp.dimension('width', null);
|
||||
|
||||
equal(newWidth, width, 'we did not set the width with 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);
|
||||
|
||||
equal(newHeight, height, 'we did not set the height with 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');
|
||||
|
Loading…
Reference in New Issue
Block a user