mirror of
https://github.com/videojs/video.js.git
synced 2025-04-11 11:42:08 +02:00
Updated to match comments in #1093
This commit is contained in:
parent
3e5ef19212
commit
27f0f789e0
@ -439,37 +439,62 @@ vjs.Component.prototype.removeChild = function(component){
|
||||
* myChildOption: true
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* // Or when creating the component
|
||||
* var myComp = new MyComponent(player, {
|
||||
* children: {
|
||||
* myChildComponent: {
|
||||
* myChildOption: true
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* The children option can also be an Array of child names or
|
||||
* child options objects (that also include a 'name' key).
|
||||
*
|
||||
* var myComp = new MyComponent(player, {
|
||||
* children: [
|
||||
* 'button',
|
||||
* {
|
||||
* name: 'button',
|
||||
* someOtherOption: true
|
||||
* }
|
||||
* ]
|
||||
* });
|
||||
*
|
||||
*/
|
||||
vjs.Component.prototype.initChildren = function(){
|
||||
var options = this.options_;
|
||||
var parent, children, child, name, opts;
|
||||
|
||||
if (options && options['children']) {
|
||||
var self = this;
|
||||
parent = this;
|
||||
children = this.options()['children'];
|
||||
|
||||
// Loop through components and add them to the player
|
||||
vjs.each(options['children'], function(name, opts){
|
||||
//Support for a simpler setup, children with no options
|
||||
if (typeof name == 'number') {
|
||||
name = opts;
|
||||
opts = {};
|
||||
if (children) {
|
||||
// Allow for an array of children details to passed in the options
|
||||
if (children instanceof Array) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
child = children[i];
|
||||
|
||||
if (typeof child == 'string') {
|
||||
name = child;
|
||||
opts = {};
|
||||
} else {
|
||||
name = child.name;
|
||||
opts = child;
|
||||
}
|
||||
|
||||
parent[name] = parent.addChild(name, opts);
|
||||
}
|
||||
} else {
|
||||
vjs.obj.each(children, function(name, opts){
|
||||
// Allow for disabling default components
|
||||
// e.g. vjs.options['children']['posterImage'] = false
|
||||
if (opts === false) return;
|
||||
|
||||
// Allow for disabling default components
|
||||
// e.g. vjs.options['children']['posterImage'] = false
|
||||
if (opts === false) return;
|
||||
|
||||
// Allow waiting to add components until a specific event is called
|
||||
var tempAdd = function(){
|
||||
// Set property name on player. Could cause conflicts with other prop names, but it's worth making refs easy.
|
||||
self[name] = self.addChild(name, opts);
|
||||
};
|
||||
|
||||
if (opts['loadEvent']) {
|
||||
// this.one(opts.loadEvent, tempAdd)
|
||||
} else {
|
||||
tempAdd();
|
||||
}
|
||||
});
|
||||
parent[name] = parent.addChild(name, opts);
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -44,26 +44,6 @@ vjs.capitalize = function(string){
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
};
|
||||
|
||||
/**
|
||||
* Loop through an array, an array of objects, or each property
|
||||
* in an object and call a function whose arguments are (key,value)
|
||||
* @param {Object} arrLike Object of properties
|
||||
* @param {Function} fn Function to be called on each property.
|
||||
* @this {*}
|
||||
* @private
|
||||
*/
|
||||
vjs.each = function (arrLike, fn, context) {
|
||||
if (vjs.obj.isPlain(arrLike)) vjs.obj.each(arrLike, fn, context);
|
||||
else {
|
||||
for (var i = 0, len = arrLike.length; i < len; ++i) {
|
||||
var val = arrLike[i];
|
||||
|
||||
if (vjs.obj.isPlain(val)) vjs.obj.each(val, fn, context);
|
||||
else fn.call(context || this, i, val);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Object functions container
|
||||
* @type {Object}
|
||||
@ -713,9 +693,9 @@ vjs.findPosition = function(el) {
|
||||
scrollTop = window.pageYOffset || body.scrollTop;
|
||||
top = box.top + scrollTop - clientTop;
|
||||
|
||||
// Android sometimes returns slightly off decimal values, so need to round
|
||||
return {
|
||||
left: vjs.round(left),
|
||||
top: vjs.round(top)
|
||||
};
|
||||
// Android sometimes returns slightly off decimal values, so need to round
|
||||
return {
|
||||
left: vjs.round(left),
|
||||
top: vjs.round(top)
|
||||
};
|
||||
};
|
||||
|
@ -53,9 +53,9 @@ test('should init child components from simple children array', function(){
|
||||
test('should init child components from children array of objects', function(){
|
||||
var comp = new vjs.Component(getFakePlayer(), {
|
||||
children: [
|
||||
{'component':{}},
|
||||
{'component':{}},
|
||||
{'component':{}}
|
||||
{ 'name': 'component' },
|
||||
{ 'name': 'component' },
|
||||
{ 'name': 'component' }
|
||||
]
|
||||
});
|
||||
|
||||
|
@ -22,47 +22,13 @@ test('should loop through each property on an object', function(){
|
||||
};
|
||||
|
||||
// Add 3 to each value
|
||||
vjs.each(asdf, function(key, value){
|
||||
vjs.obj.each(asdf, function(key, value){
|
||||
asdf[key] = value + 3;
|
||||
});
|
||||
|
||||
deepEqual(asdf,{a:4,b:5,'c':6});
|
||||
});
|
||||
|
||||
test('should loop through simple array', function(){
|
||||
var asdf = [
|
||||
'a',
|
||||
'b',
|
||||
'c'
|
||||
];
|
||||
|
||||
var newArr = [];
|
||||
vjs.each(asdf, function(key, value){
|
||||
newArr[key] = value;
|
||||
ok(typeof key == 'number', 'Key is not a number, the array index');
|
||||
ok(typeof value == 'string', 'Value is not a string');
|
||||
});
|
||||
|
||||
deepEqual(asdf,newArr);
|
||||
});
|
||||
|
||||
test('should loop through an array of objects', function(){
|
||||
var asdf = [
|
||||
{ a: {} },
|
||||
{ b: {} },
|
||||
{ 'c': {} }
|
||||
];
|
||||
|
||||
var newObj = {};
|
||||
vjs.each(asdf, function(key, value){
|
||||
newObj[key] = value;
|
||||
ok(typeof key == 'string', 'Key is not a string');
|
||||
ok(vjs.obj.isPlain(value), 'Value is not an object');
|
||||
});
|
||||
|
||||
deepEqual(newObj, { a: {}, b: {}, 'c': {}});
|
||||
});
|
||||
|
||||
test('should copy an object', function(){
|
||||
var asdf = {
|
||||
a: 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user