Fixed tooltip styling

Also fixed problem with garbage being put in clipboard
when triggered repeatedly
This commit is contained in:
Michal Budzynski 2017-05-31 21:07:30 +02:00
parent e567d22f1c
commit dfc24bec01
3 changed files with 28 additions and 18 deletions

View File

@ -828,19 +828,22 @@ table thead td {
} }
} }
.tooltiptext { .tooltiptext {
position: absolute;
visibility: hidden; visibility: hidden;
background-color: #000;
color: #fff; color: #fff;
opacity: 0.8; background-color: #333;
-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)"; -webkit-transform: translateX(-50%);
filter: alpha(opacity=80); -moz-transform: translateX(-50%);
-o-transform: translateX(-50%);
-ms-transform: translateX(-50%);
transform: translateX(-50%); /* Center by moving tooltip 50% of its width left */
left: -8px; /* Half of the width of the icon */
top: -35px;
font-size: 0.8em;
text-align: center; text-align: center;
border-radius: 6px; border-radius: 6px;
padding: 5px 8px; padding: 5px 8px;
margin: 5px; margin: 5px;
left: -250%;
bottom: 100%;
position: absolute;
z-index: 1000; z-index: 1000;
} }
.tooltipped .tooltiptext { .tooltipped .tooltiptext {

View File

@ -197,28 +197,34 @@ $( document ).ready(function() {
run_rust_code(pre_block); run_rust_code(pre_block);
}); });
buttons.find(".clip-button").mouseout(function(e){ buttons.find(".clip-button").mouseout(function(e){
e.currentTarget.setAttribute('class', 'fa fa-copy clip-button'); hideTooltip(e.currentTarget);
}); });
}); });
var clipboardSnippets = new Clipboard('.clip-button', { var clipboardSnippets = new Clipboard('.clip-button', {
text: function(trigger) { text: function(trigger) {
hideTooltip(trigger);
return trigger.parentElement.parentElement.textContent; return trigger.parentElement.parentElement.textContent;
} }
}); });
clipboardSnippets.on('success', function(e) { clipboardSnippets.on('success', function(e) {
e.clearSelection(); e.clearSelection();
showTooltip(e, "Copied!"); showTooltip(e.trigger, "Copied!");
}); });
clipboardSnippets.on('error', function(e) { clipboardSnippets.on('error', function(e) {
showTooltip(e, "Clipboard error!"); showTooltip(e.trigger, "Clipboard error!");
}); });
}); });
function hideTooltip(elem) {
elem.firstChild.innerText="";
elem.setAttribute('class', 'fa fa-copy clip-button');
}
function showTooltip(elem, msg) { function showTooltip(elem, msg) {
elem.trigger.firstChild.innerText=msg; elem.firstChild.innerText=msg;
elem.trigger.setAttribute('class', 'fa fa-copy tooltipped'); elem.setAttribute('class', 'fa fa-copy tooltipped');
} }
function run_rust_code(code_block) { function run_rust_code(code_block) {

View File

@ -1,15 +1,16 @@
.tooltiptext { .tooltiptext {
position: absolute;
visibility: hidden; visibility: hidden;
background-color: black;
color: #fff; color: #fff;
opacity: 0.8; background-color: #333;
transform: translateX(-50%); /* Center by moving tooltip 50% of its width left */
left: -8px; /* Half of the width of the icon */
top: -35px;
font-size: 0.8em;
text-align: center; text-align: center;
border-radius: 6px; border-radius: 6px;
padding: 5px 8px; padding: 5px 8px;
margin: 5px; margin: 5px;
left: -250%;
bottom: 100%;
position: absolute;
z-index: 1000; z-index: 1000;
} }
.tooltipped .tooltiptext { .tooltipped .tooltiptext {