mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-27 19:47:49 +01:00
Extracted insertElementBefore to domUtils.js
This commit is contained in:
parent
bf835c3b2e
commit
cacdc4641d
@ -0,0 +1,5 @@
|
||||
function insertElementBefore(elementSelector, createElementFunction) {
|
||||
const placeBefore = document.querySelector(elementSelector);
|
||||
const element = createElementFunction();
|
||||
placeBefore.insertAdjacentElement('beforebegin', element);
|
||||
}
|
@ -272,6 +272,7 @@ function runQuery() {
|
||||
}
|
||||
|
||||
function renderResultPath(json) {
|
||||
const gotResults = Boolean(json.data);
|
||||
let pathHtml = ``;
|
||||
for (let i = 0; i < json.path.length; i++) {
|
||||
const step = json.path[i];
|
||||
@ -282,12 +283,13 @@ function renderResultPath(json) {
|
||||
pathHtml += `<i class="fa fa-fw fa-filter"></i> ${step.kind} matched ${step.size} players</p>`
|
||||
}
|
||||
|
||||
const placeBefore = document.querySelector('.tab .row .card');
|
||||
const element = document.createElement('div');
|
||||
element.id = "result-path"
|
||||
element.classList.add("alert", "alert-warning", "shadow");
|
||||
element.innerHTML = pathHtml
|
||||
placeBefore.insertAdjacentElement('beforebegin', element);
|
||||
insertElementBefore('.tab .row .card', () => {
|
||||
const element = document.createElement('div');
|
||||
element.id = "result-path"
|
||||
element.classList.add("alert", gotResults ? "alert-success" : "alert-warning", "shadow");
|
||||
element.innerHTML = pathHtml;
|
||||
return element;
|
||||
});
|
||||
window.scrollTo(0, 0); // Scroll to top
|
||||
}
|
||||
|
||||
|
@ -311,6 +311,7 @@
|
||||
<script src="./js/sb-admin-2.js"></script>
|
||||
<script src="./js/xmlhttprequests.js"></script>
|
||||
<script src="./js/color-selector.js"></script>
|
||||
<script src="./js/domUtils.js"></script>
|
||||
|
||||
<!-- Page level plugins -->
|
||||
<script src="vendor/datatables/jquery.dataTables.min.js"></script>
|
||||
@ -328,14 +329,15 @@
|
||||
const filters = [];
|
||||
|
||||
if (location.search.includes("error=")) {
|
||||
const placeBefore = document.querySelector('.tab .row .card div');
|
||||
const element = document.createElement('alert');
|
||||
element.classList.add("alert", "alert-danger", "alert-dismissable", "show");
|
||||
element.innerHTML = `<span id="error-text"></span>
|
||||
insertElementBefore('.tab .row .card div', () => {
|
||||
const element = document.createElement('alert');
|
||||
element.classList.add("alert", "alert-danger", "alert-dismissable", "show");
|
||||
element.innerHTML = `<span id="error-text"></span>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>`
|
||||
placeBefore.insertAdjacentElement('beforebegin', element);
|
||||
return element;
|
||||
});
|
||||
document.getElementById('error-text').innerText = new URLSearchParams(location.search).get("error");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user