Skip to content

Commit 954f3d9

Browse files
authored
fix(player): video-js embed missing video-js class (videojs#5194)
When having a video-js embed with a class attribute, as part of the changes to remove old IE support (videojs#5041), we overwrote our addition of the video-js class when it was missing. Instead, we want to make sure that we don't override the class names again since they are already set up correctly. Fixes videojs/http-streaming#100
1 parent fcd7d0d commit 954f3d9

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/js/player.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,12 @@ class Player extends Component {
587587
tag.removeAttribute('height');
588588

589589
Object.getOwnPropertyNames(attrs).forEach(function(attr) {
590-
el.setAttribute(attr, attrs[attr]);
590+
// don't copy over the class attribute to the player element when we're in a div embed
591+
// the class is already set up properly in the divEmbed case
592+
// and we want to make sure that the `video-js` class doesn't get lost
593+
if (!(divEmbed && attr === 'class')) {
594+
el.setAttribute(attr, attrs[attr]);
595+
}
591596

592597
if (divEmbed) {
593598
tag.setAttribute(attr, attrs[attr]);

test/unit/video.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,26 @@ QUnit.test('should return a video player instance', function(assert) {
450450
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
451451
});
452452

453+
QUnit.test('should add video-js class to video-js embed if missing', function(assert) {
454+
const fixture = document.getElementById('qunit-fixture');
455+
456+
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>' +
457+
'<video-js id="test_vid_id2" class="foo"></video-js>';
458+
459+
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
460+
461+
assert.ok(player, 'created player from tag');
462+
assert.ok(player.id() === 'test_vid_id');
463+
assert.ok(player.hasClass('video-js'), 'we have the video-js class');
464+
465+
const tag2 = document.getElementById('test_vid_id2');
466+
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
467+
468+
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
469+
assert.ok(player2.hasClass('video-js'), 'we have the video-js class');
470+
assert.ok(player2.hasClass('foo'), 'we have the foo class');
471+
});
472+
453473
QUnit.test('should log about already initalized players if options already passed',
454474
function(assert) {
455475
const origWarnLog = log.warn;

0 commit comments

Comments
 (0)