Sin resumen de edición |
Sin resumen de edición |
||
| (No se muestra una edición intermedia del mismo usuario) | |||
| Línea 2: | Línea 2: | ||
(function () { | (function () { | ||
function initSpeciesTabs() { | function initSpeciesTabs() { | ||
document.querySelectorAll('# | document.querySelectorAll('#tabs-mararg').forEach(function (tabs) { | ||
if (tabs.dataset.tabsReady === 'true') return; | if (tabs.dataset.tabsReady === 'true') return; | ||
tabs.dataset.tabsReady = 'true'; | tabs.dataset.tabsReady = 'true'; | ||
var links = tabs.querySelectorAll('. | var links = tabs.querySelectorAll('.tab-link-mararg'); | ||
var panels = tabs.querySelectorAll('. | var panels = tabs.querySelectorAll('.tab-panel-mararg'); | ||
links.forEach(function (link) { | links.forEach(function (link) { | ||
link.addEventListener('click', function (event) { | link.addEventListener('click', function (event) { | ||
| Línea 30: | Línea 30: | ||
mw.hook('wikipage.content').add(initSpeciesTabs); | mw.hook('wikipage.content').add(initSpeciesTabs); | ||
} | } | ||
}()); | |||
/* Áreas múltiples de distribución para las fichas de especies */ | |||
(function () { | |||
'use strict'; | |||
function parseAreas(value) { | |||
return (value || '').split('/').map(function (area) { | |||
return area.split(';').map(function (pair) { | |||
var parts = pair.trim().split(',').map(function (item) { return parseFloat(item); }); | |||
return parts.length === 2 && !isNaN(parts[0]) && !isNaN(parts[1]) ? parts : null; | |||
}).filter(Boolean); | |||
}).filter(function (area) { return area.length >= 3; }); | |||
} | |||
function patchLeaflet() { | |||
if (!window.L || !window.L.map || window.L.__marargAreasPatched) return; | |||
var originalMap = window.L.map; | |||
window.L.map = function (element, options) { | |||
var map = originalMap.call(this, element, options); | |||
var areas = parseAreas(element.getAttribute('data-areas')); | |||
if (areas.length) { | |||
var bounds = window.L.latLngBounds([]); | |||
areas.forEach(function (area, index) { | |||
var polygon = window.L.polygon(area, { color: '#5146d8', weight: 2, fillColor: index % 2 ? '#8bc7c1' : '#8b7de8', fillOpacity: 0.22 }).addTo(map); | |||
polygon.bindPopup((element.getAttribute('data-label') || 'Área de distribución') + ' · Área ' + (index + 1)); | |||
bounds.extend(polygon.getBounds()); | |||
}); | |||
if (bounds.isValid()) map.fitBounds(bounds, { padding: [24, 24], maxZoom: 6 }); | |||
} | |||
return map; | |||
}; | |||
window.L.__marargAreasPatched = true; | |||
} | |||
var timer = window.setInterval(function () { if (window.L) { patchLeaflet(); window.clearInterval(timer); } }, 50); | |||
}()); | }()); | ||
Revisión actual - 12:13 15 sep 2026
/* Solapas de la ficha de especies */
(function () {
function initSpeciesTabs() {
document.querySelectorAll('#tabs-mararg').forEach(function (tabs) {
if (tabs.dataset.tabsReady === 'true') return;
tabs.dataset.tabsReady = 'true';
var links = tabs.querySelectorAll('.tab-link-mararg');
var panels = tabs.querySelectorAll('.tab-panel-mararg');
links.forEach(function (link) {
link.addEventListener('click', function (event) {
event.preventDefault();
var target = link.dataset.tab;
links.forEach(function (item) {
item.classList.toggle('is-active', item === link);
});
panels.forEach(function (panel) {
panel.classList.toggle('is-active', panel.dataset.tabPanel === target);
});
});
});
});
}
function start() { initSpeciesTabs(); }
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', start);
} else {
start();
}
if (window.mw && mw.hook) {
mw.hook('wikipage.content').add(initSpeciesTabs);
}
}());
/* Áreas múltiples de distribución para las fichas de especies */
(function () {
'use strict';
function parseAreas(value) {
return (value || '').split('/').map(function (area) {
return area.split(';').map(function (pair) {
var parts = pair.trim().split(',').map(function (item) { return parseFloat(item); });
return parts.length === 2 && !isNaN(parts[0]) && !isNaN(parts[1]) ? parts : null;
}).filter(Boolean);
}).filter(function (area) { return area.length >= 3; });
}
function patchLeaflet() {
if (!window.L || !window.L.map || window.L.__marargAreasPatched) return;
var originalMap = window.L.map;
window.L.map = function (element, options) {
var map = originalMap.call(this, element, options);
var areas = parseAreas(element.getAttribute('data-areas'));
if (areas.length) {
var bounds = window.L.latLngBounds([]);
areas.forEach(function (area, index) {
var polygon = window.L.polygon(area, { color: '#5146d8', weight: 2, fillColor: index % 2 ? '#8bc7c1' : '#8b7de8', fillOpacity: 0.22 }).addTo(map);
polygon.bindPopup((element.getAttribute('data-label') || 'Área de distribución') + ' · Área ' + (index + 1));
bounds.extend(polygon.getBounds());
});
if (bounds.isValid()) map.fitBounds(bounds, { padding: [24, 24], maxZoom: 6 });
}
return map;
};
window.L.__marargAreasPatched = true;
}
var timer = window.setInterval(function () { if (window.L) { patchLeaflet(); window.clearInterval(timer); } }, 50);
}());