forked from nostr/nostrweb
refactor: global click listener and cleanup
breaking up the global click callback to make it easier in the future to move some parts into ui modules such as settings.ts.
parent
52e2a31421
commit
9a34d4f31e
43
src/main.js
43
src/main.js
|
@ -483,22 +483,6 @@ writeInput.addEventListener('input', () => {
|
|||
});
|
||||
writeInput.addEventListener('blur', () => sendStatus.textContent = '');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
document.body.onload = () => console.log('------------ pageload ------------')
|
||||
|
||||
|
||||
|
||||
// subscribe and change view
|
||||
function route(path) {
|
||||
if (path === '/') {
|
||||
|
@ -532,11 +516,7 @@ window.addEventListener('popstate', (event) => {
|
|||
|
||||
const publishView = document.querySelector('#newNote');
|
||||
|
||||
document.body.addEventListener('click', (e) => {
|
||||
const a = e.target.closest('a');
|
||||
const pubkey = e.target.closest('[data-pubkey]')?.dataset.pubkey;
|
||||
const id = e.target.closest('[data-id]')?.dataset.id;
|
||||
if (a) {
|
||||
const handleLink = (e, a) => {
|
||||
if ('nav' in a.dataset) {
|
||||
e.preventDefault();
|
||||
closeSettingsView();
|
||||
|
@ -548,10 +528,10 @@ document.body.addEventListener('click', (e) => {
|
|||
history.pushState({}, null, href);
|
||||
e.preventDefault();
|
||||
}
|
||||
return;
|
||||
}
|
||||
const button = e.target.closest('button');
|
||||
if (button) {
|
||||
};
|
||||
|
||||
const handleButton = (e, button) => {
|
||||
const id = e.target.closest('[data-id]')?.dataset.id;
|
||||
switch(button.name) {
|
||||
case 'reply':
|
||||
if (localStorage.getItem('reply_to') === id) {
|
||||
|
@ -588,13 +568,24 @@ document.body.addEventListener('click', (e) => {
|
|||
publishView.hidden = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// const container = e.target.closest('[data-append]');
|
||||
// if (container) {
|
||||
// container.append(...parseTextContent(container.dataset.append));
|
||||
// delete container.dataset.append;
|
||||
// return;
|
||||
// }
|
||||
};
|
||||
|
||||
document.body.addEventListener('click', (e) => {
|
||||
const a = e.target.closest('a');
|
||||
if (a) {
|
||||
handleLink(e, a);
|
||||
return;
|
||||
}
|
||||
const button = e.target.closest('button');
|
||||
if (button) {
|
||||
handleButton(e, button);
|
||||
}
|
||||
});
|
||||
|
||||
// document.body.addEventListener('keyup', (e) => {
|
||||
|
|
Loading…
Reference in New Issue