1
0
Fork 0
mirror of https://github.com/haselkern/Minecraft-ArmorStand.git synced 2025-05-17 15:05:33 +00:00

Click to copy code

This commit is contained in:
Lars Martens 2017-06-14 10:07:03 +02:00
parent 7ab69d7a42
commit 99bc954931
3 changed files with 42 additions and 1 deletions

View file

@ -217,7 +217,10 @@
</div>
</div>
<div id="code" class="code"></div>
<div class="code">
<div id="code-copy-hint">click to copy</div>
<div id="code"></div>
</div>
<div id="codeinfo" class="padding">
<b>Please note:</b>
This command is too long to be executed from chat. You need to place it inside a command block. (see below)

View file

@ -80,6 +80,32 @@ Point = {
y:null
};
jQuery.fn.selectAndCopyText = function(){
// https://stackoverflow.com/a/9976413/1456971
this.find('input').each(function() {
if($(this).prev().length == 0 || !$(this).prev().hasClass('p_copy')) {
$('<p class="p_copy" style="position: absolute; z-index: -1;"></p>').insertBefore($(this));
}
$(this).prev().html($(this).val());
});
var doc = document;
var element = this[0];
if (doc.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
document.execCommand("copy");
};
$(document).ready(function(){
//Init
setup();
@ -90,6 +116,11 @@ $(document).ready(function(){
window.onbeforeunload = function(){
return "Changes will NOT be saved. Exit anyways?";
};
// Copy code on click
$(".code").click(function(){
$("#code").selectAndCopyText();
});
//Stuff to handle and update input
$("input").on("input", function(){

View file

@ -78,6 +78,13 @@ input[type="text"]:not(:last-child){
border-radius: 3px;
color: #ffffff;
}
#code-copy-hint{
font-family: sans-serif;
font-style: italic;
font-size: 0.8em;
text-align: right;
opacity: 0.6;
}
#disabledslots{
display: block;