aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-05-19 11:26:05 +1000
committerSam Potts <sam@potts.es>2018-05-19 11:26:05 +1000
commit1bab0d07b5b22230aab6e68105c8fc574add31e3 (patch)
tree34866e67f21a3e14c6874313ae8787795db96605 /src/js/utils.js
parent34401de3d03e61eb7d1a04f6f0b7599e7ce9cd93 (diff)
parent602353f4d953c5b083ee22fd0ee479ad605de281 (diff)
downloadplyr-1bab0d07b5b22230aab6e68105c8fc574add31e3.tar.lz
plyr-1bab0d07b5b22230aab6e68105c8fc574add31e3.tar.xz
plyr-1bab0d07b5b22230aab6e68105c8fc574add31e3.zip
Merge branch 'master' into develop
Diffstat (limited to 'src/js/utils.js')
-rw-r--r--src/js/utils.js31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/js/utils.js b/src/js/utils.js
index d46a7601..a58d8555 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -3,15 +3,13 @@
// ==========================================================================
import loadjs from 'loadjs';
+import Storage from './storage';
import support from './support';
import { providers } from './types';
const utils = {
// Check variable types
is: {
- plyr(input) {
- return this.instanceof(input, window.Plyr);
- },
object(input) {
return this.getConstructor(input) === Object;
},
@@ -31,22 +29,22 @@ const utils = {
return !this.nullOrUndefined(input) && Array.isArray(input);
},
weakMap(input) {
- return this.instanceof(input, window.WeakMap);
+ return this.instanceof(input, WeakMap);
},
nodeList(input) {
- return this.instanceof(input, window.NodeList);
+ return this.instanceof(input, NodeList);
},
element(input) {
- return this.instanceof(input, window.Element);
+ return this.instanceof(input, Element);
},
textNode(input) {
return this.getConstructor(input) === Text;
},
event(input) {
- return this.instanceof(input, window.Event);
+ return this.instanceof(input, Event);
},
cue(input) {
- return this.instanceof(input, window.TextTrackCue) || this.instanceof(input, window.VTTCue);
+ return this.instanceof(input, TextTrackCue) || this.instanceof(input, VTTCue);
},
track(input) {
return this.instanceof(input, TextTrack) || (!this.nullOrUndefined(input) && this.string(input.kind));
@@ -159,6 +157,8 @@ const utils = {
// Only load once if ID set
if (!hasId || !exists()) {
+ const useStorage = Storage.supported;
+
// Create container
const container = document.createElement('div');
utils.toggleHidden(container, true);
@@ -168,7 +168,7 @@ const utils = {
}
// Check in cache
- if (support.storage) {
+ if (useStorage) {
const cached = window.localStorage.getItem(prefix + id);
isCached = cached !== null;
@@ -187,7 +187,7 @@ const utils = {
return;
}
- if (support.storage) {
+ if (useStorage) {
window.localStorage.setItem(
prefix + id,
JSON.stringify({
@@ -250,7 +250,7 @@ const utils = {
// Add text node
if (utils.is.string(text)) {
- element.textContent = text;
+ element.innerText = text;
}
// Return built element
@@ -547,7 +547,7 @@ const utils = {
const event = new CustomEvent(type, {
bubbles,
detail: Object.assign({}, detail, {
- plyr: utils.is.plyr(this) ? this : null,
+ plyr: this,
}),
});
@@ -583,7 +583,7 @@ const utils = {
return input;
}
- return input.toString().replace(/{(\d+)}/g, (match, i) => utils.is.string(args[i]) ? args[i] : '');
+ return input.toString().replace(/{(\d+)}/g, (match, i) => (utils.is.string(args[i]) ? args[i] : ''));
},
// Get percentage
@@ -706,6 +706,11 @@ const utils = {
return array.filter((item, index) => array.indexOf(item) === index);
},
+ // Clone nested objects
+ cloneDeep(object) {
+ return JSON.parse(JSON.stringify(object));
+ },
+
// Get the closest value in an array
closest(array, value) {
if (!utils.is.array(array) || !array.length) {