Fix copying on IE8
This commit is contained in:
parent
eb21cd3496
commit
8aee61c01c
@ -37,6 +37,10 @@ if (!document.head) {
|
||||
document.head = document.getElementsByTagName("head")[0];
|
||||
}
|
||||
|
||||
if (!window.HTMLPictureElement) {
|
||||
document.createElement("picture");
|
||||
}
|
||||
|
||||
function toArray(iter) {
|
||||
var arr = [];
|
||||
for (var i = 0; i < iter.length; i++) arr.push(iter[i]);
|
||||
|
@ -5,12 +5,13 @@ window.addEventListener("load", function() {
|
||||
for (var i = 0; i < codes.length; i++) {
|
||||
|
||||
var code = codes[i];
|
||||
var input = code.children[1].children[0];
|
||||
var input = code.getElementsByTagName("input")[0];
|
||||
|
||||
// Select all in input when clicked
|
||||
input.onclick = function(event) {
|
||||
console.log(event);
|
||||
inputSelectAll(event.target);
|
||||
input.onclick = function(e) {
|
||||
var event = e || window.event;
|
||||
var target = event.target || event.srcElement;
|
||||
inputSelectAll(target);
|
||||
}
|
||||
|
||||
// Add clipboard icon
|
||||
@ -33,11 +34,14 @@ window.addEventListener("load", function() {
|
||||
img.src = base + "copy.png";
|
||||
img.alt = "Clipboard Icon";
|
||||
img.title = "Copy to clipboard";
|
||||
img.onclick = function(event) {
|
||||
img.onclick = function(e) {
|
||||
var event = e || window.event;
|
||||
var target = event.target || event.srcElement;
|
||||
|
||||
copyInputText(
|
||||
event.target.parentElement.parentElement.children[1].children[0],
|
||||
event.target,
|
||||
event.target.getAttribute("data-theme")
|
||||
target.parentElement.parentElement.getElementsByTagName('input')[0],
|
||||
target,
|
||||
target.getAttribute("data-theme")
|
||||
);
|
||||
};
|
||||
|
||||
@ -64,13 +68,13 @@ function copyInputText(input, clipboardIcon, theme) {
|
||||
}
|
||||
|
||||
clipboardIcon.src = path + "check.svg";
|
||||
clipboardIcon.previousElementSibling.srcset = path + "check.png";
|
||||
clipboardIcon.previousSibling.srcset = path + "check.png";
|
||||
|
||||
input.setSelectionRange(0, 0);
|
||||
inputDeselect(input);
|
||||
|
||||
setTimeout(function() {
|
||||
clipboardIcon.src = path + "copy.svg";
|
||||
clipboardIcon.previousElementSibling.srcset = path + "copy.png";
|
||||
clipboardIcon.previousSibling.srcset = path + "copy.png";
|
||||
}, 1000);
|
||||
|
||||
}
|
||||
@ -80,3 +84,8 @@ function inputSelectAll(input) {
|
||||
if (input.select) input.select();
|
||||
else input.setSelectionRange(0, this.value.length);
|
||||
}
|
||||
|
||||
function inputDeselect(input) {
|
||||
if (input.blur) input.blur();
|
||||
else input.setSelectionRange(0, 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user