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

@ -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(){