From fd5f6199e98724f2ae39d944ecdf4c3ecaae3109 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Tue, 6 Aug 2024 00:48:54 +0200 Subject: [PATCH] =?UTF-8?q?Hanterar=20dynamisk=20uppdatering=20av=20inneh?= =?UTF-8?q?=C3=A5llet=20i=20rullgardinsmenyn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/static/js/frontend.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/smartassist/src/static/js/frontend.js b/smartassist/src/static/js/frontend.js index 77d71fd..adc1962 100644 --- a/smartassist/src/static/js/frontend.js +++ b/smartassist/src/static/js/frontend.js @@ -66,7 +66,7 @@ const frontendApi = { // Populate the dropdown menu with received data data.forEach(endpoint => { const linkElement = document.createElement('a'); - linkElement.href = '#'; + linkElement.href = ''; // If attribute is set to '#', browser scrolls to top of page and reload linkElement.onclick = () => frontendApi.setEndpointAndLlm(endpoint.endpoint, endpoint.llm); linkElement.textContent = `${endpoint.endpoint} - ${endpoint.llm}`; @@ -111,6 +111,19 @@ document.addEventListener('keyup', function() { sendButton.style.backgroundColor = ''; // Restore the original style when any key is released }); +// Get the dropdown button and the dropdown content elements +const dropbtn = document.getElementById('selected-endpoint'); +const dropdownContent = document.getElementById('endpoint-dropdown'); + +// Add event listeners to each dropdown item +dropdownContent.addEventListener('click', (e) => { + if (e.target.tagName === 'A') { // Only respond to clicks on anchor tags + e.preventDefault(); // Prevent default link behavior + const selectedEndpoint = e.target.textContent; + dropbtn.textContent = selectedEndpoint; // Update the button's text + // You can also add code here to update the current endpoint in your application + } +}); function init() { // Other initialization code here...