Skip to content

Commit

Permalink
use <dialog> to show messages instead of alert() or <pre>; also suppr…
Browse files Browse the repository at this point in the history
…ess the 'connection reset by peer' error
  • Loading branch information
yihui committed Aug 6, 2024
1 parent 9a78b21 commit c227c86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: litedown
Type: Package
Title: A Lightweight Version of R Markdown
Version: 0.0.36
Version: 0.0.37
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person()
Expand Down
2 changes: 1 addition & 1 deletion inst/resources/server.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ td .pencil {
span[data-line-number] {
cursor: pointer;
}
.waiting {
::backdrop {
cursor: wait;
opacity: .5;
}
Expand Down
21 changes: 16 additions & 5 deletions inst/resources/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
req.send();
req.onload = callback;
}
function show_dialog(resp) {
let el = d.querySelector('dialog.litedown-dialog');
if (!el) {
el = d.createElement('dialog');
el.className = 'litedown-dialog';
el.innerHTML = '<p></p><button>OK</button>';
el.querySelector('button').onclick = e => el.close();
d.body.append(el);
}
const p = el.firstElementChild;
p.innerText = resp.responseText; if (resp.status !== 200) p.className = 'error';
el.showModal();
}
// remove empty frontmatter
const fm = d.querySelector('.frontmatter');
if (fm && !fm.innerText) fm.remove();
Expand Down Expand Up @@ -36,7 +49,7 @@
if (cls.contains('waiting')) return;
cls.add('waiting');
new_req(a.href, 'save', e => {
alert(e.target.responseText);
show_dialog(e.target);
cls.remove('waiting');
});
};
Expand All @@ -52,10 +65,8 @@
new_req(u, q ? (a ? 'asset' : `book:${el.dataset[s]}`) : 'page', e => {
const res = e.target.responseText;
if (e.target.status !== 200) {
el.innerHTML = `<pre><code class="error">${res}</code></pre>`;
return;
}
if (res !== '') {
if (res.toLowerCase() != 'connection reset by peer') show_dialog(e.target);
} else if (res !== '') {
if (a) {
el[a] = `${u.replace(/[?].*/, '')}?timestamp=${+new Date()}`;
el.tagName ==='SCRIPT' && update_script(el);
Expand Down

0 comments on commit c227c86

Please sign in to comment.