Skip to content

Commit

Permalink
[IMPROVEMENT] Rewrite copyto in plain javascript #482
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Feb 19, 2024
2 parents ce609ab + ad40c9a commit 491c9b4
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions promgen/static/js/promgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ function update_page(data) {
}
}

// Wait until DOM is loaded to add our extra listeners
document.addEventListener("DOMContentLoaded", function () {
/*
Copy to shortcut
Example: <code data-copyto="#id_duration">30s</code>
*/
document.querySelectorAll("[data-copyto]").forEach(srcElement => {
srcElement.style.cursor = "pointer";
srcElement.addEventListener("click", e => {
const dstElement = document.querySelector(srcElement.dataset.copyto);
dstElement.value = srcElement.innerText;
});
});
});

$(document).ready(function() {
$('[data-toggle="popover"]').popover();
$('[data-toggle="tooltip"]').tooltip();
Expand All @@ -45,11 +61,6 @@ $(document).ready(function() {
$.post(btn.data('href'), btn.data()).done(update_page);
}).css('cursor', 'pointer');

$('[data-copyto]').click(function(){
var ele = $(this);
$(ele.data('copyto')).val(ele.text())
}).css('cursor', 'pointer');

$('[data-toggle="toggle"]').bootstrapSwitch();
$('[data-toggle="toggle"][data-action]').on('switchChange.bootstrapSwitch', function(event, state) {
if (window.confirm("Are you sure?")) {
Expand Down

0 comments on commit 491c9b4

Please sign in to comment.