From 0b913053a76e83a43846e19097963f98c8519a1d Mon Sep 17 00:00:00 2001 From: Ivan Gabaldon Date: Sun, 6 Jul 2025 12:27:28 +0200 Subject: [mod] theme/simple: migrate codebase to TypeScript TypeScript is a superset of JavaScript, converting the entire theme to TypeScript allows us to receive much more feedback on possible issues made in package updates or our own typos, furthermore, it allows to transpile properly to lower specs. This PR couldn't be done in smaller commits, a lot of work needed to make everything *work properly*: - A browser baseline has been set that requires minimum **Chromium 93, Firefox 92 and Safari 15** (proper visuals/operation on older browser versions is not guaranteed) - LightningCSS now handles minification and prefix creation for CSS. - All hardcoded polyfills and support for previous browser baseline versions have been removed. - Convert codebase to TypeScript. - Convert IIFE to ESM, handling globals with IIFE is cumbersome, ESM is the standard for virtually any use of JS nowadays. - Vite now builds the theme without the need for `vite-plugin-static-copy`. - `searxng.ready` now accepts an array of conditions for the callback to be executed. - Replace `leaflet` with `ol` as there were some issues with proper Vite bundling. - Merged `head` with `main` script, as head was too small now. - Add `assertElement` to properly check the existence of critical DOM elements. - `searxng.on` renamed to `searxng.listen` with some handling improvements. --- client/simple/src/js/main/mapresult.js | 77 ---------------------------------- 1 file changed, 77 deletions(-) delete mode 100644 client/simple/src/js/main/mapresult.js (limited to 'client/simple/src/js/main/mapresult.js') diff --git a/client/simple/src/js/main/mapresult.js b/client/simple/src/js/main/mapresult.js deleted file mode 100644 index 3f2d06548..000000000 --- a/client/simple/src/js/main/mapresult.js +++ /dev/null @@ -1,77 +0,0 @@ -/* SPDX-License-Identifier: AGPL-3.0-or-later */ -/* global L */ -((_w, _d, searxng) => { - searxng.ready(() => { - searxng.on(".searxng_init_map", "click", function (event) { - // no more request - this.classList.remove("searxng_init_map"); - - // - const leaflet_target = this.dataset.leafletTarget; - const map_lon = parseFloat(this.dataset.mapLon); - const map_lat = parseFloat(this.dataset.mapLat); - const map_zoom = parseFloat(this.dataset.mapZoom); - const map_boundingbox = JSON.parse(this.dataset.mapBoundingbox); - const map_geojson = JSON.parse(this.dataset.mapGeojson); - - searxng.loadStyle("css/leaflet.css"); - searxng.loadScript("js/leaflet.js", () => { - let map_bounds = null; - if (map_boundingbox) { - const southWest = L.latLng(map_boundingbox[0], map_boundingbox[2]); - const northEast = L.latLng(map_boundingbox[1], map_boundingbox[3]); - map_bounds = L.latLngBounds(southWest, northEast); - } - - // init map - const map = L.map(leaflet_target); - // create the tile layer with correct attribution - const osmMapnikUrl = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"; - const osmMapnikAttrib = 'Map data © OpenStreetMap contributors'; - const osmMapnik = new L.TileLayer(osmMapnikUrl, { minZoom: 1, maxZoom: 19, attribution: osmMapnikAttrib }); - const osmWikimediaUrl = "https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png"; - const osmWikimediaAttrib = - 'Wikimedia maps | Maps data © OpenStreetMap contributors'; - const osmWikimedia = new L.TileLayer(osmWikimediaUrl, { - minZoom: 1, - maxZoom: 19, - attribution: osmWikimediaAttrib - }); - // init map view - if (map_bounds) { - // TODO hack: https://github.com/Leaflet/Leaflet/issues/2021 - // Still useful ? - setTimeout(() => { - map.fitBounds(map_bounds, { - maxZoom: 17 - }); - }, 0); - } else if (map_lon && map_lat) { - if (map_zoom) { - map.setView(new L.LatLng(map_lat, map_lon), map_zoom); - } else { - map.setView(new L.LatLng(map_lat, map_lon), 8); - } - } - - map.addLayer(osmMapnik); - - const baseLayers = { - "OSM Mapnik": osmMapnik, - "OSM Wikimedia": osmWikimedia - }; - - L.control.layers(baseLayers).addTo(map); - - if (map_geojson) { - L.geoJson(map_geojson).addTo(map); - } /* else if(map_bounds) { - L.rectangle(map_bounds, {color: "#ff7800", weight: 3, fill:false}).addTo(map); - } */ - }); - - // this event occur only once per element - event.preventDefault(); - }); - }); -})(window, document, window.searxng); -- cgit v1.2.3