68 lines
1.7 KiB
JavaScript
68 lines
1.7 KiB
JavaScript
// Utility functions
|
|
export function escapeHtml(text) {
|
|
if (text === null || text === undefined) {
|
|
return '';
|
|
}
|
|
const div = document.createElement('div');
|
|
div.textContent = String(text);
|
|
return div.innerHTML;
|
|
}
|
|
|
|
export function parseGeoLocation(value) {
|
|
if (!value) return null;
|
|
|
|
// Try semicolon separator first
|
|
let parts = value.split(';');
|
|
if (parts.length !== 2) {
|
|
// Try comma separator
|
|
parts = value.split(',');
|
|
}
|
|
|
|
if (parts.length === 2) {
|
|
const lat = parseFloat(parts[0].trim());
|
|
const lng = parseFloat(parts[1].trim());
|
|
|
|
if (!isNaN(lat) && !isNaN(lng)) {
|
|
return { lat, lng };
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function showStatus(message, type = 'info') {
|
|
const container = document.getElementById('status-container');
|
|
|
|
const messageDiv = document.createElement('div');
|
|
messageDiv.className = `status-message ${type}`;
|
|
messageDiv.textContent = message;
|
|
|
|
container.appendChild(messageDiv);
|
|
|
|
// Auto-remove after 5 seconds
|
|
setTimeout(() => {
|
|
messageDiv.remove();
|
|
}, 5000);
|
|
}
|
|
|
|
export function hideLoading() {
|
|
const loading = document.getElementById('loading');
|
|
if (loading) {
|
|
loading.classList.add('hidden');
|
|
}
|
|
}
|
|
|
|
export function updateLocationCount(count) {
|
|
const countElement = document.getElementById('location-count');
|
|
const mobileCountElement = document.getElementById('mobile-location-count');
|
|
|
|
const countText = `${count} location${count !== 1 ? 's' : ''}`;
|
|
|
|
if (countElement) {
|
|
countElement.textContent = countText;
|
|
}
|
|
if (mobileCountElement) {
|
|
mobileCountElement.textContent = countText;
|
|
}
|
|
}
|