summaryrefslogtreecommitdiff
path: root/rannak/mangud/arimees/pood/script.js
blob: 985255ec75a0eea69cd95636fec18d9c71e44f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
document.addEventListener('DOMContentLoaded', () => {
    let btn = document.querySelector('.modalButton');
    btn.click();
});




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;

            sums = document.querySelectorAll(".summa");
            console.log(sums);

            if (origText != curText){
                td.removeAttribute('data-clicked');
                td.removeAttribute('data-text');
                td.innerHTML = curText;
                td.style.cssText = 'padding: .5rem .5rem';


                totalSumma = 0; 
                sums.forEach(el => {
                    totalSumma += Number(el.innerHTML);
                });
                // Can move on?
                for (cell of cells){
                    if (totalSumma >= 12000) 
                        moveOnEnable();
                    else if (cell.textContent == '')
                            return;
                }
                moveOnEnable();
            }
            
            else {
                td.removeAttribute('data-clicked');
                td.removeAttribute('data-text');
                td.innerHTML = origText;
                td.style.cssText = 'padding: .5rem .5rem';

                sums.forEach(el => {
                    console.log(el); 
                });
            }


        } // onblur func end


        input.onkeypress = function (){
            if (event.keyCode == 13)
                this.onblur();
        }

        this.innerHTML = '';
        this.style.cssText = 'padding: 0px';
        this.append(input);
        this.firstElementChild.select();
        

    } // OnClick Loop
} //ForLoop



// If All Done

function moveOnEnable(){
    const btn = document.querySelector(".moveOn");
    btn.disabled = false;
    btn.onclick = () => location.href = "../muusika";
}