From 760e8fff4d4fd71350ddc9b17e85e95a17d4ce8e Mon Sep 17 00:00:00 2001 From: Rasmus Date: Fri, 31 Mar 2023 19:41:34 +0300 Subject: oops --- rannak/mangud/arimees/pood/script.js | 83 ++++++++++++++++++++++++++++++------ 1 file changed, 71 insertions(+), 12 deletions(-) mode change 100755 => 100644 rannak/mangud/arimees/pood/script.js (limited to 'rannak/mangud/arimees/pood/script.js') diff --git a/rannak/mangud/arimees/pood/script.js b/rannak/mangud/arimees/pood/script.js old mode 100755 new mode 100644 index 8803bbe..5a48c84 --- a/rannak/mangud/arimees/pood/script.js +++ b/rannak/mangud/arimees/pood/script.js @@ -4,25 +4,84 @@ document.addEventListener('DOMContentLoaded', () => { }); -const selectors = document.querySelectorAll('select'); -for(el of selectors){ - el.addEventListener('change', () => { - let selected = new Array(); - for (el of selectors){ - if (!selected.includes(el.value) && el.value != 'Vali') - selected.push(el.value); +const cells = document.querySelectorAll("td"); + +for (let i=0;i < cells.length; i++){ + cells[i].onclick = function(){ + + if (this.hasAttribute('data-clicked')) + return; + + this.setAttribute('data-clicked', 'yes') + this.setAttribute('data-text', this.innerHTML) + + let input = document.createElement('input'); + input.setAttribute('type', 'text'); + input.value = this.innerHTML; + input.style.width = this.offsetWidth - (this.clientLeft * 2) + 'px'; + input.style.height = this.offsetHeight - (this.clientTop * 2) + 'px'; + input.style.border = '0px'; + input.fontFamily = 'inherit'; + input.fontSize = 'inherit'; + input.textAlign = 'inherit'; + input.style.backgroundColor = 'LightGoldenRodYellow'; + + + // On offclick + input.onblur = function(){ + let td = input.parentElement; + let origText = input.parentElement.getAttribute('data-text'); + let curText = this.value; + + if (origText != curText){ + td.removeAttribute('data-clicked'); + td.removeAttribute('data-text'); + td.innerHTML = curText; + td.style.cssText = 'padding: .5rem .5rem'; + + + // Can move on? + for (cell of cells){ + if (cell.textContent == '') + return; + } + moveOnEnable(); + } + else { + td.removeAttribute('data-clicked'); + td.removeAttribute('data-text'); + td.innerHTML = origText; + td.style.cssText = 'padding: .5rem .5rem'; + } + + + // Here Check if Done + //TODO + + + + } // onblur func end + + + input.onkeypress = function (){ + if (event.keyCode == 13) + this.onblur(); } - if (selected.length == 6) - moveOnEnable(); + this.innerHTML = ''; + this.style.cssText = 'padding: 0px'; + this.append(input); + this.firstElementChild.select(); - }); -} + + } // OnClick Loop +} //ForLoop + -// If All Else Done +// If All Done function moveOnEnable(){ const btn = document.querySelector(".moveOn"); -- cgit v1.2.3