Skip to content

Commit 78a350c

Browse files
authored
bs4_book: Copy button uses an icon instead of text (#1192)
1 parent 28b11a4 commit 78a350c

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# CHANGES IN bookdown VERSION 0.23
22

3+
- In `bs4_book()`, copy button has now a light icon instead of a text with white background (#1192).
4+
35
- Fix an issue with `bs4_book()` where text written using [Line Block](https://bookdown.org/yihui/rmarkdown-cookbook/indent-text.html) was not found in search (thanks, @dmklotz, #1141).
46

57
- `bs4_book()` has now some `<meta>` tags that allows sharing a published book on social media. `cover-image`, `url`, `title` and `description` set in YAML will be used in `index.html` and then modified to be adapted per HTML page (#1034).

inst/resources/bs4_book/bs4_book.css

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,34 @@ code a:any-link {
392392
text-decoration-color: #ccc;
393393
}
394394

395+
/* copy button */
396+
395397
pre .copy {
396398
position: absolute;
397399
top: 0.5rem;
398400
right: 0.5rem;
399401
}
402+
400403
pre .copy button {
401-
background-color: #fff;
402404
font-size: 80%;
403405
padding: 4px 6px;
404406
}
405407

408+
pre .copy > button > i.bi::before {
409+
display: inline-block;
410+
height: 1rem;
411+
width: 1rem;
412+
content: "";
413+
vertical-align: -0.125em;
414+
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M4 1.5H3a2 2 0 0 0-2 2V14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V3.5a2 2 0 0 0-2-2h-1v1h1a1 1 0 0 1 1 1V14a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3.5a1 1 0 0 1 1-1h1v-1z"/><path d="M9.5 1a.5.5 0 0 1 .5.5v1a.5.5 0 0 1-.5.5h-3a.5.5 0 0 1-.5-.5v-1a.5.5 0 0 1 .5-.5h3zm-3-1A1.5 1.5 0 0 0 5 1.5v1A1.5 1.5 0 0 0 6.5 4h3A1.5 1.5 0 0 0 11 2.5v-1A1.5 1.5 0 0 0 9.5 0h-3z"/></svg>');
415+
background-repeat: no-repeat;
416+
background-size: 1rem 1rem;
417+
}
418+
419+
pre .copy > button.btn-copy-checked > .bi::before {
420+
background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg>');
421+
}
422+
406423
/* https://github.com/rstudio/distill/blob/master/inst/rmarkdown/templates/distill_article/resources/a11y.theme + https://gist.github.com/hadley/f53b6e92df20994fdabe6562d284728a */
407424
code span.ot {color:#007faa}
408425
code span.at {color:#7d9029}

inst/resources/bs4_book/bs4_book.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function changeTooltipMessage(element, msg) {
107107
$(document).ready(function() {
108108
if(ClipboardJS.isSupported()) {
109109
// Insert copy buttons
110-
var copyButton = "<div class='copy'><button type='button' class='btn btn-outline-primary btn-copy' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='popover' data-placement='top' data-trigger='hover'>Copy</button></div>";
110+
var copyButton = "<div class='copy'><button type='button' class='btn btn-copy' title='Copy to clipboard' aria-label='Copy to clipboard' data-toggle='popover' data-placement='top' data-trigger='hover'><i class='bi'></i></button></div>";
111111
$(copyButton).appendTo("pre");
112112
// Initialize tooltips:
113113
$('.btn-copy').tooltip({container: 'body', boundary: 'window'});
@@ -120,7 +120,12 @@ $(document).ready(function() {
120120
});
121121

122122
clipboard.on('success', function(e) {
123-
changeTooltipMessage(e.trigger, 'Copied!');
123+
const btn = e.trigger;
124+
changeTooltipMessage(btn, 'Copied!');
125+
btn.classList.add('btn-copy-checked');
126+
setTimeout(function() {
127+
btn.classList.remove('btn-copy-checked');
128+
}, 2000);
124129
e.clearSelection();
125130
});
126131

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy