Skip to content

Commit

Permalink
Update dialog.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nuxodin committed Mar 24, 2023
1 parent c6ac005 commit 56a1da4
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ if (!window.HTMLDialogElement) {
if (returnValue!=null) activeDialog.returnValue = returnValue;
activeDialog = null;
this.__lastActiveElement?.focus();
let event = new Event('close',{bubbles:false})
const event = new Event('close',{bubbles:false})
this.dispatchEvent(event);
}
Object.defineProperty(proto, 'open', {
Expand All @@ -63,25 +63,6 @@ if (!window.HTMLDialogElement) {
}
})

function preventBlurListener(e){
if (!e.relatedTarget) return;
if (!activeDialog.contains(e.relatedTarget)) {
setTimeout(()=>{
e.target.focus();
})
}
}
function escListener(e){
if (e.key === "Escape") {
let event = new Event('cancel',{bubbles:true,cancelable:true})
activeDialog.dispatchEvent(event);
if (!event.defaultPrevented) {
activeDialog.close();
}
}
}


document.addEventListener('submit',e=>{
if (e.target.getAttribute('method') !== 'dialog') return;
e.preventDefault();
Expand Down Expand Up @@ -129,3 +110,21 @@ if (!window.HTMLDialogElement) {
document.head.insertAdjacentHTML('afterbegin','<style>'+css+'</style>');

}

function preventBlurListener(e){
if (!e.relatedTarget) return;
if (!activeDialog.contains(e.relatedTarget)) {
setTimeout(()=>{
e.target.focus();
})
}
}
function escListener(e){
if (e.key === "Escape") {
const event = new Event('cancel',{bubbles:true,cancelable:true})
activeDialog.dispatchEvent(event);
if (!event.defaultPrevented) {
activeDialog.close();
}
}
}

0 comments on commit 56a1da4

Please sign in to comment.