mirror of
https://github.com/videojs/video.js.git
synced 2025-03-03 15:12:49 +02:00
Ignore null, undefined, and NaN is dimension()
Add vjs.isNaN to have a better cross browser isNaN checker. Previously, only undefined was ignored, so, it tried setting the dimension using null and NaN as values. In most browsers this isn't a problem, but in particular on IE8, things break. With this PR, all three of those values will be ignored.
This commit is contained in:
parent
055d81dc3a
commit
68ad48d8e8
@ -805,7 +805,7 @@ vjs.Component.prototype.dimensions = function(width, height){
|
||||
* @private
|
||||
*/
|
||||
vjs.Component.prototype.dimension = function(widthOrHeight, num, skipListeners){
|
||||
if (num !== undefined) {
|
||||
if (num !== undefined && num !== null && !vjs.isNaN(num)) {
|
||||
|
||||
// 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,29 @@ test('should show and hide an element', function(){
|
||||
ok(comp.el().style.display === 'block');
|
||||
});
|
||||
|
||||
test('dimension() should ignore undefined, null, and NaN values', 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);
|
||||
|
||||
equal(newWidth, width, 'we did not set the width with null');
|
||||
|
||||
newHeight = comp.dimension('height', NaN);
|
||||
|
||||
equal(newHeight, height, 'we did not set the height with NaN');
|
||||
|
||||
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…
x
Reference in New Issue
Block a user