Skip to content
Snippets Groups Projects
Commit b5f68a61 authored by Julian's avatar Julian
Browse files

Simplify icon changing JavaScript

parent e52972e5
No related branches found
No related tags found
Loading
Pipeline #61194 canceled
$(".copy-button").click((e) => { $(".copy-button").click((e) => {
const target = $(e.currentTarget); const target = $(e.currentTarget);
const input = $("#" + target.data("target")); const input = $("#" + target.data("target"));
const icon = target.children("svg")[0]; const copy_icon = target.children(".copy-icon-copy").first();
const check_icon = target.children(".copy-icon-success").first();
if (!Iconify.iconExists("mdi:content-copy")) {
Iconify.loadIcon("mdi:content-copy");
}
const copy = Iconify.renderSVG("mdi:content-copy");
copy.classList.add("material-icons");
if (!Iconify.iconExists("mdi:check")) {
Iconify.loadIcon("mdi:check");
}
const check = Iconify.renderSVG("mdi:check");
check.classList.add("material-icons");
console.log(copy);
if (navigator.clipboard) { if (navigator.clipboard) {
console.log("Copying to clipboard"); console.log("Copying to clipboard");
navigator.clipboard.writeText(input.val()).then(r => { navigator.clipboard.writeText(input.val()).then(r => {
icon.replaceWith(check); check_icon.show();
// target.children("svg")[0].classList.add("material-icons"); copy_icon.hide();
setTimeout(() => { setTimeout(() => {
target.children("svg")[0].replaceWith(copy); check_icon.hide();
// target.children("svg")[0].classList.add("material-icons"); copy_icon.show();
}, 1000); }, 1000);
}); });
} else { } else {
...@@ -32,10 +19,11 @@ $(".copy-button").click((e) => { ...@@ -32,10 +19,11 @@ $(".copy-button").click((e) => {
input.select(); input.select();
document.execCommand("copy"); document.execCommand("copy");
input.blur(); input.blur();
icon.replaceWith(check); check_icon.show();
// target.children("svg")[0].classList.add("material-icons"); copy_icon.hide();
setTimeout(() => { setTimeout(() => {
icon.innerHTML = copy.body; check_icon.hide();
copy_icon.show();
}, 1000); }, 1000);
} }
}); });
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
</a> </a>
<button type="button" data-target="input-{{ forloop.counter0 }}" <button type="button" data-target="input-{{ forloop.counter0 }}"
class="secondary-content btn-flat btn-small secondary-color-text btn-smaller-padding copy-button waves-effect waves-secondary"> class="secondary-content btn-flat btn-small secondary-color-text btn-smaller-padding copy-button waves-effect waves-secondary">
<i class="material-icons iconify" data-icon="mdi:content-copy"></i> <i class="material-icons iconify copy-icon-copy" data-icon="mdi:content-copy"></i>
<i class="material-icons iconify copy-icon-success" style="display: none" data-icon="mdi:check"></i>
</button> </button>
</span> </span>
<p class="ical-description">{{ object.ical_feed_object.title }} – {{ object.ical_feed_object.description }}</p> <p class="ical-description">{{ object.ical_feed_object.title }} – {{ object.ical_feed_object.description }}</p>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment