From 765c01e83dc4173d778538061a82e1973a8574f0 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Thu, 10 May 2018 09:34:15 +1000 Subject: Remove references to window.Plyr --- src/js/utils.js | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/js/utils.js') diff --git a/src/js/utils.js b/src/js/utils.js index d46a7601..ebfb9c96 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -9,9 +9,6 @@ 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 +28,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)); @@ -547,7 +544,7 @@ const utils = { const event = new CustomEvent(type, { bubbles, detail: Object.assign({}, detail, { - plyr: utils.is.plyr(this) ? this : null, + plyr: this, }), }); -- cgit v1.2.3 From 7ca21697907850790f875d01bf27870a0386527b Mon Sep 17 00:00:00 2001 From: Albin Larsson Date: Mon, 14 May 2018 06:49:04 +0200 Subject: Expose defaults (enable overriding) --- src/js/utils.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/js/utils.js') diff --git a/src/js/utils.js b/src/js/utils.js index ebfb9c96..5c4934a1 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -703,6 +703,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) { -- cgit v1.2.3 From 51814249afd4337c1a7d1426ea913988228a7574 Mon Sep 17 00:00:00 2001 From: Sam Potts Date: Sat, 19 May 2018 11:24:56 +1000 Subject: Reduce circular dependencies --- src/js/utils.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/js/utils.js') diff --git a/src/js/utils.js b/src/js/utils.js index ebfb9c96..1de5ed6c 100644 --- a/src/js/utils.js +++ b/src/js/utils.js @@ -3,6 +3,7 @@ // ========================================================================== import loadjs from 'loadjs'; +import Storage from './storage'; import support from './support'; import { providers } from './types'; @@ -156,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); @@ -165,7 +168,7 @@ const utils = { } // Check in cache - if (support.storage) { + if (useStorage) { const cached = window.localStorage.getItem(prefix + id); isCached = cached !== null; @@ -184,7 +187,7 @@ const utils = { return; } - if (support.storage) { + if (useStorage) { window.localStorage.setItem( prefix + id, JSON.stringify({ @@ -247,7 +250,7 @@ const utils = { // Add text node if (utils.is.string(text)) { - element.textContent = text; + element.innerText = text; } // Return built element @@ -580,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 -- cgit v1.2.3