Browse Source

Add copy-code button

master
Huu Lane 6 months ago
parent
commit
96a002c85b
3 changed files with 35 additions and 0 deletions
  1. 19
    0
      layout/_partial/scripts.ejs
  2. 9
    0
      source/css/style.styl
  3. 7
    0
      source/lib/clipboard/clipboard.min.js

+ 19
- 0
layout/_partial/scripts.ejs View File

@@ -1,7 +1,26 @@
<!-- jquery -->
<%- js('lib/jquery/jquery.min') %>
<%- js('lib/justified-gallery/js/jquery.justifiedGallery.min.js') %>
<!-- clipboard -->
<% if (is_post()){ %>
<%- js('lib/clipboard/clipboard.min') %>
<script type="text/javascript">
$(function(){
var btn = '<i class="btn-copy far fa-clone"></i>';
$(".highlight .code pre").before(btn);
var clip = new ClipboardJS('.btn-copy', {
target: function(trigger) {
return trigger.nextElementSibling;
}
});
clip.on('success', function(e) {
e.clearSelection();
})
})
</script>
<% } %>
<%- js('js/main') %>

<!-- search -->
<% if (config.search && (page.search || page.type === "search")){ %>
<%- js('js/search.js') %>

+ 9
- 0
source/css/style.styl View File

@@ -180,6 +180,15 @@ code
&:after
clear: both

:hover .btn-copy
opacity: 1

.btn-copy
font-size: 1.2rem;
position: absolute
right: 20px
opacity: 0

pre
padding: 0
border: none

+ 7
- 0
source/lib/clipboard/clipboard.min.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save