Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: regression for getting a player via the tech's id #4969

Merged
merged 3 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/js/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,13 +269,23 @@ videojs.getPlayers = () => Player.players;
*/
videojs.getPlayer = (id) => {
const players = Player.players;
let tag;

if (typeof id === 'string') {
return players[normalizeId(id)];
const nId = normalizeId(id);
const player = players[nId];

if (player) {
return player;
}

tag = Dom.$('#' + nId);
} else {
tag = id;
}

if (Dom.isEl(id)) {
const {player, playerId} = id;
if (Dom.isEl(tag)) {
const {player, playerId} = tag;

// Element may have a `player` property referring to an already created
// player instance. If so, return that.
Expand Down
28 changes: 28 additions & 0 deletions test/unit/video.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,34 @@ QUnit.test('getPlayer', function(assert) {
player.dispose();
});

QUnit.test('videojs() works with the tech id', function(assert) {
const fixture = document.getElementById('qunit-fixture');

fixture.innerHTML += '<video-js id="player"></video-js>';

const tag = document.querySelector('#player');
const player = videojs('#player', {techOrder: ['html5']});

assert.strictEqual(videojs('player_html5_api'), player, 'the player was returned for the tech id');
assert.strictEqual(videojs(tag), player, 'the player was returned when using the original tag/element');

player.dispose();
});

QUnit.test('getPlayer works with the tech id', function(assert) {
const fixture = document.getElementById('qunit-fixture');

fixture.innerHTML += '<video-js id="player"></video-js>';

const tag = document.querySelector('#player');
const player = videojs('#player', {techOrder: ['html5']});

assert.strictEqual(videojs.getPlayer('player_html5_api'), player, 'the player was returned for the tech id');
assert.strictEqual(videojs.getPlayer(tag), player, 'the player was returned when using the original tag/element');

player.dispose();
});

QUnit.test('getAllPlayers', function(assert) {
const fixture = document.getElementById('qunit-fixture');

Expand Down