Skip to content

Commit

Permalink
Don't run Javascript when Nodes are not available
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kastl <daniel@georepublic.de>
  • Loading branch information
dkastl committed Nov 29, 2023
1 parent b93d9ea commit 298a5f4
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions assets/javascripts/gtt_assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ document.addEventListener('DOMContentLoaded', () => {

// Function to move the smart assistant element
function moveElement() {
// Find the label element with for="issue_subject"
const field = document.querySelector('label[for="issue_subject"]');
const smartAssistant = document.querySelector('#smart_assistant');

// If the label element is not found, skip
if (!field) {
// Exit the function if either the field, its parent, or smartAssistant is not found
if (!field || !field.parentNode || !smartAssistant) {
return;
}

// Find the enclosing p element of the label
const target = field.parentNode;

// Find the p element with id="smart_assistant"
const smartAssistant = document.querySelector('#smart_assistant');

// Move the smart assistant element after the target
target.parentNode.insertBefore(smartAssistant, target.nextSibling);
field.parentNode.parentNode.insertBefore(smartAssistant, field.parentNode.nextSibling);

// Set the smart assistant element's display style to block
smartAssistant.style.display = "block";
}



// Function to register requests for the assistant buttons
function registerRequest() {
// Get all assistant buttons
Expand Down

0 comments on commit 298a5f4

Please sign in to comment.