Skip to content

Commit

Permalink
Rewrite copyto in plain javascript
Browse files Browse the repository at this point in the history
As we work towards removing our dependence on jQuery, we want to rewrite
our copyto helper in plain javascript
  • Loading branch information
kfdm committed Feb 19, 2024
1 parent ce609ab commit ad40c9a
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 ad40c9a

Please sign in to comment.