„MediaWiki:Common.js” változatai közötti eltérés
Megjelenés
Nincs szerkesztési összefoglaló |
Nincs szerkesztési összefoglaló |
||
| 31. sor: | 31. sor: | ||
/** | /** | ||
* ============================================================================ | * ============================================================================ | ||
* LIGHTGALLERY GLOBÁLIS INTEGRÁCIÓ ( | * LIGHTGALLERY GLOBÁLIS INTEGRÁCIÓ (Egyedi sablon galériák inicializálása) | ||
* ============================================================================ | * ============================================================================ | ||
*/ | */ | ||
(function() { | (function() { | ||
if ($('.wiki-dynamic-gallery').length === 0 && $('.egyedi-galeria-container').length === 0) return; | if ($('.wiki-dynamic-gallery').length === 0 && $('.egyedi-galeria-container').length === 0) return; | ||
// | // Mivel a LocalSettings.php már betöltötte a scriptet, azonnal inicializálhatunk a DOM ready után | ||
$(function() { | |||
if ($('.wiki-dynamic-gallery').length > 0) { | |||
initWikiDynamicGallery(); | |||
$ | } | ||
if ($('.egyedi-galeria-container').length > 0) { | |||
initMindenGaleriaElem(); | |||
} | |||
}); | |||
// --- RÉGI WIKI DYNAMIC GALLERY LOGIKA --- | // --- RÉGI WIKI DYNAMIC GALLERY LOGIKA --- | ||
| 446. sor: | 436. sor: | ||
/** | /** | ||
* ============================================================================ | * ============================================================================ | ||
* NATÍV CIKKBELI KÉPEK | * NATÍV CIKKBELI KÉPEK AUTOMATIKUS LIGHTGALLERY-BE TERELÉSE (ÖSSZEFÜGGŐ GALÉRIA) | ||
* ============================================================================ | * ============================================================================ | ||
*/ | */ | ||
window.addEventListener('click', function(e) { | |||
var targetLink = e.target.closest(' | // Elkapjuk az összes klasszikus MediaWiki képlinket | ||
var targetLink = e.target.closest('a.mw-file-description, a.image'); | |||
if (!targetLink) return; | if (!targetLink) return; | ||
// Kihagyjuk a már meglévő egyedi galériákat, ha vannak | |||
if (targetLink.closest('.egyedi-galeria-container') || targetLink.closest('.wiki-dynamic-gallery')) return; | if (targetLink.closest('.egyedi-galeria-container') || targetLink.closest('.wiki-dynamic-gallery')) return; | ||
// | // Fájl leíró oldalakon ne fusson, ott kell a gyári működés | ||
if (window.location.pathname.includes('/wiki/F%C3%A1jl:') || window.location.pathname.includes('/wiki/File:')) { | |||
return; | |||
} | |||
// AZONNAL megállítjuk a gyári átirányítást a /wiki/Fájl: oldalra | |||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
e.stopImmediatePropagation(); | e.stopImmediatePropagation(); | ||
var dynamicSlides = []; | var dynamicSlides = []; | ||
var clickedIndex = 0; | var clickedIndex = 0; | ||
var $mindenNativA = $(' | // Összegyűjtjük az összes natív képet az oldalon, ami NEM része egyedi galériának | ||
var $mindenNativA = $('a.mw-file-description, a.image').filter(function() { | |||
return $(this).closest('.egyedi-galeria-container').length === 0 && $(this).closest('.wiki-dynamic-gallery').length === 0; | return $(this).closest('.egyedi-galeria-container').length === 0 && $(this).closest('.wiki-dynamic-gallery').length === 0; | ||
} | }); | ||
$mindenNativA.each(function(index) { | $mindenNativA.each(function(index) { | ||
var $el = $(this); | var $el = $(this); | ||
var $img = $el.find('img | var $img = $el.find('img'); | ||
if ($img.length > 0) { | if ($img.length > 0) { | ||
if ($el.is( | if ($el.is(targetLink)) { | ||
clickedIndex = index; | clickedIndex = index; | ||
} | } | ||
// | // Retina/HD fix: ha van srcset, a legnagyobb felbontásút használjuk eredetiként | ||
var | var origSrc = $img.attr('srcset') ? | ||
var | $img.attr('srcset').split(',').pop().trim().split(' ')[0] : | ||
$el.attr('href'); | |||
var thumbSrc = $img.attr('src'); | |||
// Képaláírás kinyerése a MediaWiki struktúrából | |||
var captionText = ''; | |||
var figure = $el.closest('figure, .thumb'); | |||
if (figure) { | |||
var figcaption = figure.querySelector('figcaption, .thumbcaption'); | |||
if (figcaption) { | |||
captionText = figcaption.textContent.replace(/×/g, '').trim(); | |||
} | |||
} | |||
if (!captionText) { | |||
captionText = $img.attr('alt') || $img.attr('title') || ''; | |||
} | } | ||
dynamicSlides.push({ | dynamicSlides.push({ | ||
src: origSrc, | src: origSrc, | ||
thumb: | thumb: thumbSrc, | ||
subHtml: | subHtml: captionText ? '<h4>' + captionText + '</h4>' : '' | ||
}); | }); | ||
} | } | ||
}); | }); | ||
// LightGallery indítása dinamikus tömbbel | |||
if (window.lightGallery && dynamicSlides.length > 0) { | if (window.lightGallery && dynamicSlides.length > 0) { | ||
var container = document.createElement('div'); | var container = document.createElement('div'); | ||
| 508. sor: | 512. sor: | ||
animateThumb: true, | animateThumb: true, | ||
showThumbByDefault: true, | showThumbByDefault: true, | ||
index: clickedIndex | index: clickedIndex, | ||
download: true, | |||
counter: dynamicSlides.length > 1 | |||
}); | }); | ||
dynamicGallery.openGallery(); | dynamicGallery.openGallery(); | ||
} else { | |||
console.error("LightGallery hiba: a könyvtár nem érhető el a kattintáskor."); | |||
} | } | ||
}, true); | }, true); // Capturing fázis! | ||
A lap 2026. június 18., 09:48-kori változata
/**
* VECTOR 2022 TELEPORT BUGFIX - DRGYZ
* Létrehozza a hiányzó teleportációs célpontokat, mielőtt a skin JS elhasalna
*/
(function() {
function injectVectorTargets() {
// Azon ID-k listája, amikre a vector skin classList-et akar hívni
var targets = ['p-lang-btn', 'vector-user-links-dropdown', 'vector-toc-landmark'];
targets.forEach(function(id) {
if (!document.getElementById(id)) {
var dummy = document.createElement('div');
dummy.id = id;
// Adunk neki egy üres classList-et biztonságból
dummy.className = 'vector-teleport-dummy-target';
dummy.style.display = 'none';
document.body.appendChild(dummy);
}
});
}
// Azonnal megpróbáljuk injektálni, amint a Common.js beolvasódik
injectVectorTargets();
// Ha még nem töltődött be a teljes DOM, akkor a betöltődéskor is ráerősítünk
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', injectVectorTargets);
}
})();
/**
* ============================================================================
* LIGHTGALLERY GLOBÁLIS INTEGRÁCIÓ (Egyedi sablon galériák inicializálása)
* ============================================================================
*/
(function() {
if ($('.wiki-dynamic-gallery').length === 0 && $('.egyedi-galeria-container').length === 0) return;
// Mivel a LocalSettings.php már betöltötte a scriptet, azonnal inicializálhatunk a DOM ready után
$(function() {
if ($('.wiki-dynamic-gallery').length > 0) {
initWikiDynamicGallery();
}
if ($('.egyedi-galeria-container').length > 0) {
initMindenGaleriaElem();
}
});
// --- RÉGI WIKI DYNAMIC GALLERY LOGIKA ---
function initWikiDynamicGallery() {
$('.wiki-dynamic-gallery').each(function() {
var $container = $(this);
if ($container.data('initialized')) return;
$container.data('initialized', true);
var searchTerm = $container.data('search');
var limit = $container.data('limit') || 3;
var targetHeight = 200;
var apiUrl = "https://commons.wikimedia.org/w/api.php?action=query&format=json&generator=search&gsrsearch=File:" +
encodeURIComponent(searchTerm) + "&gsrlimit=" + limit +
"&prop=imageinfo&iiprop=url|size&iiurlheight=" + targetHeight + "&origin=*";
$.getJSON(apiUrl, function(data) {
if (data && data.query && data.query.pages) {
var pages = data.query.pages;
var galleryHtml = '';
for (var id in pages) {
if (!pages[id].imageinfo) continue;
var img = pages[id].imageinfo[0];
var title = pages[id].title.replace('File:', '');
galleryHtml += '<a href="' + img.url + '" class="lg-item" data-src="' + img.url + '" data-sub-html="<h4>' + title + '</h4>">';
galleryHtml += ' <img src="' + img.thumburl + '" style="height:' + targetHeight + 'px; width:auto; margin:5px; border-radius:6px; cursor:pointer;" alt="' + title + '" />';
galleryHtml += '</a>';
}
$container.html(galleryHtml);
if (window.lightGallery) {
lightGallery($container[0], {
selector: '.lg-item',
licenseKey: '0000-0000-000-0000'
});
}
}
});
});
}
// --- LIGHTGALLERY V2 VEGYES GALÉRIA LOGIKA ---
function initMindenGaleriaElem() {
$('.egyedi-galeria-container').each(function() {
var $container = $(this);
if ($container.data('vegyes-initialized')) return;
$container.data('vegyes-initialized', true);
// 1. Külső URL és Commons képek kezelése
$container.find('.kulso-url-doboz').each(function() {
var $doboz = $(this);
var imgUrl = $doboz.attr('data-src');
var forrasNev = $doboz.attr('data-forras-nev') || 'Külső forrás';
var $feliratElem = $doboz.find('.galeria-felirat');
var felirat = $feliratElem.text().trim();
// Ha nincs felirat, generálunk a fájlnévből egyet
if (!felirat) {
var fileTitle = imgUrl.substring(imgUrl.lastIndexOf('/') + 1).split('.')[0];
felirat = decodeURIComponent(fileTitle).replace(/_/g, ' ');
$feliratElem.text(felirat); // A kártyára kiírjuk a tiszta generált feliratot
}
// --- ITT ÉPÍTJÜK FEL A JAVÍTOTT HTML-T A LIGHTGALLERY-NEK ---
var forrasLinkHtml = '<br/><span class="galeria-forras-jelzo" style="font-size:0.85em; color:#bbb; display:block; margin-top:4px;">' +
'Forrás: <a href="' + imgUrl + '" target="_blank" rel="noopener noreferrer" style="color:#66b2ff; text-decoration:underline;">' + forrasNev + '</a> ↗' +
'</span>';
var captionHtml = '<div class="lg-egyedi-felirat"><h4>' + felirat + '</h4>' + forrasLinkHtml + '</div>';
// ------------------------------------------------------------
var $lgItem = $('<a>', {
'href': imgUrl,
'class': 'lg-vegyes-item',
'data-src': imgUrl,
'data-sub-html': captionHtml // A teljes, működő HTML-t kapja meg a LightGallery
});
$('<img>', {
'src': imgUrl,
'class': 'galeria-kep url-kep',
'alt': felirat
}).appendTo($lgItem);
$doboz.prepend($lgItem);
$doboz.find('.url-link-szoveg').remove();
});
// 2. Belső MediaWiki <figure> képek kezelése
$container.find('figure').each(function() {
var $figure = $(this);
var $a = $figure.find('a.mw-file-description');
var $img = $figure.find('img.mw-file-element');
if ($a.length > 0 && $img.length > 0) {
var imgSrc = $img.attr('src');
var origSrc = imgSrc;
if (imgSrc.indexOf('/thumb/') !== -1) {
origSrc = imgSrc.replace('/thumb/', '/').substring(0, imgSrc.replace('/thumb/', '/').lastIndexOf('/'));
}
var $figcaption = $figure.find('figcaption');
var felirat = $figcaption.text().trim();
if (!felirat) {
var hrefAttr = $a.attr('href') || '';
var rawTitle = hrefAttr.substring(hrefAttr.lastIndexOf(':') + 1).split('.')[0];
felirat = decodeURIComponent(rawTitle).replace(/_/g, ' ');
$figcaption.text(felirat);
}
var captionHtml = '<h4>' + felirat + '</h4>';
// Itt szigorúan rákényszerítjük az attribútumokat a meglévő belső linkre
$a.addClass('lg-vegyes-item noviewer') // <--- IDE KERÜLT A NOVIEWER!
.attr('href', origSrc)
.attr('data-src', origSrc)
.attr('data-sub-html', captionHtml);
}
});
// 3. Inicializálás LightGallery v2-re optimalizálva
var lgInstance = lightGallery($container[0], {
selector: '.lg-vegyes-item',
licenseKey: '0000-0000-000-0000',
thumbnail: true,
animateThumb: true,
showThumbByDefault: true,
getCaptionFromTitleOrAlt: false // Ezzel kényszerítjük a v2-t a data-sub-html használatára
});
// V2-es eseménykezelő mentőövként, ha a getCaption valamiért mégis elbukna
$container[0].addEventListener('lgBeforeSlide', function(event) {
var index = event.detail.index;
var $item = $container.find('.lg-vegyes-item').eq(index);
var htmlSzoveg = $item.attr('data-sub-html');
if (htmlSzoveg) {
setTimeout(function() {
$('.lg-sub-html').html(htmlSzoveg);
}, 50);
}
});
});
}
})();
/**
* ============================================================================
* KIEGÉSZÍTŐIKONOK ÉS STÍLUSLAPOK BETÖLTÉSE
* ============================================================================
*/
var link = document.createElement("link");
link.rel = "stylesheet";
link.href = "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css";
document.head.appendChild(link);
/**
* ============================================================================
* JOGOSULTSÁGKEZELÉS (Fülek elrejtése anonim felhasználóknak)
* ============================================================================
*/
if (mw.config.get('wgUserName') === null) {
var hideTabs = function () {
var el1 = document.querySelector('#ca-history');
var el2 = document.querySelector('#ca-viewsource');
if (el1) el1.style.display = 'none';
if (el2) el2.style.display = 'none';
if (el1 || el2) clearInterval(observer);
};
var observer = setInterval(hideTabs, 100);
}
/**
* ============================================================================
* KÜLSŐ LINK VISLEKEDÉS (Új lapon nyíló külső hivatkozások)
* ============================================================================
*/
$(function () {
$('a.external').attr('target', '_blank');
});
/**
* ============================================================================
* NAVIGÁCIÓS GOMBOK (Tetejére és Vissza gomb logikája)
* ============================================================================
*/
$(function() {
// Tetejére gomb létrehozása
var $btn = $('<button/>', {
html: '<i class="bi bi-arrow-up-square"></i> Tetejére',
id: 'backToTopBtn',
title: 'Az oldal tetejére',
css: {
position: 'fixed',
bottom: '20px',
right: '20px',
padding: '10px 15px',
'font-size': '14px',
'background-color': '#888446ff',
color: 'white',
border: 'none',
'border-radius': '10px',
cursor: 'pointer',
display: 'none',
width: '100px',
'z-index': 1000
},
click: function() {
window.scrollTo({top: 0, behavior: 'smooth'});
}
});
// Vissza gomb létrehozása
var $backBtn = $('<button/>', {
html: '<i class="bi bi-arrow-left-square"></i> Vissza',
id: 'backBtn',
title: 'Előző oldal',
css: {
position: 'fixed',
bottom: '60px',
right: '20px',
padding: '10px 15px',
'font-size': '14px',
'background-color': '#547454ff',
color: 'white',
border: 'none',
'border-radius': '10px',
cursor: 'pointer',
display: 'none',
width: '100px',
'z-index': 1000
},
click: function() {
window.history.back();
}
});
$('body').append($btn).append($backBtn);
// Gombok láthatóságának kezelése görgetéskor
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$btn.fadeIn();
$backBtn.fadeIn();
} else {
$btn.fadeOut();
$backBtn.fadeOut();
}
});
});
/**
* ============================================================================
* TAXOBOX ÉS RENDSZERTANI LINKEK KEZELÉSE
* ============================================================================
*/
$(document).ready(function() {
$('.taxobox-icons a').attr('target', '_blank');
});
/**
* ============================================================================
* DATATABLES INTEGRÁCIÓ (Javított táblázatkezelés)
* ============================================================================
*/
mw.loader.using( ['jquery', 'mediawiki.util'] ).done( function () {
if ( $( '.datatable-hook' ).length > 0 ) {
$.getScript( 'https://cdn.datatables.net/2.1.8/js/dataTables.min.js' )
.done( function() {
$( '.datatable-hook' ).each( function() {
var $table = $(this);
var $headerRow = $table.find( 'tr:has(th)' ).first();
if ( $headerRow.length > 0 ) {
var $thead = $( '<thead></thead>' );
$headerRow.detach().appendTo( $thead );
$table.prepend( $thead );
}
$table.DataTable({
language: {
url: '//cdn.datatables.net/plug-ins/2.1.8/i18n/hu.json'
},
layout: {
topStart: 'pageLength',
topEnd: 'search',
bottomStart: 'info',
bottomEnd: 'paging'
},
pageLength: 10,
columnDefs: [ { targets: '_all', defaultContent: '' } ]
});
});
})
.fail( function() {
console.error( 'Hiba: Nem sikerült betölteni a DataTables szkriptet.' );
});
}
});
/**
* ============================================================================
* SZUKKULENS NÖVÉNYHATÁROZÓ KULCSOK LOGIKÁJA
* ============================================================================
*/
mw.hook('wikipage.content').add(function () {
const aktualisKategoriak = mw.config.get('wgCategories') || [];
if (!aktualisKategoriak.includes('Szukkulens növényhatározó kulcsok')) {
return;
}
const regexKoztespont = /^Szukkulens határozó:/;
const bodyContent = document.getElementById('bodyContent');
if (!bodyContent) return;
// Köztes határozó oldalak linkjei
bodyContent.querySelectorAll('a').forEach(a => {
const teljesNev = a.getAttribute('title') || '';
if (regexKoztespont.test(teljesNev)) {
let tisztaGombSzöveg = teljesNev.replace(/\s*\(a lap nem létezik\)$/, '');
a.innerHTML = '';
const arrowSpan = document.createElement('span');
arrowSpan.className = 'arrow-prefix';
arrowSpan.textContent = '→';
const spaceNode = document.createTextNode(' ');
const textNode = document.createTextNode(tisztaGombSzöveg);
a.appendChild(arrowSpan);
a.appendChild(spaceNode);
a.appendChild(textNode);
a.className = "new hatarozo-koztespont-btn";
let previousNode = a.previousSibling;
if (previousNode && previousNode.nodeType === Node.TEXT_NODE) {
previousNode.textContent = previousNode.textContent.replace(/[→\s\xA0→]+$/, '');
}
}
});
// Határozó kulcs valódi végpontjai
bodyContent.querySelectorAll('li').forEach(li => {
const bendoLinkek = li.querySelectorAll('a[href*="/wiki/"]:not(.external)');
bendoLinkek.forEach(link => {
const title = link.getAttribute('title') || '';
if (regexKoztespont.test(title) || link.classList.contains('hatarozo-koztespont-btn')) {
return;
}
let vizsgaltNode = link.previousSibling;
if (link.parentElement.tagName.toLowerCase() === 'i') {
vizsgaltNode = link.parentElement.previousSibling;
}
let elotteLevoSzo = "";
if (vizsgaltNode && vizsgaltNode.nodeType === Node.TEXT_NODE) {
elotteLevoSzo = vizsgaltNode.textContent;
}
if (!elotteLevoSzo.includes('Pl.') && !elotteLevoSzo.includes('(')) {
if (!link.classList.contains('hatarozo-vegpont-btn')) {
const tisztaFajnev = link.textContent.replace(/^[→\s\xA0]+/, '').replace(/[→\s\xA0]+$/, '').trim() || title;
link.innerHTML = `<span class="arrow-prefix">→ </span><span class="botanical-name">${tisztaFajnev}</span>`;
link.classList.add("hatarozo-vegpont-btn");
if (link.parentElement.tagName.toLowerCase() === 'i') {
link.parentElement.style.fontStyle = "normal";
}
}
if (vizsgaltNode && vizsgaltNode.nodeType === Node.TEXT_NODE) {
vizsgaltNode.textContent = vizsgaltNode.textContent.replace(/[→\s\xA0→]+$/, '');
}
}
});
});
});
/**
* ============================================================================
* NATÍV CIKKBELI KÉPEK AUTOMATIKUS LIGHTGALLERY-BE TERELÉSE (ÖSSZEFÜGGŐ GALÉRIA)
* ============================================================================
*/
window.addEventListener('click', function(e) {
// Elkapjuk az összes klasszikus MediaWiki képlinket
var targetLink = e.target.closest('a.mw-file-description, a.image');
if (!targetLink) return;
// Kihagyjuk a már meglévő egyedi galériákat, ha vannak
if (targetLink.closest('.egyedi-galeria-container') || targetLink.closest('.wiki-dynamic-gallery')) return;
// Fájl leíró oldalakon ne fusson, ott kell a gyári működés
if (window.location.pathname.includes('/wiki/F%C3%A1jl:') || window.location.pathname.includes('/wiki/File:')) {
return;
}
// AZONNAL megállítjuk a gyári átirányítást a /wiki/Fájl: oldalra
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
var dynamicSlides = [];
var clickedIndex = 0;
// Összegyűjtjük az összes natív képet az oldalon, ami NEM része egyedi galériának
var $mindenNativA = $('a.mw-file-description, a.image').filter(function() {
return $(this).closest('.egyedi-galeria-container').length === 0 && $(this).closest('.wiki-dynamic-gallery').length === 0;
});
$mindenNativA.each(function(index) {
var $el = $(this);
var $img = $el.find('img');
if ($img.length > 0) {
if ($el.is(targetLink)) {
clickedIndex = index;
}
// Retina/HD fix: ha van srcset, a legnagyobb felbontásút használjuk eredetiként
var origSrc = $img.attr('srcset') ?
$img.attr('srcset').split(',').pop().trim().split(' ')[0] :
$el.attr('href');
var thumbSrc = $img.attr('src');
// Képaláírás kinyerése a MediaWiki struktúrából
var captionText = '';
var figure = $el.closest('figure, .thumb');
if (figure) {
var figcaption = figure.querySelector('figcaption, .thumbcaption');
if (figcaption) {
captionText = figcaption.textContent.replace(/×/g, '').trim();
}
}
if (!captionText) {
captionText = $img.attr('alt') || $img.attr('title') || '';
}
dynamicSlides.push({
src: origSrc,
thumb: thumbSrc,
subHtml: captionText ? '<h4>' + captionText + '</h4>' : ''
});
}
});
// LightGallery indítása dinamikus tömbbel
if (window.lightGallery && dynamicSlides.length > 0) {
var container = document.createElement('div');
var dynamicGallery = lightGallery(container, {
dynamic: true,
dynamicEl: dynamicSlides,
licenseKey: '0000-0000-000-0000',
thumbnail: true,
animateThumb: true,
showThumbByDefault: true,
index: clickedIndex,
download: true,
counter: dynamicSlides.length > 1
});
dynamicGallery.openGallery();
} else {
console.error("LightGallery hiba: a könyvtár nem érhető el a kattintáskor.");
}
}, true); // Capturing fázis!