Skip to content

Commit

Permalink
Only associate buttons' onClick when they exist.
Browse files Browse the repository at this point in the history
(to allow removing them)
  • Loading branch information
lapo-luchini committed Apr 29, 2024
1 parent f2f3e2a commit f4fc630
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,19 @@ export function decodeBinaryString(str) {
}
}
// set up buttons
id('butDecode').onclick = function () {
const butClickHandlers = {
butDecode: () => {
decodeText(area.value);
};
id('butClear').onclick = function () {
},
butClear: () => {
area.value = '';
file.value = '';
tree.innerHTML = '';
dump.innerHTML = '';
selectDefs.innerHTML = '';
hash = window.location.hash = '';
};
id('butExample').onclick = function () {
},
butExample: () => {
console.log('Loading example:', examples.value);
let request = new XMLHttpRequest();
request.open('GET', 'examples/' + examples.value, true);
Expand All @@ -150,7 +151,13 @@ id('butExample').onclick = function () {
}
};
request.send();
},
};
for (const [name, onClick] of Object.entries(butClickHandlers)) {
let elem = id(name);
if (elem)
elem.onclick = onClick;
}
// set dark theme depending on OS settings
function setTheme() {
let storedTheme = localStorage.getItem('theme');
Expand Down

0 comments on commit f4fc630

Please sign in to comment.