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
1 merge request!975Resolve "Add possibility to create Ical feeds for all apps"
Checking pipeline status
$(".copy-button").click((e) => {
const target = $(e.currentTarget);
const input = $("#" + target.data("target"));
const icon = target.children("svg")[0];
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);
const copy_icon = target.children(".copy-icon-copy").first();
const check_icon = target.children(".copy-icon-success").first();
if (navigator.clipboard) {
console.log("Copying to clipboard");
navigator.clipboard.writeText(input.val()).then(r => {
icon.replaceWith(check);
// target.children("svg")[0].classList.add("material-icons");
check_icon.show();
copy_icon.hide();
setTimeout(() => {
target.children("svg")[0].replaceWith(copy);
// target.children("svg")[0].classList.add("material-icons");
check_icon.hide();
copy_icon.show();
}, 1000);
});
} else {
......@@ -32,10 +19,11 @@ $(".copy-button").click((e) => {
input.select();
document.execCommand("copy");
input.blur();
icon.replaceWith(check);
// target.children("svg")[0].classList.add("material-icons");
check_icon.show();
copy_icon.hide();
setTimeout(() => {
icon.innerHTML = copy.body;
check_icon.hide();
copy_icon.show();
}, 1000);
}
});
......@@ -27,7 +27,8 @@
</a>
<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">
<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>
</span>
<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