Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/counter.js')
-rw-r--r--src/modules/counter.js44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/modules/counter.js b/src/modules/counter.js
index de393a0..162e56e 100644
--- a/src/modules/counter.js
+++ b/src/modules/counter.js
@@ -6,8 +6,6 @@ export default class Counter {
constructor(svg, container) {
this.svg = svg;
this.container = container;
-
- this.getCounters().forEach(c => this.addEventListeners(c));
}
dataSelector(troopNumber, allegiance) {
@@ -60,13 +58,6 @@ export default class Counter {
return pt;
}
- addEventListeners(counter) {
- counter.addEventListener('pointerover', this.pointerOver.bind(this));
- counter.addEventListener('pointerout', this.pointerOut.bind(this));
- counter.addEventListener('click', this.click.bind(this));
- // counter.addEventListener('dblclick', dblClick);
- }
-
pointerOver(e) {
const { number: troopNumber, allegiance: troopAllegiance } = e.target.dataset,
cp = this.svg.querySelector(`#clip-path-${troopAllegiance}-${troopNumber}`);
@@ -245,32 +236,33 @@ export default class Counter {
troopAllegiance = selected.dataset.allegiance,
troopNumber = selected.dataset.number;
- let counter, points,
+ let points,
counterNodeList = this.getCounterAndClones(troopAllegiance, troopNumber);
if (counterNodeList.length > 0 && selected.parentElement.hasAttribute('data-x')) {
- let counters = Array.from(counterNodeList),
- original = counters.find(el => !el.classList.contains('clone')),
- trace = this.svg.querySelector(this.traceSelector(troopNumber, troopAllegiance));
+ let trace = this.svg.querySelector(this.traceSelector(troopNumber, troopAllegiance));
+
+ let prevCoords = [
+ selected.parentElement.dataset.x,
+ selected.parentElement.parentElement.dataset.y
+ ]
- counter = original.cloneNode();
- counter.setAttributeNS(null, 'x', 0);
- counter.setAttributeNS(null, 'y', 0);
- counter.classList.remove(selectedClass);
- counter.classList.add('clone');
+ let clone = selected.cloneNode();
+ clone.classList.remove(selectedClass);
+ clone.classList.add('clone');
- original.setAttributeNS(null, 'x', 0);
- original.setAttributeNS(null, 'y', 0);
+ selected.dataset.previous = prevCoords;
+ selected.parentElement.appendChild(clone);
+ point.parentElement.appendChild(selected);
- original.parentElement.appendChild(counter);
- point.parentElement.appendChild(original);
+ console.log(this.getCounterAndClones(troopAllegiance, troopNumber));
- if (counter.parentElement.querySelector('[href="#counter-prone"]')) {
+ if (clone.parentElement.querySelector('[href="#counter-prone"]')) {
this.toggleProne();
}
- let previous = this.getCellPosition(counter.parentElement),
- current = this.getCellPosition(original.parentElement);
+ let previous = this.getCellPosition(clone.parentElement),
+ current = this.getCellPosition(selected.parentElement);
if (!trace) {
trace = document.createElementNS(svgns, 'polyline');
@@ -287,7 +279,7 @@ export default class Counter {
}
trace.setAttributeNS(null, 'points', points);
- counter.addEventListener('click', this.clickClone.bind(this));
+ // clone.addEventListener('click', this.clickClone.bind(this));
} else {
selected.removeAttribute('data-x');
point.parentElement.appendChild(selected);