From c9b1217e10da30b8ba2b8d2ecbc8f80136403eb2 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 1 Jul 2014 15:10:45 -0400 Subject: [PATCH 1/2] Copy over data attrs from video el to wrapper el. --- src/js/player.js | 17 ++++++++++++----- test/unit/player.js | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index caa2e5d59d..77c28e35f8 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -159,8 +159,11 @@ 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, + attr; // Remove width/height attrs from tag so CSS can make it 100% width/height tag.removeAttribute('width'); @@ -189,10 +192,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); + for (attr in attrs) { + if (Object.prototype.hasOwnProperty.call(attrs, attr)) { + 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 diff --git a/test/unit/player.js b/test/unit/player.js index 7eb6db94e6..31cd7180d7 100644 --- a/test/unit/player.js +++ b/test/unit/player.js @@ -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'); +}); From b65eb0e5f3843960962166e4f063b358f6ea0564 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 1 Jul 2014 16:11:32 -0400 Subject: [PATCH 2/2] switch to vjs.obj.each --- src/js/player.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index 77c28e35f8..e82da3622c 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -162,8 +162,7 @@ vjs.Player.prototype.createEl = function(){ var el = this.el_ = vjs.Component.prototype.createEl.call(this, 'div'), tag = this.tag, - attrs, - attr; + attrs; // Remove width/height attrs from tag so CSS can make it 100% width/height tag.removeAttribute('width'); @@ -195,11 +194,11 @@ vjs.Player.prototype.createEl = function(){ // Copy over all the attributes from the tag, including ID and class // ID will now reference player box, not the video tag attrs = vjs.getAttributeValues(tag); - for (attr in attrs) { + vjs.obj.each(attrs, function(attr) { if (Object.prototype.hasOwnProperty.call(attrs, attr)) { 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