File size: 1,044 Bytes
39aba6e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class ButtonTextPair {
    constructor(btnId, btnTextId, clickMsg = 'Well, this was a nice test!') {
        this.btnId = btnId;
        this.btnTextId = btnTextId;
        this.clickMsg = clickMsg;

        this.initBtn();
    }

    get btn() {
        return document.getElementById(this.btnId);
    }

    get btnText() {
        return document.getElementById(this.btnTextId);
    }

    initBtn() {
        this.clearMsg();
        this.btn.addEventListener('mousedown', e => this.writeMsg());
        this.btn.addEventListener('mouseup', e => this.clearMsg());
        this.btn.addEventListener('mouseout', e => this.clearMsg());
    }

    clearMsg() {
        this.btnText.className = 'test_button_text_empty';
        this.btnText.innerHTML = '';
    }

    writeMsg() {
        this.btnText.className = 'test_button_text';
        this.btnText.innerHTML = this.clickMsg;
    }
}

var pair1 = new ButtonTextPair('btn1', 'btn1_text', 'Well, this was a nice test.');
var pair1 = new ButtonTextPair('btn2', 'btn2_text', 'This is fun.');