Spaces:
Sleeping
Sleeping
| 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.'); | |