diff options
author | Sam Potts <sam@potts.es> | 2018-03-22 00:04:28 +1100 |
---|---|---|
committer | Sam Potts <sam@potts.es> | 2018-03-22 00:04:28 +1100 |
commit | 59d4a27240e77c7ee586829b1d5f032c912a1d87 (patch) | |
tree | 3b090d636dbe3048437bfbd34b64c3f6ed88c722 /dist/plyr.js | |
parent | bb7eea27e513bf33dd4a4d846b3234b37a5be48d (diff) | |
download | plyr-59d4a27240e77c7ee586829b1d5f032c912a1d87.tar.lz plyr-59d4a27240e77c7ee586829b1d5f032c912a1d87.tar.xz plyr-59d4a27240e77c7ee586829b1d5f032c912a1d87.zip |
Improve Sprite checking (fixes #827)
Diffstat (limited to 'dist/plyr.js')
-rw-r--r-- | dist/plyr.js | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/dist/plyr.js b/dist/plyr.js index dfaff4a3..b7d110a9 100644 --- a/dist/plyr.js +++ b/dist/plyr.js @@ -1010,7 +1010,16 @@ var utils = { var hasId = utils.is.string(id); var isCached = false; - function updateSprite(data) { + var exists = function exists() { + return document.querySelectorAll('#' + id).length; + }; + + function injectSprite(data) { + // Check again incase of race condition + if (hasId && exists()) { + return; + } + // Inject content this.innerHTML = data; @@ -1018,8 +1027,8 @@ var utils = { document.body.insertBefore(this, document.body.childNodes[0]); } - // Only load once - if (!hasId || !document.querySelectorAll('#' + id).length) { + // Only load once if ID set + if (!hasId || !exists()) { // Create container var container = document.createElement('div'); utils.toggleHidden(container, true); @@ -1035,7 +1044,7 @@ var utils = { if (isCached) { var data = JSON.parse(cached); - updateSprite.call(container, data.content); + injectSprite.call(container, data.content); return; } } @@ -1052,7 +1061,7 @@ var utils = { })); } - updateSprite.call(container, result); + injectSprite.call(container, result); }).catch(function () {}); } }, |