Improve Sprite checking (fixes #827)

This commit is contained in:
Sam Potts 2018-03-22 00:04:28 +11:00
parent bb7eea27e5
commit 59d4a27240
9 changed files with 46 additions and 21 deletions

19
dist/plyr.js vendored
View File

@ -1010,7 +1010,16 @@ var utils = {
var hasId = utils.is.string(id); var hasId = utils.is.string(id);
var isCached = false; 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 // Inject content
this.innerHTML = data; this.innerHTML = data;
@ -1018,8 +1027,8 @@ var utils = {
document.body.insertBefore(this, document.body.childNodes[0]); document.body.insertBefore(this, document.body.childNodes[0]);
} }
// Only load once // Only load once if ID set
if (!hasId || !document.querySelectorAll('#' + id).length) { if (!hasId || !exists()) {
// Create container // Create container
var container = document.createElement('div'); var container = document.createElement('div');
utils.toggleHidden(container, true); utils.toggleHidden(container, true);
@ -1035,7 +1044,7 @@ var utils = {
if (isCached) { if (isCached) {
var data = JSON.parse(cached); var data = JSON.parse(cached);
updateSprite.call(container, data.content); injectSprite.call(container, data.content);
return; return;
} }
} }
@ -1052,7 +1061,7 @@ var utils = {
})); }));
} }
updateSprite.call(container, result); injectSprite.call(container, result);
}).catch(function () {}); }).catch(function () {});
} }
}, },

2
dist/plyr.js.map vendored

File diff suppressed because one or more lines are too long

2
dist/plyr.min.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6191,7 +6191,16 @@ var utils = {
var hasId = utils.is.string(id); var hasId = utils.is.string(id);
var isCached = false; 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 // Inject content
this.innerHTML = data; this.innerHTML = data;
@ -6199,8 +6208,8 @@ var utils = {
document.body.insertBefore(this, document.body.childNodes[0]); document.body.insertBefore(this, document.body.childNodes[0]);
} }
// Only load once // Only load once if ID set
if (!hasId || !document.querySelectorAll('#' + id).length) { if (!hasId || !exists()) {
// Create container // Create container
var container = document.createElement('div'); var container = document.createElement('div');
utils.toggleHidden(container, true); utils.toggleHidden(container, true);
@ -6216,7 +6225,7 @@ var utils = {
if (isCached) { if (isCached) {
var data = JSON.parse(cached); var data = JSON.parse(cached);
updateSprite.call(container, data.content); injectSprite.call(container, data.content);
return; return;
} }
} }
@ -6233,7 +6242,7 @@ var utils = {
})); }));
} }
updateSprite.call(container, result); injectSprite.call(container, result);
}).catch(function () {}); }).catch(function () {});
} }
}, },

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -143,7 +143,14 @@ const utils = {
const hasId = utils.is.string(id); const hasId = utils.is.string(id);
let isCached = false; let isCached = false;
function updateSprite(data) { const exists = () => document.querySelectorAll(`#${id}`).length;
function injectSprite(data) {
// Check again incase of race condition
if (hasId && exists()) {
return;
}
// Inject content // Inject content
this.innerHTML = data; this.innerHTML = data;
@ -151,8 +158,8 @@ const utils = {
document.body.insertBefore(this, document.body.childNodes[0]); document.body.insertBefore(this, document.body.childNodes[0]);
} }
// Only load once // Only load once if ID set
if (!hasId || !document.querySelectorAll(`#${id}`).length) { if (!hasId || !exists()) {
// Create container // Create container
const container = document.createElement('div'); const container = document.createElement('div');
utils.toggleHidden(container, true); utils.toggleHidden(container, true);
@ -168,7 +175,7 @@ const utils = {
if (isCached) { if (isCached) {
const data = JSON.parse(cached); const data = JSON.parse(cached);
updateSprite.call(container, data.content); injectSprite.call(container, data.content);
return; return;
} }
} }
@ -190,7 +197,7 @@ const utils = {
); );
} }
updateSprite.call(container, result); injectSprite.call(container, result);
}) })
.catch(() => {}); .catch(() => {});
} }