1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-10 23:30:03 +02:00

Added cross-browser isArray for cross-frame support. fixes #1195. closes #1218

This commit is contained in:
shmulik 2014-06-12 15:24:46 -07:00 committed by Steve Heffernan
parent 6116e3c3da
commit 6d78c95bb4
5 changed files with 22 additions and 3 deletions

View File

@ -2,7 +2,7 @@ CHANGELOG
=========
## HEAD (Unreleased)
_(none)_
* Added cross-browser isArray for cross-frame support. fixes #1195 ([view](https://github.com/videojs/video.js/pull/1218))
--------------------

View File

@ -471,7 +471,7 @@ vjs.Component.prototype.initChildren = function(){
if (children) {
// Allow for an array of children details to passed in the options
if (children instanceof Array) {
if (vjs.obj.isArray(children)) {
for (var i = 0; i < children.length; i++) {
child = children[i];

View File

@ -160,6 +160,17 @@ vjs.obj.isPlain = function(obj){
&& obj.constructor === Object;
};
/**
* Check if an object is Array
* Since instanceof Array will not work on arrays created in another frame we need to use Array.isArray, but since IE8 does not support Array.isArray we need this shim
* @param {Object} obj Object to check
* @return {Boolean} True if plain, false otherwise
* @private
*/
vjs.obj.isArray = Array.isArray || function(arr) {
return Object.prototype.toString.call(arr) === '[object Array]';
};
/**
* Bind (a.k.a proxy or Context). A simple method for changing the context of a function
It also stores a unique id on the function so it can be easily removed from events

View File

@ -1103,7 +1103,7 @@ vjs.Player.prototype.src = function(source){
}
// Case: Array of source objects to choose from and pick the best to play
if (source instanceof Array) {
if (vjs.obj.isArray(source)) {
var sourceTech = this.selectSource(source),
techName;

View File

@ -41,6 +41,14 @@ test('should copy an object', function(){
deepEqual(asdf,fdsa);
});
test('should check if an object is an Array', function(){
var arr = ['a', 'b', 'c'];
ok(vjs.obj.isArray(arr) === true, 'Arr object is an Array');
var obj = {};
ok(vjs.obj.isArray(obj) === false, 'Obj is not an Array');
});
test('should check if an object is plain', function(){
var empty = {};
ok(vjs.obj.isPlain(empty) === true, 'Empty object is plain');