From 25e5c6acea32f279d5138ebd7585b27d7ad7f057 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Thu, 25 Jul 2024 23:23:57 +0200 Subject: [PATCH] Testar vidare... --- smartassist/src/static/js/frontend.js | 73 ++------------------------- 1 file changed, 4 insertions(+), 69 deletions(-) diff --git a/smartassist/src/static/js/frontend.js b/smartassist/src/static/js/frontend.js index 5606d84..ec029ca 100644 --- a/smartassist/src/static/js/frontend.js +++ b/smartassist/src/static/js/frontend.js @@ -5,71 +5,6 @@ const userInput = document.getElementById('userInput'); // Get API endpoint for chat from environment variable -// const apiEndpoint = process.env.BE_API_ENDPOINT || 'http://localhost:5005/api/chat'; // Default if not found -// const apiEndpoint = '<%= api_endpoint %>'; // Templating syntax (Jinja2) -// const iframe = document.getElementById('client-frame'); -// const apiEndpoint = iframe.getAttribute('data-api-endpoint'); -// console.log("frontend.js - the API Endpoint is:", apiEndpoint); - -// document.addEventListener('DOMContentLoaded', () => { -// const iframe = document.getElementById('client-frame'); -// const iframeContentUrl = iframe.srcdoc; - -// // Extract the query parameter 'apiEndpoint' from the URL -// const urlParams = new URLSearchParams(iframeContentUrl.split('?')[1]); -// const apiEndpoint = urlParams.get('apiEndpoint'); - -// console.log("frontend.js - The API Endpoint is:", apiEndpoint); -// }); - -// document.addEventListener('DOMContentLoaded', () => { -// setTimeout(() => { -// const iframe = document.getElementById('client-frame'); -// if (iframe) { -// const iframeContentUrl = iframe.srcdoc; -// // Extract the query parameter 'apiEndpoint' from the URL -// const urlParams = new URLSearchParams(iframeContentUrl.split('?')[1]); -// const apiEndpoint = urlParams.get('apiEndpoint'); } else { -// console.error("Error: iframe element not found."); -// } -// }, 100); // Adjust this delay (in milliseconds) if needed -// }); - -// const observer = new MutationObserver(() => { -// const iframe = document.getElementById('client-frame'); -// if (iframe) { -// console.log("iframe DO exist") -// if (iframe.srcdoc) { -// console.log("srcdoc exist") -// // Extract the query parameter 'apiEndpoint' from the URL -// const urlParams = new URLSearchParams(iframe.srcdoc.split('?')[1]); -// const apiEndpoint = urlParams.get('apiEndpoint'); -// console.log("frontend.js - The API Endpoint is:", apiEndpoint); -// } -// else { -// console.error("Error: iframe.srcdoc not found."); -// observer.disconnect(); // Stop observing once you've extracted the data -// } -// } -// else { -// console.error("Error: iframe DOES NOT exist."); -// observer.disconnect(); // Stop observing once you've extracted the data - -// } - - -// if (iframe && iframe.srcdoc) { // Check if iframe exists and srcdoc is populated -// const iframeContentUrl = iframe.srcdoc; -// // Extract the query parameter 'apiEndpoint' from the URL -// const urlParams = new URLSearchParams(iframeContentUrl.split('?')[1]); -// const apiEndpoint = urlParams.get('apiEndpoint'); -// } -// else { -// console.error("Error: iframe element not found."); -// observer.disconnect(); // Stop observing once you've extracted the data -// } -// }); -// observer.observe(document.body, { childList: true, subtree: true }); // Handle resize events window.addEventListener('resize', () => { @@ -128,18 +63,18 @@ function renderMessage(text, className) { function handleIframeLoad() { - const iframe = document.getElementById('client-frame'); + const clientFrame = document.getElementById('client-frame'); - if (iframe) { // Check if the iframe exists + if (clientFrame) { // Check if the iframe exists - const apiEndpoint = iframe.getAttribute('data-api-endpoint') || iframe.srcdoc.split('?')[1].split('=')[1]; + const apiEndpoint = clientFrame.getAttribute('data-api-endpoint') || clientFrame.srcdoc.split('?')[1].split('=')[1]; console.log("The API Endpoint is:", apiEndpoint); // Now you can use this 'apiEndpoint' for communication } else { setTimeout(handleIframeLoad, 200); // Retry in a short while if iframe not found yet - console.log("iframe not found yet"); + console.log("The iframe with id client-frame not found yet"); } }