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

Copy over data attrs from video el to wrapper el. #1321

Merged
merged 2 commits into from
Jul 28, 2014
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: 11 additions & 5 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ vjs.Player.prototype.getTagSettings = function(tag){
};

vjs.Player.prototype.createEl = function(){
var el = this.el_ = vjs.Component.prototype.createEl.call(this, 'div');
var tag = this.tag;
var
el = this.el_ = vjs.Component.prototype.createEl.call(this, 'div'),
tag = this.tag,
attrs;

// Remove width/height attrs from tag so CSS can make it 100% width/height
tag.removeAttribute('width');
Expand Down Expand Up @@ -189,10 +191,14 @@ vjs.Player.prototype.createEl = function(){
}
}

// Give video tag ID and class to player div
// Copy over all the attributes from the tag, including ID and class
// ID will now reference player box, not the video tag
el.id = tag.id;
el.className = tag.className;
attrs = vjs.getAttributeValues(tag);
vjs.obj.each(attrs, function(attr) {
if (Object.prototype.hasOwnProperty.call(attrs, attr)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I had it here still because I was doing this with a for-loop originally.

el.setAttribute(attr, attrs[attr]);
}
});

// Update tag id/class for use as HTML5 playback tech
// Might think we should do this after embedding in container so .vjs-tech class
Expand Down
12 changes: 12 additions & 0 deletions test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,15 @@ test('player should handle different error types', function(){
vjs.log.error.restore();
});

test('Data attributes on the video element should persist in the new wrapper element', function() {
var dataId, tag, player;

dataId = 123;

tag = PlayerTest.makeTag();
tag.setAttribute('data-id', dataId);

player = PlayerTest.makePlayer({}, tag);

equal(player.el().getAttribute('data-id'), dataId, 'data-id should be available on the new player element after creation');
});