Skip to content

Commit

Permalink
@nbibler ensured classes begin with alpha characters. Fixes #2828. cl…
Browse files Browse the repository at this point in the history
…oses #2829
  • Loading branch information
nbibler authored and gkatsev committed Nov 20, 2015
1 parent 7dff83b commit 3a40b10
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CHANGELOG

## HEAD (Unreleased)
* @DatTran fixed bower paths. Fixes #2740 ([view](https://github.com/videojs/video.js/pull/2775))
* @nbibler ensured classes begin with alpha characters. Fixes #2828 ([view](https://github.com/videojs/video.js/pull/2829))

--------------------

Expand Down
8 changes: 7 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ class Player extends Component {
let width;
let height;
let aspectRatio;
let idClass;

// The aspect ratio is either used directly or to calculate width and height.
if (this.aspectRatio_ !== undefined && this.aspectRatio_ !== 'auto') {
Expand Down Expand Up @@ -451,7 +452,12 @@ class Player extends Component {
height = width * ratioMultiplier;
}

let idClass = this.id()+'-dimensions';
// Ensure the CSS class is valid by starting with an alpha character
if (/^[^a-zA-Z]/.test(this.id())) {
idClass = 'dimensions-'+this.id();
} else {
idClass = this.id()+'-dimensions';
}

// Ensure the right class is still on the player for the style element
this.addClass(idClass);
Expand Down
15 changes: 15 additions & 0 deletions test/unit/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,21 @@ test('should set the width, height, and aspect ratio via a css class', function(
ok(confirmSetting('padding-top', '25%'), 'aspect ratio percent should match the newly set aspect ratio');
});

test('should use an class name that begins with an alpha character', function(){
let alphaPlayer = TestHelpers.makePlayer({ id: 'alpha1' });
let numericPlayer = TestHelpers.makePlayer({ id: '1numeric' });

let getStyleText = function(styleEl){
return (styleEl.styleSheet && styleEl.styleSheet.cssText) || styleEl.innerHTML;
};

alphaPlayer.width(100);
numericPlayer.width(100);

ok(/\s*\.alpha1-dimensions\s*\{/.test(getStyleText(alphaPlayer.styleEl_)), 'appends -dimensions to an alpha player ID');
ok(/\s*\.dimensions-1numeric\s*\{/.test(getStyleText(numericPlayer.styleEl_)), 'prepends dimensions- to a numeric player ID');
});

test('should wrap the original tag in the player div', function(){
var tag = TestHelpers.makeTag();
var container = document.createElement('div');
Expand Down

0 comments on commit 3a40b10

Please sign in to comment.