Ugrás a tartalomhoz

MediaWiki:Common.js

Innen: MKOE wiki
A lap korábbi változatát látod, amilyen Dr. Gyúró Zoltán (vitalap | szerkesztései) 2026. május 1., 14:13-kor történt szerkesztése után volt.

Megjegyzés: közzététel után frissítened kell a böngésződ gyorsítótárát, hogy lásd a változásokat.

  • Firefox / Safari: tartsd lenyomva a Shift gombot és kattints a Frissítés gombra a címsorban, vagy használd a Ctrl–F5 vagy Ctrl–R (Macen ⌘–R) billentyűkombinációt
  • Google Chrome: használd a Ctrl–Shift–R (Macen ⌘–Shift–R) billentyűkombinációt
  • Edge: tartsd nyomva a Ctrl-t, és kattints a Frissítés gombra, vagy nyomj Ctrl–F5-öt
/* ==========================================================================
   UNIVERZÁLIS GALÉRIA ÉS WIKI FUNKCIÓK
   Tartalmazza: LightGallery (Commons + Helyi), DataTables, UI gombok
   ========================================================================== */

(function() {
    // 1. Erőforrások betöltése
    mw.loader.addStyleTag('@import "https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/css/lightgallery-bundle.min.css";');

    $.getScript('https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/lightgallery.umd.min.js', function() {
        
        // --- A: HELYI KÉPEK ELŐKÉSZÍTÉSE (Sablonok + Bélyegképek) ---
        function prepareLocalImages() {
            // Megkeressük az összes wiki képet (infobox, taxobox, thumb, vagy sima beillesztett kép)
            $('.infobox a.image, .taxobox a.image, .thumb a.image, a.image').each(function() {
                var $link = $(this);
                var $img = $link.find('img');
                
                if ($img.length > 0) {
                    var src = $img.attr('src');
                    // Eredeti kép URL kiszámítása (eltávolítjuk a /thumb/ részt és a méret korlátozást)
                    var fullSrc = src.replace(/\/thumb\//, '/').replace(/\/\d+px-.*$/, '');
                    
                    $link.attr('data-src', fullSrc);
                    $link.addClass('lg-unified-item'); // Közös osztály a lapozhatósághoz
                    
                    // Képaláírás kinyerése
                    var caption = $link.closest('.thumbinner').find('.thumbcaption').text() || $img.attr('alt') || "";
                    $link.attr('data-sub-html', '<h4>' + caption + '</h4>');
                }
            });
        }

        // --- B: COMMONS DINAMIKUS GALÉRIA ÉPÍTŐ ---
        function initWikiDynamicGallery() {
            var $dynGalleries = $('.wiki-dynamic-gallery');
            
            // Ha nincs dinamikus galéria, csak a helyieket indítjuk
            if ($dynGalleries.length === 0) {
                finalizeGallery();
                return;
            }

            var processed = 0;
            $dynGalleries.each(function() {
                var $container = $(this);
                var searchTerm = $container.data('search');
                var limit = $container.data('limit') || 3;

                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=200&origin=*";

                $.getJSON(apiUrl, function(data) {
                    if (data && data.query && data.query.pages) {
                        var pages = data.query.pages;
                        var html = '';
                        for (var id in pages) {
                            if (!pages[id].imageinfo) continue;
                            var img = pages[id].imageinfo[0];
                            var title = pages[id].title.replace('File:', '');

                            html += '<a href="' + img.url + '" class="lg-unified-item" data-src="' + img.url + '" data-sub-html="<h4>' + title + '</h4>">';
                            html += '  <img src="' + img.thumburl + '" style="height:200px; width:auto; margin:5px; border-radius:6px; cursor:pointer;" alt="' + title + '" />';
                            html += '</a>';
                        }
                        $container.html(html);
                    }
                    processed++;
                    // Ha az összes API hívás kész, indítjuk a galériát
                    if (processed === $dynGalleries.length) finalizeGallery();
                });
            });
        }

        // --- C: A KÖZÖS GALÉRIA INICIALIZÁLÁSA ---
        function finalizeGallery() {
            prepareLocalImages(); // Helyi képek felcímkézése
            
            if (window.lightGallery) {
                lightGallery(document.body, {
                    selector: '.lg-unified-item', // Csak azokat a linkeket gyűjti be, amiket mi megjelöltünk
                    hash: false,
                    download: true,
                    speed: 400,
                    licenseKey: '0000-0000-000-0000'
                });
            }
        }

        // Indítás
        $(document).ready(function() {
            initWikiDynamicGallery();
        });
    });
})();

/* --- EGYÉB UI FUNKCIÓK --- */

// Bootstrap Icons betöltése
var biLink = document.createElement("link");
biLink.rel = "stylesheet";
biLink.href = "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css";
document.head.appendChild(biLink);

// Fülek elrejtése anonim felhasználóknak
if (mw.config.get('wgUserName') === null) {
    var observer = setInterval(function() {
        var el1 = document.querySelector('#ca-history'), el2 = document.querySelector('#ca-viewsource');
        if (el1) el1.style.display = 'none';
        if (el2) el2.style.display = 'none';
        if (el1 || el2) clearInterval(observer);
    }, 100);
}

// Külső linkek új lapon
$(function () { $('a.external').attr('target', '_blank'); });

// Tetejére és Vissza gombok
$(function() {
    var btnStyle = { position: 'fixed', right: '20px', padding: '10px 15px', 'font-size': '14px', color: 'white', border: 'none', 'border-radius': '10px', cursor: 'pointer', display: 'none', width: '100px', 'z-index': 1000 };
    
    var $topBtn = $('<button/>', { html: '<i class="bi bi-arrow-up-square"></i> Tetejére', css: $.extend({}, btnStyle, { bottom: '20px', 'background-color': '#888446' }), click: function() { window.scrollTo({top: 0, behavior: 'smooth'}); } });
    var $backBtn = $('<button/>', { html: '<i class="bi bi-arrow-left-square"></i> Vissza', css: $.extend({}, btnStyle, { bottom: '65px', 'background-color': '#547454' }), click: function() { window.history.back(); } });

    $('body').append($topBtn, $backBtn);
    $(window).scroll(function() {
        if ($(window).scrollTop() > 100) { $topBtn.fadeIn(); $backBtn.fadeIn(); }
        else { $topBtn.fadeOut(); $backBtn.fadeOut(); }
    });
});

/* --- DATATABLES INTEGRÁCIÓ --- */
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' },
                    pageLength: 10,
                    columnDefs: [{ targets: '_all', defaultContent: '' }]
                });
            });
        });
    }
});