aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/utils.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-06-09 12:04:53 +1000
committerSam Potts <sam@potts.es>2018-06-09 12:04:53 +1000
commit0c03accd417e31ad34f81b12f1e9febec6e6fc48 (patch)
tree88b7f489243d2234ebd41fed9592be3dcf3d4f83 /src/js/utils.js
parent8e634862ff7a1307f3e72c7ed6a92092711ab4d5 (diff)
downloadplyr-0c03accd417e31ad34f81b12f1e9febec6e6fc48.tar.lz
plyr-0c03accd417e31ad34f81b12f1e9febec6e6fc48.tar.xz
plyr-0c03accd417e31ad34f81b12f1e9febec6e6fc48.zip
Fix Sprite issue
Diffstat (limited to 'src/js/utils.js')
-rw-r--r--src/js/utils.js24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/js/utils.js b/src/js/utils.js
index b6ba0941..a7d2ada4 100644
--- a/src/js/utils.js
+++ b/src/js/utils.js
@@ -151,24 +151,23 @@ const utils = {
return;
}
- const prefix = 'cache-';
+ const prefix = 'cache';
const hasId = utils.is.string(id);
let isCached = false;
- const exists = () => document.querySelectorAll(`#${id}`).length;
+ const exists = () => document.getElementById(id) !== null;
+
+ const update = (container, data) => {
+ container.innerHTML = data;
- function injectSprite(data) {
// Check again incase of race condition
if (hasId && exists()) {
return;
}
- // Inject content
- this.innerHTML = data;
-
// Inject the SVG to the body
- document.body.insertBefore(this, document.body.childNodes[0]);
- }
+ document.body.insertAdjacentElement('afterbegin', container);
+ };
// Only load once if ID set
if (!hasId || !exists()) {
@@ -184,13 +183,12 @@ const utils = {
// Check in cache
if (useStorage) {
- const cached = window.localStorage.getItem(prefix + id);
+ const cached = window.localStorage.getItem(`${prefix}-${id}`);
isCached = cached !== null;
if (isCached) {
const data = JSON.parse(cached);
- injectSprite.call(container, data.content);
- return;
+ update(container, data.content);
}
}
@@ -204,14 +202,14 @@ const utils = {
if (useStorage) {
window.localStorage.setItem(
- prefix + id,
+ `${prefix}-${id}`,
JSON.stringify({
content: result,
}),
);
}
- injectSprite.call(container, result);
+ update(container, result);
})
.catch(() => {});
}