Skip to content

Commit

Permalink
enhance(editor): confirm before reset (#2052)
Browse files Browse the repository at this point in the history
* enhance(editor): confirm before reset

* chore(editor): update reset copy

Co-authored-by: Brian Thomas Smith <[email protected]>
  • Loading branch information
caugner and bsmth authored Dec 20, 2024
1 parent c273d3c commit 73037f7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
11 changes: 10 additions & 1 deletion editor/js/editable-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,16 @@ import "../css/editable-css.css";
function handleResetEvents() {
const resetButton = document.getElementById("reset") as HTMLElement;

resetButton.addEventListener("click", () => {
resetButton.addEventListener("click", (event) => {
if (
!window.confirm(
"Are you sure you want to reset the editor?\nAny changes you have made will be lost.",
)
) {
event.preventDefault();
return;
}

exampleChoices.forEach((e, i) => {
const preEl = e.querySelector("pre") as HTMLElement;

Expand Down
13 changes: 12 additions & 1 deletion editor/js/editable-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,18 @@ import {
applyCode();
});

reset.addEventListener("click", () => window.location.reload());
reset.addEventListener("click", (event) => {
if (
!window.confirm(
"Are you sure you want to reset the editor?\nAny changes you have made will be lost.",
)
) {
event.preventDefault();
return;
}

window.location.reload();
});
} else {
console.warn(
`Feature ${exampleFeature} is not supported; code editor disabled.`,
Expand Down
13 changes: 12 additions & 1 deletion editor/js/editable-wat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,18 @@ import {
applyCode();
});

reset.addEventListener("click", () => window.location.reload());
reset.addEventListener("click", (event) => {
if (
!window.confirm(
"Are you sure you want to reset the editor?\nAny changes you have made will be lost.",
)
) {
event.preventDefault();
return;
}

window.location.reload();
});
} else {
console.warn(
`Feature ${
Expand Down
15 changes: 13 additions & 2 deletions editor/js/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,20 @@ import "../css/tabbed-editor.css";

header.addEventListener("click", (event) => {
const target = event.target as typeof header;
if (target.classList.contains("reset")) {
window.location.reload();
if (!target.classList.contains("reset")) {
return;
}

if (
!window.confirm(
"Are you sure you want to reset the editor?\nAny changes you have made will be lost.",
)
) {
event.preventDefault();
return;
}

window.location.reload();
});

htmlEditor.addEventListener("keyup", () => autoUpdate());
Expand Down

0 comments on commit 73037f7

Please sign in to comment.