Common.js: различия между версиями
Материал из Много троп
Mnogotrop (обсуждение | вклад) Новая страница: «→Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице: $(function () { $('.hidden-iframe-container').each(function () { const container = this; const iframe = container.querySelector('.hidden-iframe'); if (!iframe) { return; } let loaded = false; // Считаем iframe...» |
Mnogotrop (обсуждение | вклад) Нет описания правки |
||
| Строка 32: | Строка 32: | ||
}); | }); | ||
}); | }); | ||
document.getElementById('download-gpx').addEventListener('click', function() { | |||
const data = JSON.parse(document.getElementById('route-data').textContent); | |||
const gpx = geoJsonToGpx(data); | |||
const blob = new Blob([gpx], {type: 'application/gpx+xml'}); | |||
const url = URL.createObjectURL(blob); | |||
const a = document.createElement('a'); | |||
a.href = url; | |||
a.download = 'route.gpx'; | |||
a.click(); | |||
}); | |||
function geoJsonToGpx(geojson) { | |||
let gpx = '<?xml version="1.0" encoding="UTF-8"?>\n'; | |||
gpx += '<gpx version="1.1" creator="MediaWiki">\n'; | |||
geojson.features.forEach(feature => { | |||
if (feature.geometry.type === 'LineString') { | |||
gpx += ' <trk>\n'; | |||
gpx += ` <name>${feature.properties.title || 'Track'}</name>\n`; | |||
gpx += ' <trkseg>\n'; | |||
feature.geometry.coordinates.forEach(([lon, lat]) => { | |||
gpx += ` <trkpt lat="${lat}" lon="${lon}" />\n`; | |||
}); | |||
gpx += ' </trkseg>\n'; | |||
gpx += ' </trk>\n'; | |||
} | |||
}); | |||
gpx += '</gpx>'; | |||
return gpx; | |||
} | |||
Версия от 23:31, 21 сентября 2026
/* Размещённый здесь код JavaScript будет загружаться пользователям при обращении к каждой странице */
$(function () {
$('.hidden-iframe-container').each(function () {
const container = this;
const iframe = container.querySelector('.hidden-iframe');
if (!iframe) {
return;
}
let loaded = false;
// Считаем iframe загруженным после события load
iframe.addEventListener('load', function () {
loaded = true;
// Небольшая задержка перед отображением
setTimeout(function () {
container.style.display = '';
}, 3000); // 3000 мс = 3 секунды
});
// Если iframe не загрузился за 5 секунд, оставляем его скрытым
setTimeout(function () {
if (!loaded) {
container.remove();
// Или вместо удаления:
// container.style.display = 'none';
}
}, 5000);
});
});
document.getElementById('download-gpx').addEventListener('click', function() {
const data = JSON.parse(document.getElementById('route-data').textContent);
const gpx = geoJsonToGpx(data);
const blob = new Blob([gpx], {type: 'application/gpx+xml'});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'route.gpx';
a.click();
});
function geoJsonToGpx(geojson) {
let gpx = '<?xml version="1.0" encoding="UTF-8"?>\n';
gpx += '<gpx version="1.1" creator="MediaWiki">\n';
geojson.features.forEach(feature => {
if (feature.geometry.type === 'LineString') {
gpx += ' <trk>\n';
gpx += ` <name>${feature.properties.title || 'Track'}</name>\n`;
gpx += ' <trkseg>\n';
feature.geometry.coordinates.forEach(([lon, lat]) => {
gpx += ` <trkpt lat="${lat}" lon="${lon}" />\n`;
});
gpx += ' </trkseg>\n';
gpx += ' </trk>\n';
}
});
gpx += '</gpx>';
return gpx;
}