Skip to content

Commit

Permalink
state and selected styling update - steadily making it more DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
VirtualDOMinic committed Sep 5, 2018
1 parent df34fda commit 99fffaa
Showing 1 changed file with 48 additions and 1 deletion.
49 changes: 48 additions & 1 deletion script.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ stopwatchAreaListener = function(){
console.log("stopwatchAreaListener")
document.getElementById("stopwatch-area").addEventListener("click", function(x) {
if(x.target.id.includes("presenter")){
drySelector(x.target)
/*
x.target.parentElement.childNodes.forEach(y => {
if(x.target.id !== y.id){
y.classList.remove("selected")
Expand All @@ -148,12 +150,20 @@ stopwatchAreaListener = function(){
selectUserForTimer(y.id)
}
})
*/
}
else if(x.target.nodeName.toLowerCase() === "button"){
/* else */ if(x.target.nodeName.toLowerCase() === "button"){
console.log("button clicked!")
if(x.target.innerText === "select"){
x.target.innerText = "deselect"
} else {
x.target.innerText = "select"
}

if(x.target.innerText === "deselect"){
console.log("deselect initiated")
}

x.target.parentElement.parentElement.childNodes.forEach(function(y){
if(x.target.parentElement.id !== y.id){
y.classList.remove("selected")
Expand Down Expand Up @@ -204,11 +214,13 @@ function createPeopleTest(i) {
presenterDiv.id = "presenter_" + i;
presenterName.innerText = timerState["presenter_" + i].name;
timerButton.innerText = "select";
/*
timerButton.onclick = function(e) {
var userSel = e.target.parentElement.id;
updateButtonText(userSel, timerState.userSelected);
// selectUserForTimer(userSel);
};
*/
presenterDiv.appendChild(presenterName);
presenterDiv.appendChild(timerButton);
stopwatchArea.appendChild(presenterDiv);
Expand Down Expand Up @@ -250,6 +262,7 @@ formatTime = function(ms) {
console.log(Math.floor(mins) + "m:" + secs + "s");
};

/*
updateButtonText = function(selected, prevSelected) {
// e.g. selected = "person_2", prevSelected = "person_0"
console.log("Run: updateButtonText");
Expand All @@ -267,6 +280,14 @@ updateButtonText = function(selected, prevSelected) {
.getElementsByTagName("button")[0].innerText = "select";
}
};
*/

/*
updateButtonTextHelper = function(a, b) {
// this is to replace the "updateButtonText" function, for use inside "stopwatchAreaListener"
}
*/

//
//
Expand Down Expand Up @@ -297,3 +318,29 @@ function createSecondForm(ppl, time) {
}
*/


// CODE IS WAY TOO WET! Below, I should make a function to update the div style, button text and userSelected, with inputs being:
// name of div, id of div?
function drySelector(divClicked){
console.log("drySelector called");
divClicked.parentElement.childNodes.forEach(function(div){
if(div.id === divClicked.id){
if(div.id === timerState.userSelected){
div.classList.remove("selected");
div.classList.add("normal");
div.getElementsByTagName("button")[0].innerText = "select";
timerState.userSelected = undefined;
} else {
div.classList.remove("normal");
div.classList.add("selected");
div.getElementsByTagName("button")[0].innerText = "deselect";
timerState.userSelected = div.id;
}
} else {
div.classList.remove("selected");
div.classList.add("normal");
div.getElementsByTagName("button")[0].innerText = "select";
}
})
}

0 comments on commit 99fffaa

Please sign in to comment.