Skip to content

Commit

Permalink
@chikathreesix fixed an issue where data-setup options could be missed.
Browse files Browse the repository at this point in the history
closes #1514
  • Loading branch information
chikathreesix authored and heff committed Sep 29, 2014
1 parent e0a1248 commit f47bf26
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CHANGELOG
* @mynameisstephen fixed an issue where slider event listeners were not being cleaned up ([view](https://github.com/videojs/video.js/pull/1475))
* @alexrqs cleaned up the Spanish translation ([view](https://github.com/videojs/video.js/pull/1494))
* @t2y added a Japanese translation ([view](https://github.com/videojs/video.js/pull/1497))
* @chikathreesix fixed an issue where data-setup options could be missed ([view](https://github.com/videojs/video.js/pull/1514))

--------------------

Expand Down
22 changes: 17 additions & 5 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,24 @@ vjs.Player.prototype.dispose = function(){
};

vjs.Player.prototype.getTagSettings = function(tag){
var options = {
'sources': [],
'tracks': []
};
var tagOptions,
dataSetup,
options = {
'sources': [],
'tracks': []
};

tagOptions = vjs.getElementAttributes(tag);
dataSetup = tagOptions['data-setup'];

// Check if data-setup attr exists.
if (dataSetup !== null){
// Parse options JSON
// If empty string, make it a parsable json object.
vjs.obj.merge(tagOptions, vjs.JSON.parse(dataSetup || '{}'));
}

vjs.obj.merge(options, vjs.getElementAttributes(tag));
vjs.obj.merge(options, tagOptions);

// Get tag children settings
if (tag.hasChildNodes()) {
Expand Down
7 changes: 1 addition & 6 deletions src/js/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ vjs.autoSetup = function(){
// Check if data-setup attr exists.
// We only auto-setup if they've added the data-setup attr.
if (options !== null) {

// Parse options JSON
// If empty string, make it a parsable json object.
options = vjs.JSON.parse(options || '{}');

// Create new video.js instance.
player = videojs(vid, options);
player = videojs(vid);
}
}

Expand Down
11 changes: 11 additions & 0 deletions test/unit/setup.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
module('Setup');

test('should set options from data-setup even if autoSetup is not called before initialisation', function(){
var el = PlayerTest.makeTag();
el.setAttribute('data-setup', '{"controls": true, "autoplay": false, "preload": "auto"}');

var player = PlayerTest.makePlayer({}, el);

ok(player.options_['controls'] === true);
ok(player.options_['autoplay'] === false);
ok(player.options_['preload'] === 'auto');
});

0 comments on commit f47bf26

Please sign in to comment.