Skip to content

Commit

Permalink
Close GH-845: Move player id generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlap authored and heff committed Dec 2, 2013
1 parent 0cbe95d commit 1cab783
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ vjs.Player = vjs.Component.extend({
init: function(tag, options, ready){
this.tag = tag; // Store the original tag used to set options

// Make sure tag ID exists
tag.id = tag.id || 'vjs_video_' + vjs.guid++;

// Set Options
// The options argument overrides options set in the video tag
// which overrides globally set options.
Expand Down Expand Up @@ -205,9 +208,6 @@ vjs.Player.prototype.createEl = function(){
}
}

// Make sure tag ID exists
tag.id = tag.id || 'vjs_video_' + vjs.guid++;

// Give video tag ID and class to player div
// ID will now reference player box, not the video tag
el.id = tag.id;
Expand Down
15 changes: 15 additions & 0 deletions test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,3 +356,18 @@ test('should use custom message when encountering an unsupported video type',

player.dispose();
});

test('should register players with generated ids', function(){
var fixture, video, player, id;
fixture = document.getElementById('qunit-fixture');

video = document.createElement('video');
video.className = 'vjs-default-skin video-js';
fixture.appendChild(video);

player = new vjs.Player(video);
id = player.el().id;

equal(player.el().id, player.id(), 'the player and element ids are equal');
ok(vjs.players[id], 'the generated id is registered');
});

0 comments on commit 1cab783

Please sign in to comment.