Ugrás a tartalomhoz

„MediaWiki:Common.js” változatai közötti eltérés

Innen: MKOE wiki
Nincs szerkesztési összefoglaló
Nincs szerkesztési összefoglaló
416. sor: 416. sor:
/**
/**
  * ============================================================================
  * ============================================================================
  * NATÍV CIKKBELI KÉPEK (3. ESET) AUTOMATIKUS LIGHTGALLERY INTEGRÁCIÓJA (UNIVERZÁLIS KATTINTÁS)
  * NATÍV CIKKBELI KÉPEK (3. ESET) AUTOMATIKUS LIGHTGALLERY INTEGRÁCIÓJA (ÉLŐ ADATGYŰJTÉS)
  * ============================================================================
  * ============================================================================
  */
  */
mw.hook('wikipage.content').add(function($content) {
mw.hook('wikipage.content').add(function($content) {
    // 1. Csak az osztályokat és az alapértelmezett attribútumokat készítjük elő az oldalon
     var $nativKepek = $content.find('figure[typeof*="mw:File/Thumb"]').filter(function() {
     var $nativKepek = $content.find('figure[typeof*="mw:File/Thumb"]').filter(function() {
         return $(this).closest('.egyedi-galeria-container').length === 0;
         return $(this).closest('.egyedi-galeria-container').length === 0;
426. sor: 427. sor:
     if ($nativKepek.length === 0) return;
     if ($nativKepek.length === 0) return;


    var dynamicSlides = [];
     $nativKepek.each(function() {
 
    // 1. Adatgyűjtés és attribútumok felrakása
     $nativKepek.each(function(index) {
         var $figure = $(this);
         var $figure = $(this);
         var $a = $figure.find('a.mw-file-description');
         var $a = $figure.find('a.mw-file-description');
435. sor: 433. sor:


         if ($a.length > 0 && $img.length > 0) {
         if ($a.length > 0 && $img.length > 0) {
            $a.attr('data-lg-index', index);
             if (!$a.hasClass('lg-nativ-ready')) {
             if (!$a.hasClass('lg-nativ-ready')) {
                 $a.addClass('lg-nativ-ready lg-nativ-item noviewer');
                 $a.addClass('lg-nativ-ready lg-nativ-item noviewer');
454. sor: 450. sor:
                   .attr('data-sub-html', captionHtml);
                   .attr('data-sub-html', captionHtml);
             }
             }
            dynamicSlides.push({
                src: $a.attr('data-src'),
                thumb: $img.attr('src'),
                subHtml: $a.attr('data-sub-html')
            });
         }
         }
     });
     });
});


    // 2. Brutálisan biztos, globális dokumentum-szintű kattintáskezelő
// 2. Globális kattintáskezelő az mw.hook-on KÍVÜL, ami kattintáskor ÉLŐBEN építi fel a galériát
    // Ezt csak egyszer kötjük be globalizálva, levéve a korábbiakat
$(document).off('click', 'a.lg-nativ-item').on('click', 'a.lg-nativ-item', function(e) {
    $(document).off('click', 'a.lg-nativ-item').on('click', 'a.lg-nativ-item', function(e) {
    e.preventDefault();
        e.preventDefault();
    e.stopImmediatePropagation(); // Megállítunk minden gyári MediaWiki és egyéb scriptet
        e.stopImmediatePropagation(); // Megállít minden más MediaWiki scriptet, ami ide akarna ugrani


        var clickedIndex = parseInt($(this).attr('data-lg-index'), 10);
    var $vlasztottLink = $(this);
        if (isNaN(clickedIndex)) clickedIndex = 0;
    var dynamicSlides = [];
    var clickedIndex = 0;


        if (window.lightGallery && dynamicSlides.length > 0) {
    // Élőben végigmegyünk az oldalon található ÖSSZES aktív natív képen
            var container = document.createElement('div');
    $('a.lg-nativ-item').each(function(index) {
            var dynamicGallery = lightGallery(container, {
        var $el = $(this);
                dynamic: true,
                dynamicEl: dynamicSlides,
                licenseKey: '0000-0000-000-0000',
                thumbnail: true,
                animateThumb: true,
                showThumbByDefault: true,
                index: clickedIndex
            });


            dynamicGallery.openGallery();
        // Ha ez a most megkattintott kép, elmentjük az indexét
        if ($el.is($vlasztottLink)) {
            clickedIndex = index;
         }
         }
         return false;
 
         dynamicSlides.push({
            src: $el.attr('data-src') || $el.attr('href'),
            thumb: $el.find('img').attr('src'),
            subHtml: $el.attr('data-sub-html')
        });
     });
     });
    // Ha van kép és betöltődött a LightGallery, azonnal indítjuk
    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
        });
        dynamicGallery.openGallery();
    }
    return false;
});
});

A lap 2026. június 18., 08:24-kori változata

/**
 * ============================================================================
 * LIGHTGALLERY GLOBÁLIS INTEGRÁCIÓ (Régi dynamic és új vegyes galéria)
 * ============================================================================
 */
(function() {
    // 1. LÉPÉS: Ellenőrizzük, hogy BÁRMELYIK galéria típus létezik-e az oldalon. Ha egyik sincs, csak akkor állunk le.
    if ($('.wiki-dynamic-gallery').length === 0 && $('.egyedi-galeria-container').length === 0) return;

    // Erőforrások betöltése mw.loader-rel (Csak egyszer fut le az oldalon)
    mw.loader.addStyleTag('@import "https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/css/lightgallery-bundle.min.css";');

    // LightGallery mag betöltése
    $.getScript('https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/lightgallery.umd.min.js')
        .done(function() {
            console.log('LightGallery 2.4.0 sikeresen betöltve.');

            // Ha a régi típusú galéria van az oldalon, elindítjuk
            if ($('.wiki-dynamic-gallery').length > 0) {
                initWikiDynamicGallery();
            }

            // Ha az új típusú vegyes galéria van az oldalon, elindítjuk
            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&rarr;]+$/, '');
            }
        }
    });

    // 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&rarr;]+$/, '');
                }
            }
        });
    });
});

/**
 * ============================================================================
 * NATÍV CIKKBELI KÉPEK (3. ESET) AUTOMATIKUS LIGHTGALLERY INTEGRÁCIÓJA (ÉLŐ ADATGYŰJTÉS)
 * ============================================================================
 */
mw.hook('wikipage.content').add(function($content) {
    // 1. Csak az osztályokat és az alapértelmezett attribútumokat készítjük elő az oldalon
    var $nativKepek = $content.find('figure[typeof*="mw:File/Thumb"]').filter(function() {
        return $(this).closest('.egyedi-galeria-container').length === 0;
    });

    if ($nativKepek.length === 0) return;

    $nativKepek.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) {
            if (!$a.hasClass('lg-nativ-ready')) {
                $a.addClass('lg-nativ-ready lg-nativ-item noviewer');

                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();
                var captionHtml = felirat ? '<h4>' + felirat + '</h4>' : '';

                $a.attr('href', origSrc)
                  .attr('data-src', origSrc)
                  .attr('data-sub-html', captionHtml);
            }
        }
    });
});

// 2. Globális kattintáskezelő az mw.hook-on KÍVÜL, ami kattintáskor ÉLŐBEN építi fel a galériát
$(document).off('click', 'a.lg-nativ-item').on('click', 'a.lg-nativ-item', function(e) {
    e.preventDefault();
    e.stopImmediatePropagation(); // Megállítunk minden gyári MediaWiki és egyéb scriptet

    var $vlasztottLink = $(this);
    var dynamicSlides = [];
    var clickedIndex = 0;

    // Élőben végigmegyünk az oldalon található ÖSSZES aktív natív képen
    $('a.lg-nativ-item').each(function(index) {
        var $el = $(this);

        // Ha ez a most megkattintott kép, elmentjük az indexét
        if ($el.is($vlasztottLink)) {
            clickedIndex = index;
        }

        dynamicSlides.push({
            src: $el.attr('data-src') || $el.attr('href'),
            thumb: $el.find('img').attr('src'),
            subHtml: $el.attr('data-sub-html')
        });
    });

    // Ha van kép és betöltődött a LightGallery, azonnal indítjuk
    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
        });

        dynamicGallery.openGallery();
    }
    return false;
});