-
Notifications
You must be signed in to change notification settings - Fork 141
Add copy buttons to code blocks #629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,10 @@ code { | |
| word-break: normal; | ||
| } | ||
|
|
||
| pre { | ||
| position: relative; | ||
| } | ||
|
|
||
| pre.hljs > code { | ||
| background: none; | ||
| } | ||
|
|
@@ -19,7 +23,6 @@ pre > code.hljs { | |
| -webkit-background-clip: padding-box; /* for Safari */ | ||
| background: ghostwhite; | ||
| background-clip: padding-box; /* for IE9+, Firefox 4+, Opera, Chrome */ | ||
| border: 1px solid rgb(200, 200, 200); | ||
| border: 1px solid rgba(200, 200, 200, 0.3); | ||
| border-radius: 5px; | ||
| } | ||
|
|
@@ -52,6 +55,26 @@ kbd { | |
| color: #555; | ||
| } | ||
|
|
||
| pre .clipboard-icon { | ||
| position: absolute; | ||
| top: 4px; | ||
| z-index: 2; | ||
| cursor: pointer; | ||
| border: 1px solid transparent; | ||
| color: #ccc; | ||
| background-color: transparent; | ||
| height: 30px; | ||
| transition: all .25s ease-out; | ||
| } | ||
|
|
||
| pre .clipboard-icon:hover { | ||
| color: #555; | ||
| } | ||
|
|
||
| pre .clipboard-btn { | ||
| right: 10px; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems too much, it's noticeably further from the right than the top. |
||
| } | ||
|
|
||
| code.hljs.inline { | ||
| background: #f8f8f8; | ||
| color: #333; | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,10 +33,30 @@ function setupAnchors() { | |
| }); | ||
| } | ||
|
|
||
| function setupCopyButtonsForCodeBlocks() { | ||
| const clipboard = new ClipboardJS('.clipboard-btn', { | ||
| target(trigger) { | ||
| return trigger.parentNode.querySelector('code'); | ||
| }, | ||
| }); | ||
|
|
||
| clipboard.on('success', (e) => { | ||
| const clipboardBtn = jQuery(e.trigger); | ||
| clipboardBtn.removeClass('fa fa-clipboard'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| clipboardBtn.addClass('fa fa-clipboard-check'); | ||
| e.clearSelection(); | ||
| setTimeout(() => { | ||
| clipboardBtn.removeClass('fa fa-clipboard-check'); | ||
| clipboardBtn.addClass('fa fa-clipboard'); | ||
| }, 2000); | ||
| }); | ||
| } | ||
|
|
||
| function executeAfterMountedRoutines() { | ||
| flattenModals(); | ||
| scrollToUrlAnchorHeading(); | ||
| setupAnchors(); | ||
| setupCopyButtonsForCodeBlocks(); | ||
| } | ||
|
|
||
| function setupSiteNav() { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the attributes should be ordered alphabetically for CSS 🙂