Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/counter.js')
-rw-r--r--src/modules/counter.js24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/modules/counter.js b/src/modules/counter.js
index 3438566..a4bd4b4 100644
--- a/src/modules/counter.js
+++ b/src/modules/counter.js
@@ -13,7 +13,7 @@ export default class Counter {
}
selector(troopNumber, allegiance) {
- return `use.counter${this.dataSelector(troopNumber, allegiance)}`;
+ return `.counter${this.dataSelector(troopNumber, allegiance)}`;
}
position(x, y) {
@@ -21,7 +21,7 @@ export default class Counter {
}
counterPosition(x, y) {
- return `use.counter[data-x="${x}"][data-x="${y}"]`;
+ return `.counter[data-x="${x}"][data-x="${y}"]`;
}
traceSelector(troopNumber, allegiance) {
@@ -29,19 +29,19 @@ export default class Counter {
}
getCounters() {
- return this.svg.querySelectorAll(`use[data-allegiance][data-number]:not(.clone)`);
+ return this.svg.querySelectorAll(`.counter[data-allegiance][data-number]:not(.clone)`);
}
getClones(al, n) {
- return this.svg.querySelectorAll(`use[data-allegiance="${al}"][data-number="${n}"].clone`);
+ return this.svg.querySelectorAll(`.counter.clone[data-allegiance="${al}"][data-number="${n}"]`);
}
getCounter(al, n) {
- return this.svg.querySelector(`use[data-allegiance="${al}"][data-number="${n}"]:not(.clone)`);
+ return this.svg.querySelector(`.counter[data-allegiance="${al}"][data-number="${n}"]:not(.clone)`);
}
getCounterAndClones(al, n) {
- return this.svg.querySelectorAll(`use[data-allegiance="${al}"][data-number="${n}"]`);
+ return this.svg.querySelectorAll(`.counter[data-allegiance="${al}"][data-number="${n}"]`);
}
getTrace({ dataset: { allegiance, number } }) {
@@ -247,7 +247,7 @@ export default class Counter {
selected.parentElement.parentElement.dataset.y
]
- let clone = selected.cloneNode();
+ let clone = selected.cloneNode(true);
clone.classList.remove(selectedClass);
clone.classList.add('clone');
@@ -255,12 +255,6 @@ export default class Counter {
selected.parentElement.appendChild(clone);
point.parentElement.appendChild(selected);
- console.log(this.getCounterAndClones(troopAllegiance, troopNumber));
-
- if (clone.parentElement.querySelector('[href="#counter-prone"]')) {
- this.toggleProne();
- }
-
let previous = this.getCellPosition(clone.parentElement),
current = this.getCellPosition(selected.parentElement);
@@ -331,14 +325,14 @@ export default class Counter {
isOnBoard = selected && selected.parentElement.hasAttribute('data-x');
if (selected && isOnBoard) {
- const proneCounter = selected.parentElement.querySelector('[href="#counter-prone"]');
+ const proneCounter = selected.querySelector('[href="#counter-prone"]');
if (proneCounter) {
proneCounter.remove();
} else {
const counter = document.createElementNS(svgns, 'use');
counter.setAttributeNS(null, 'href', '#counter-prone');
- selected.parentElement.appendChild(counter);
+ selected.appendChild(counter);
}
}
}