Skip to content

Commit

Permalink
add back/forward/refresh/print buttons to the toolbar in preview
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Sep 17, 2024
1 parent 3a768f6 commit 3847d36
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 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.2.2
Version: 0.2.3
Authors@R: c(
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
person()
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# CHANGES IN litedown VERSION 0.3

- Added back/forward/refresh/print buttons to the toolbar in the `litedown::roam()` preview interface.

# CHANGES IN litedown VERSION 0.2

Expand Down
15 changes: 7 additions & 8 deletions inst/resources/server.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
width: 100%;
order: -1;
}
.pencil, .save {
text-decoration: none;
font-size: 1.5em;
font-style: normal;
.buttons {
float: right;
margin-left: .5em;
}
li .pencil {
float: none;
a {
text-decoration: none;
font-size: 1.2em;
font-style: normal;
margin-left: .5em;
}
}
td .pencil {
font-size: inherit;
Expand Down
21 changes: 20 additions & 1 deletion inst/resources/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,27 @@
chapters.forEach(el => {
const u = el.dataset.source;
u && !el.querySelector('.pencil') &&
el.insertAdjacentHTML('afterbegin', `<a href="?path=${u}" title="Open ${u}">✎</a>`);
el.insertAdjacentHTML('afterbegin', `<span class="buttons"><a href="?path=${u}" title="Open ${u}">✎</a></span>`);
});
const nav = d.querySelector('.nav-path, .title h1');
const btn = d.createElement('span'); btn.className = 'buttons';
['back', 'forward', 'refresh', 'print'].forEach((action, i) => {
if (btn.querySelector(`.${action}`)) return;
const a = d.createElement('a');
a.href = '#'; a.title = action[0].toUpperCase() + action.slice(1); a.className = action;
a.innerText = ['←', '→', '⟳', '⧉'][i];
a.onclick = e => {
e.preventDefault();
action === 'print' ? window.print() : (
action === 'refresh' ? location.reload() : history[action]()
);
};
btn.append(a);
});
if (nav) {
nav.querySelectorAll('a[href="#"]').forEach(a => btn.append(a));
nav.append(btn);
}
// add classes and events to edit buttons
d.querySelectorAll('a[href]').forEach(a => {
if (a.innerText !== '✎' || a.classList.contains('pencil')) return;
Expand Down

0 comments on commit 3847d36

Please sign in to comment.