mirror of
https://github.com/videojs/video.js.git
synced 2024-12-23 02:04:34 +02:00
fix: bring back Android 4.x support (#6289)
Use a WeakMap and Set shams for browsers that don't support it.
This commit is contained in:
parent
de21baf34f
commit
bacd2b238d
@ -98,9 +98,38 @@ class Component {
|
|||||||
this.childIndex_ = {};
|
this.childIndex_ = {};
|
||||||
this.childNameIndex_ = {};
|
this.childNameIndex_ = {};
|
||||||
|
|
||||||
this.setTimeoutIds_ = new Set();
|
let SetSham;
|
||||||
this.setIntervalIds_ = new Set();
|
|
||||||
this.rafIds_ = new Set();
|
if (!window.Set) {
|
||||||
|
SetSham = class {
|
||||||
|
constructor() {
|
||||||
|
this.set_ = {};
|
||||||
|
}
|
||||||
|
has(key) {
|
||||||
|
return key in this.set_;
|
||||||
|
}
|
||||||
|
delete(key) {
|
||||||
|
const has = this.has(key);
|
||||||
|
|
||||||
|
delete this.set_[key];
|
||||||
|
|
||||||
|
return has;
|
||||||
|
}
|
||||||
|
add(key) {
|
||||||
|
this.set_[key] = 1;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
forEach(callback, thisArg) {
|
||||||
|
for (const key in this.set_) {
|
||||||
|
callback.call(thisArg, key, key, this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setTimeoutIds_ = window.Set ? new Set() : new SetSham();
|
||||||
|
this.setIntervalIds_ = window.Set ? new Set() : new SetSham();
|
||||||
|
this.rafIds_ = window.Set ? new Set() : new SetSham();
|
||||||
this.clearingTimersOnDispose_ = false;
|
this.clearingTimersOnDispose_ = false;
|
||||||
|
|
||||||
// Add any child components in options
|
// Add any child components in options
|
||||||
|
@ -655,7 +655,11 @@ class Player extends Component {
|
|||||||
// `src` or `controls` that were set via js before the player
|
// `src` or `controls` that were set via js before the player
|
||||||
// was initialized.
|
// was initialized.
|
||||||
Object.keys(el).forEach((k) => {
|
Object.keys(el).forEach((k) => {
|
||||||
|
try {
|
||||||
tag[k] = el[k];
|
tag[k] = el[k];
|
||||||
|
} catch (e) {
|
||||||
|
// we got a a property like outerHTML which we can't actually copy, ignore it
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,62 @@
|
|||||||
* @module dom-data
|
* @module dom-data
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import log from './log.js';
|
||||||
|
import * as Guid from './guid.js';
|
||||||
|
import window from 'global/window';
|
||||||
|
|
||||||
|
let FakeWeakMap;
|
||||||
|
|
||||||
|
if (!window.WeakMap) {
|
||||||
|
FakeWeakMap = class {
|
||||||
|
constructor() {
|
||||||
|
this.vdata = 'vdata' + Math.floor(window.performance && window.performance.now() || Date.now());
|
||||||
|
this.data = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
set(key, value) {
|
||||||
|
const access = key[this.vdata] || Guid.newGUID();
|
||||||
|
|
||||||
|
if (!key[this.vdata]) {
|
||||||
|
key[this.vdata] = access;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.data[access] = value;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
get(key) {
|
||||||
|
const access = key[this.vdata];
|
||||||
|
|
||||||
|
// we have data, return it
|
||||||
|
if (access) {
|
||||||
|
return this.data[access];
|
||||||
|
}
|
||||||
|
|
||||||
|
// we don't have data, return nothing.
|
||||||
|
// return undefined explicitly as that's the contract for this method
|
||||||
|
log('We have no data for this element', key);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
has(key) {
|
||||||
|
const access = key[this.vdata];
|
||||||
|
|
||||||
|
return access in this.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
delete(key) {
|
||||||
|
const access = key[this.vdata];
|
||||||
|
|
||||||
|
if (access) {
|
||||||
|
delete this.data[access];
|
||||||
|
delete key[this.vdata];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Element Data Store.
|
* Element Data Store.
|
||||||
*
|
*
|
||||||
@ -13,4 +69,4 @@
|
|||||||
* @type {Object}
|
* @type {Object}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
export default new WeakMap();
|
export default window.WeakMap ? new WeakMap() : new FakeWeakMap();
|
||||||
|
Loading…
Reference in New Issue
Block a user