+var fetch_content_cache = {};
+export async function fetch_content_into_element(url, dom_element) {
+ if (!window.location.protocol.match(/^http/)) {
+ dom_element.innerHTML = `Cannot display data from ${url} here. `
+ + 'Browser security prevents loading content from file:// URLs.';
+ return;
+ }
+
+ if (fetch_content_cache[url]) {
+ dom_element.innerHTML = fetch_content_cache[url];
+ return;
+ }
+ try {
+ await fetch(url)
+ .then(response => response.text())
+ .then(html => {
+ html = html.replace('Nominatim_API_Endpoint', generate_nominatim_endpoint_url());
+ dom_element.innerHTML = html;
+ fetch_content_cache[url] = html;
+ });
+ } catch (error) {
+ dom_element.innerHTML = `Error fetching content from ${url} (${error})`;
+ }
+}
+
+function generate_nominatim_endpoint_url(endpoint_name) {
+ var conf_endpoint = Nominatim_Config.Nominatim_API_Endpoint;
+
+ if (typeof conf_endpoint === 'function') {
+ return conf_endpoint(endpoint_name);
+ }
+
+ if (!endpoint_name) return conf_endpoint;
+
+ return conf_endpoint + endpoint_name + '.php';
+}
+