From bca6dcdd4db13d79579f203ea2ba822bf13b7db2 Mon Sep 17 00:00:00 2001 From: SahilRakhaiya05 Date: Sun, 16 Mar 2025 11:59:20 +0530 Subject: [PATCH 1/3] fix: remove global variables and improve resource management --- src/main.js | 7 ++--- src/utils/dom-elements.js | 41 +++++++++++++++++++++----- src/utils/sounds.js | 60 +++++++++++++++++++++++++++++++++++---- 3 files changed, 92 insertions(+), 16 deletions(-) diff --git a/src/main.js b/src/main.js index d5b3d1e..d615203 100644 --- a/src/main.js +++ b/src/main.js @@ -1,4 +1,3 @@ - /* * Copyright (c) 2023-25 Zendalona * This software is licensed under the GPL-3.0 License. @@ -12,7 +11,7 @@ import { addDisclaimer } from "./layout/disclaimer.js"; import { detailsCloseButton, distanceBox, distanceIcon, input } from "./utils/dom-elements.js"; import { lockTabKey } from "./utils/keydown-helpers.js"; import { closeSound, successSound } from "./utils/sounds.js"; -let marker +let marker; addDisclaimer() // Add a disclaimer to the UI fetch('https://ipinfo.io/json') //fetching the location of the user and setting the map to that location, if failed then setting it to the default location @@ -22,9 +21,9 @@ fetch('https://ipinfo.io/json') //fetching the location of the user and setting map.setView([lat, lon], 7) }) .catch(error => { -map.setView([10.16,76.64],7) + map.setView([10.16,76.64],7) }).finally(()=>{ - window.marker = new Marker(map.getCenter()).addTo(map) + marker = new Marker(map.getCenter()).addTo(map) }) document.addEventListener('keydown',handleKeyDownOnDocument) // Initialize event listeners for key shortcuts on the document, general any time shortcuts addListenerstoUI() // Initialize event listeners for the UI elements on the page diff --git a/src/utils/dom-elements.js b/src/utils/dom-elements.js index 79018ca..d8c1572 100644 --- a/src/utils/dom-elements.js +++ b/src/utils/dom-elements.js @@ -4,14 +4,41 @@ * See the LICENSE file in the root directory for more information. */ +const getElement = (id) => { + const element = document.getElementById(id); + if (!element) { + console.warn(`Element with id "${id}" not found`); + } + return element; +}; -export let searchResults = document.getElementById("search-results"); -export let detalisElement = document.getElementById("detalisElement") -export let input = document.getElementById("search-input") -export let distanceIcon = document.getElementById("trigger-icon") -export let distanceBox = document.getElementById("box"); +const getQueryElement = (selector) => { + const element = document.querySelector(selector); + if (!element) { + console.warn(`Element with selector "${selector}" not found`); + } + return element; +}; -export let ser = document.querySelector(".box-input") -export let detailsCloseButton=document.getElementById("closeBtnD") +export const elements = { + get searchResults() { return getElement("search-results"); }, + get detalisElement() { return getElement("detalisElement"); }, + get input() { return getElement("search-input"); }, + get distanceIcon() { return getElement("trigger-icon"); }, + get distanceBox() { return getElement("box"); }, + get ser() { return getQueryElement(".box-input"); }, + get detailsCloseButton() { return getElement("closeBtnD"); } +}; + +// For backward compatibility +export const { + searchResults, + detalisElement, + input, + distanceIcon, + distanceBox, + ser, + detailsCloseButton +} = elements; diff --git a/src/utils/sounds.js b/src/utils/sounds.js index 78f96eb..ca24aeb 100644 --- a/src/utils/sounds.js +++ b/src/utils/sounds.js @@ -2,9 +2,59 @@ * Copyright (c) 2023-25 Zendalona * This software is licensed under the GPL-3.0 License. * See the LICENSE file in the root directory for more information. - */ -export const clickSound = new Audio("../src/assets/audio/click.mp3"); -export const closeSound = new Audio("../src/assets/audio/close.mp3"); -export const successSound= new Audio('../src/assets/audio/sucessfull.mp3') -export const bordercrossSound = new Audio('../src/assets/audio/border-crossing.mp3'); + */ + +class AudioManager { + constructor() { + this._sounds = new Map(); + } + + _createAudio(path) { + if (!this._sounds.has(path)) { + try { + const audio = new Audio(path); + this._sounds.set(path, audio); + } catch (error) { + console.warn(`Failed to load audio file: ${path}`, error); + return null; + } + } + return this._sounds.get(path); + } + + play(path) { + const audio = this._createAudio(path); + if (audio) { + audio.play().catch(error => { + console.warn(`Failed to play audio: ${path}`, error); + }); + } + } +} + +const audioManager = new AudioManager(); + +const AUDIO_PATHS = { + CLICK: '../src/assets/audio/click.mp3', + CLOSE: '../src/assets/audio/close.mp3', + SUCCESS: '../src/assets/audio/sucessfull.mp3', + BORDER_CROSS: '../src/assets/audio/border-crossing.mp3' +}; + +// For backward compatibility +export const clickSound = { + play: () => audioManager.play(AUDIO_PATHS.CLICK) +}; + +export const closeSound = { + play: () => audioManager.play(AUDIO_PATHS.CLOSE) +}; + +export const successSound = { + play: () => audioManager.play(AUDIO_PATHS.SUCCESS) +}; + +export const bordercrossSound = { + play: () => audioManager.play(AUDIO_PATHS.BORDER_CROSS) +}; From e273b855aa6e0dec9de2b56bd1ab9b2a251fc2be Mon Sep 17 00:00:00 2001 From: SahilRakhaiya05 Date: Sun, 16 Mar 2025 12:13:14 +0530 Subject: [PATCH 2/3] fix: improve user manual UI and fix encoding issues --- public/index.html | 20 +- src/pages/user-guide/index.html | 781 ++++++++++++++++++-------------- 2 files changed, 446 insertions(+), 355 deletions(-) diff --git a/public/index.html b/public/index.html index 513c203..a662ff3 100644 --- a/public/index.html +++ b/public/index.html @@ -2,6 +2,8 @@ + + @@ -33,10 +35,10 @@
+ Help +
@@ -125,6 +127,18 @@

Find Distance

+ +