Commit 60ee877f authored by Jorge Aguilera's avatar Jorge Aguilera 📚

add clipboardjs to all listingblocks

parent ee85fb5b
Pipeline #41088668 passed with stages
in 2 minutes and 33 seconds
.asciidoctorcopypaste {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABVUlEQVQ4T+2TO0gDQRBAZ+YuwRTa+OkEwUrE0pyVriBYxCgKQexFLSJYm8rOTitjob1wiHAxFopkUwgeaay0sLMQtVQkQnI7sgcLcQuj2DrV/PbtzM4sgiW5XM55eKmfA+K9HWOA4UQCF68ugkcTQztJCOHWoWs3lEHejnli1kdkdlzcMJAYkJ7MTCPTkNYRmRTjPAIca1tBdFSTZ09a90R2nx23QKpZNJAY4E3MHEbIO/aNDtOWYmCgKK8hnsieAMAzMnQy4XtYCVZiwJjIHFzL8rIN0H5KJjcbH809AzE5uppQltbaAhQ4N4iqDxQvhNXyCACwaactYHR8rh+o0a0PELiFFLwuSSmbPwa0tqRLTsFb/h/wxzdg5KJijuKNZVqvVUur3+6BPQVEvlVMSvsZ1V2tcnr5K0DrGL/8xrTIbhOoHnuVW+0IaHCgt2PK9/24BSOfXnvqEcWHX5oAAAAASUVORK5CYII=) no-repeat top left;
border: none;
}
.asciidoctorcopypaste:focus {
outline: 0;
}
......@@ -12,3 +12,4 @@
@import "header.css";
@import "footer.css";
@import "highlight.css";
@import "clipboard.css";
; (function () {
'use strict'
/* global ClipboardJS */
function addBlockClipboard () {
// inject .asciidoctorcopypaste class to all .listingblock
find('.listingblock', document).forEach(function (item, idx) {
if (!item.getAttribute('id')) {
item.setAttribute('id', 'listingblock' + (idx++))
}
createBlockClipboard(item)
})
try {
var clipboard = new ClipboardJS('.asciidoctorcopypaste')
clipboard.on('success', function (e) {
var element = e.trigger
element.innerHTML = '   Copied!'
setTimeout(function () {
element.innerHTML = ' '
}, 1000)
e.clearSelection()
})
} catch (e) {
console.log(e)
}
}
function createBlockClipboard (block) {
find('.content', block).forEach(function (content) {
var id = block.getAttribute('id') + '_content'
content.setAttribute('id', id)
var str = '<button class="asciidoctorcopypaste" id="' +
id + '-copy-button" data-clipboard-target="#' +
id + '">&nbsp;</button>'
var title = find('.title', block)
if (title.length) {
title[0].innerHTML = title[0].innerHTML + '&nbsp;&nbsp;' + str
} else {
content.innerHTML = str + content.innerHTML
}
})
}
function find (selector, from) {
return [].slice.call((from || document).querySelectorAll(selector))
}
addBlockClipboard()
})()
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.0/clipboard.min.js"></script>
<script src="{{uiRootPath}}/js/site.js"></script>
<script src="{{uiRootPath}}/js/vendor/highlight.js"></script>
<script>hljs.initHighlighting()</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment