Initial implementation of clipboard handling

This commit is contained in:
Michal Budzynski 2017-05-31 01:14:01 +02:00
parent bfc3fbb405
commit e567d22f1c
5 changed files with 60 additions and 0 deletions

View File

@ -827,3 +827,22 @@ table thead td {
word-wrap: break-word /* Internet Explorer 5.5+ */; word-wrap: break-word /* Internet Explorer 5.5+ */;
} }
} }
.tooltiptext {
visibility: hidden;
background-color: #000;
color: #fff;
opacity: 0.8;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
filter: alpha(opacity=80);
text-align: center;
border-radius: 6px;
padding: 5px 8px;
margin: 5px;
left: -250%;
bottom: 100%;
position: absolute;
z-index: 1000;
}
.tooltipped .tooltiptext {
visibility: visible;
}

View File

@ -191,15 +191,35 @@ $( document ).ready(function() {
buttons = pre_block.find(".buttons"); buttons = pre_block.find(".buttons");
} }
buttons.prepend("<i class=\"fa fa-play play-button\"></i>"); buttons.prepend("<i class=\"fa fa-play play-button\"></i>");
buttons.prepend("<i class=\"fa fa-copy clip-button\"><i class=\"tooltiptext\"></i></i>");
buttons.find(".play-button").click(function(e){ buttons.find(".play-button").click(function(e){
run_rust_code(pre_block); run_rust_code(pre_block);
}); });
buttons.find(".clip-button").mouseout(function(e){
e.currentTarget.setAttribute('class', 'fa fa-copy clip-button');
});
}); });
var clipboardSnippets = new Clipboard('.clip-button', {
text: function(trigger) {
return trigger.parentElement.parentElement.textContent;
}
});
clipboardSnippets.on('success', function(e) {
e.clearSelection();
showTooltip(e, "Copied!");
});
clipboardSnippets.on('error', function(e) {
showTooltip(e, "Clipboard error!");
});
}); });
function showTooltip(elem, msg) {
elem.trigger.firstChild.innerText=msg;
elem.trigger.setAttribute('class', 'fa fa-copy tooltipped');
}
function run_rust_code(code_block) { function run_rust_code(code_block) {
var result_block = code_block.find(".result"); var result_block = code_block.find(".result");

View File

@ -24,6 +24,9 @@
<!-- MathJax --> <!-- MathJax -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- Clipboard.js -->
<script src="https://cdn.jsdelivr.net/clipboard.js/1.6.1/clipboard.min.js"></script>
<!-- Fetch JQuery from CDN but have a local fallback --> <!-- Fetch JQuery from CDN but have a local fallback -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script> <script>

View File

@ -8,3 +8,4 @@
@import 'theme-popup' @import 'theme-popup'
@import 'themes' @import 'themes'
@import 'print' @import 'print'
@import 'tooltip'

View File

@ -0,0 +1,17 @@
.tooltiptext {
visibility: hidden;
background-color: black;
color: #fff;
opacity: 0.8;
text-align: center;
border-radius: 6px;
padding: 5px 8px;
margin: 5px;
left: -250%;
bottom: 100%;
position: absolute;
z-index: 1000;
}
.tooltipped .tooltiptext {
visibility: visible;
}