1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-25 02:42:10 +02:00

@gkasev updated vjs to correctly return already created player when given an element. closes #3006

This commit is contained in:
Gary Katsevman 2016-01-15 15:27:35 -05:00
parent b48797bf17
commit 6977b0e3fe
4 changed files with 49 additions and 4 deletions

View File

@ -2,7 +2,7 @@ CHANGELOG
=========
## HEAD (Unreleased)
_(none)_
* @gkasev updated vjs to correctly return already created player when given an element ([view](https://github.com/videojs/video.js/pull/3006))
--------------------

View File

@ -269,6 +269,7 @@ class Player extends Component {
// Update tag id/class for use as HTML5 playback tech
// Might think we should do this after embedding in container so .vjs-tech class
// doesn't flash 100% width/height, but class only applies with .video-js parent
tag.playerId = tag.id;
tag.id += '_html5_api';
tag.className = 'vjs-tech';

View File

@ -52,8 +52,8 @@ if (typeof HTMLVideoElement === 'undefined') {
* @mixes videojs
* @method videojs
*/
var videojs = function(id, options, ready){
var tag; // Element of ID
let videojs = function(id, options, ready){
let tag; // Element of ID
// Allow for element or ID to be passed in
// String ID
@ -95,7 +95,7 @@ var videojs = function(id, options, ready){
// Element may have a player attr referring to an already created player instance.
// If not, set up a new player and return the instance.
return tag['player'] || new Player(tag, options, ready);
return tag['player'] || Player.players[tag.playerId] || new Player(tag, options, ready);
};
// Add default styles

View File

@ -30,6 +30,50 @@ test('should return a video player instance', function(){
var playerAgain = videojs('test_vid_id');
ok(player === playerAgain, 'did not create a second player from same tag');
equal(player, playerAgain, 'we did not make a new player');
var tag2 = document.getElementById('test_vid_id2');
var player2 = videojs(tag2, { techOrder: ['techFaker'] });
ok(player2.id() === 'test_vid_id2', 'created player from element');
});
test('should return a video player instance from el html5 tech', function() {
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML += '<video id="test_vid_id"></video><video id="test_vid_id2"></video>';
var vid = document.querySelector('#test_vid_id');
var player = videojs(vid);
ok(player, 'created player from tag');
ok(player.id() === 'test_vid_id');
ok(videojs.getPlayers()['test_vid_id'] === player, 'added player to global reference');
var playerAgain = videojs(vid);
ok(player === playerAgain, 'did not create a second player from same tag');
equal(player, playerAgain, 'we did not make a new player');
var tag2 = document.getElementById('test_vid_id2');
var player2 = videojs(tag2, { techOrder: ['techFaker'] });
ok(player2.id() === 'test_vid_id2', 'created player from element');
});
test('should return a video player instance from el techfaker', function() {
var fixture = document.getElementById('qunit-fixture');
fixture.innerHTML += '<video id="test_vid_id"></video><video id="test_vid_id2"></video>';
var vid = document.querySelector('#test_vid_id');
var player = videojs(vid, {techOrder: ['techFaker']});
ok(player, 'created player from tag');
ok(player.id() === 'test_vid_id');
ok(videojs.getPlayers()['test_vid_id'] === player, 'added player to global reference');
var playerAgain = videojs(vid);
ok(player === playerAgain, 'did not create a second player from same tag');
equal(player, playerAgain, 'we did not make a new player');
var tag2 = document.getElementById('test_vid_id2');
var player2 = videojs(tag2, { techOrder: ['techFaker'] });
ok(player2.id() === 'test_vid_id2', 'created player from element');