From c7e4774fba123f51f28995fa78fc25efa447d3eb Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Wed, 20 Sep 2017 18:12:16 -0400 Subject: [PATCH] Set correct name when updating pile text --- script.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index d6f769a..e4d9aa4 100644 --- a/script.js +++ b/script.js @@ -58,18 +58,19 @@ interact('.card-pile') .dropzone({ accept: '.card', ondrop: event => { - let pile = piles[event.target.getAttribute('data-pile')]; - pile.push(event.relatedTarget.getAttribute('data-num')); + let pileName = event.target.getAttribute('data-pile'); + piles[pileName].push(event.relatedTarget.getAttribute('data-num')); event.relatedTarget.parentElement.removeChild(event.relatedTarget); // update deck text - event.target.innerHTML = `DECK
${pile.length}/${cardCount}`; + event.target.innerHTML = `${pileName.toUpperCase()}
${piles[pileName].length}/${cardCount}`; } }) .draggable({manualStart: true}) .on('move', event => { let interaction = event.interaction; - let pile = piles[event.target.getAttribute('data-pile')]; + let pileName = event.target.getAttribute('data-pile'); + let pile = piles[pileName]; // if the pointer was moved while being held down // and an interaction hasn't started yet @@ -92,7 +93,7 @@ interact('.card-pile') document.querySelector("#card-container").appendChild(newCard); // update deck text - event.target.innerHTML = `DECK
${pile.length}/${cardCount}`; + event.target.innerHTML = `${pileName.toUpperCase()}
${pile.length}/${cardCount}`; // start a drag interaction targeting the clone interaction.start({name: 'drag'}, cardInteract, newCard);