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ó
1. sor: 1. sor:
/* ==========================================================================
/* LightGallery + Commons API Integráció */
  UNIVERZÁLIS GALÉRIA ÉS WIKI FUNKCIÓK
(function() {
  Tartalmazza: LightGallery (Commons + Helyi), DataTables, UI gombok
    // Csak akkor fusson, ha van galéria az oldalon
  ========================================================================== */
    if ($('.wiki-dynamic-gallery').length === 0) return;


(function() {
     // Erőforrások betöltése mw.loader-rel
     // 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";');
     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() {
     $.getScript('https://cdn.jsdelivr.net/npm/lightgallery@2.4.0/lightgallery.umd.min.js')
          
         .done(function() {
        // --- A: HELYI KÉPEK ELŐKÉSZÍTÉSE (Sablonok + Bélyegképek) ---
             console.log('LightGallery 2.4.0 inicializálva.');
        function prepareLocalImages() {
            initWikiDynamicGallery();
             // 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);
    function initWikiDynamicGallery() {
                var $img = $link.find('img');
        $('.wiki-dynamic-gallery').each(function() {
               
            var $container = $(this);
                if ($img.length > 0) {
            if ($container.data('initialized')) return;
                    var src = $img.attr('src');
            $container.data('initialized', true);
                    // 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-.*$/, '');
            var searchTerm = $container.data('search');
                   
            var limit = $container.data('limit') || 3;
                    $link.attr('data-src', fullSrc);
             var targetHeight = 200;
                    $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Ő ---
             var apiUrl = "https://commons.wikimedia.org/w/api.php?action=query&format=json&generator=search&gsrsearch=File:" +
        function initWikiDynamicGallery() {
                        encodeURIComponent(searchTerm) + "&gsrlimit=" + limit +
             var $dynGalleries = $('.wiki-dynamic-gallery');
                        "&prop=imageinfo&iiprop=url|size&iiurlheight=" + targetHeight + "&origin=*";
           
            // Ha nincs dinamikus galéria, csak a helyieket indítjuk
            if ($dynGalleries.length === 0) {
                finalizeGallery();
                return;
            }


            var processed = 0;
             $.getJSON(apiUrl, function(data) {
             $dynGalleries.each(function() {
                 if (data && data.query && data.query.pages) {
                 var $container = $(this);
                    var pages = data.query.pages;
                var searchTerm = $container.data('search');
                    var galleryHtml = '';
                var limit = $container.data('limit') || 3;


                var apiUrl = "https://commons.wikimedia.org/w/api.php?action=query&format=json&generator=search&gsrsearch=File:" +
                    for (var id in pages) {
                            encodeURIComponent(searchTerm) + "&gsrlimit=" + limit +
                        if (!pages[id].imageinfo) continue;
                            "&prop=imageinfo&iiprop=url|size&iiurlheight=200&origin=*";
                        var img = pages[id].imageinfo[0];
                        var title = pages[id].title.replace('File:', '');


                $.getJSON(apiUrl, function(data) {
                        galleryHtml += '<a href="' + img.url + '" class="lg-item" data-src="' + img.url + '" data-sub-html="<h4>' + title + '</h4>">';
                    if (data && data.query && data.query.pages) {
                         galleryHtml += '  <img src="' + img.thumburl + '" style="height:' + targetHeight + 'px; width:auto; margin:5px; border-radius:6px; cursor:pointer;" alt="' + title + '" />';
                        var pages = data.query.pages;
                        galleryHtml += '</a>';
                        var html = '';
                    }
                         for (var id in pages) {
                    $container.html(galleryHtml);
                            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>">';
                    if (window.lightGallery) {
                            html += '  <img src="' + img.thumburl + '" style="height:200px; width:auto; margin:5px; border-radius:6px; cursor:pointer;" alt="' + title + '" />';
                        lightGallery($container[0], {
                            html += '</a>';
                             selector: '.lg-item',
                         }
                            licenseKey: '0000-0000-000-0000'
                        $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
// Bootstrap Icons betöltése
var biLink = document.createElement("link");
var link = document.createElement("link");
biLink.rel = "stylesheet";
link.rel = "stylesheet";
biLink.href = "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css";
//link.href = "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css";
document.head.appendChild(biLink);
link.href = "https://cdn.jsdelivr.net/npm/bootstrap-icons@1.13.1/font/bootstrap-icons.min.css";
document.head.appendChild(link);


// Fülek elrejtése anonim felhasználóknak
/* Az ide elhelyezett JavaScript kód minden felhasználó számára lefut az oldalak betöltésekor. */
// Fülek elrejtése anonim felhasználók számára
if (mw.config.get('wgUserName') === null) {
if (mw.config.get('wgUserName') === null) {
     var observer = setInterval(function() {
     var hideTabs = function () {
         var el1 = document.querySelector('#ca-history'), el2 = document.querySelector('#ca-viewsource');
         var el1 = document.querySelector('#ca-history');
        var el2 = document.querySelector('#ca-viewsource');
         if (el1) el1.style.display = 'none';
         if (el1) el1.style.display = 'none';
         if (el2) el2.style.display = 'none';
         if (el2) el2.style.display = 'none';
        // Ha mindkét elem megtalálható, leállítjuk az ismétlést
         if (el1 || el2) clearInterval(observer);
         if (el1 || el2) clearInterval(observer);
     }, 100);
     };
 
    // 100ms-onként ellenőrizzük, hogy megjelentek-e a fülek
    var observer = setInterval(hideTabs, 100);
}
}


// Külső linkek új lapon
/* MediaWikiben az alapértelmezett viselkedés az, hogy a külső hivatkozások (pl. [https://példa.hu link szövege]) ugyanazon a lapon nyílnak meg.
$(function () { $('a.external').attr('target', '_blank'); });
Ahhoz, hogy ezek új lapon nyíljanak meg:*/
$(function () {
  $('a.external').attr('target', '_blank');
});


// Tetejére és Vissza gombok
// Egy "Tetejére" gomb megjelenítése és kattintáskor scrollozás az oldal tetejére
$(function() {
$(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 };
    // Létrehozzuk a gombot
   
     var $btn = $('<button/>', {
    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'}); } });
        //text: '⬆ Tetejére',
     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(); } });
        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',   // alapból rejtve
            width: '100px',
            'z-index': 1000
        },
        click: function() {
            window.scrollTo({top: 0, behavior: 'smooth'});
        }
     });


     $('body').append($topBtn, $backBtn);
    // A body végére tesszük a gombot
     $('body').append($btn);
 
    // Megjelenítés, ha az oldal le van görgetve 100px-nél
     $(window).scroll(function() {
     $(window).scroll(function() {
         if ($(window).scrollTop() > 100) { $topBtn.fadeIn(); $backBtn.fadeIn(); }
         if ($(window).scrollTop() > 100) {
         else { $topBtn.fadeOut(); $backBtn.fadeOut(); }
            $btn.fadeIn();
         } else {
            $btn.fadeOut();
        }
     });
     });
});
});


/* --- DATATABLES INTEGRÁCIÓ --- */
// Egy "Vissza" gomb megjelenítése, ami az előző oldalra mutat
mw.loader.using(['jquery', 'mediawiki.util']).done(function() {
$(function() {
     if ($('.datatable-hook').length > 0) {
    // Vissza gomb létrehozása
         $.getScript('https://cdn.datatables.net/2.1.8/js/dataTables.min.js').done(function() {
    var $backBtn = $('<button/>', {
            $('.datatable-hook').each(function() {
//      text: '⬅ Vissza',
                var $table = $(this);
        html: '<i class="bi bi-arrow-left-square"></i> Vissza',
                var $headerRow = $table.find('tr:has(th)').first();
        id: 'backBtn',
                if ($headerRow.length > 0) {
        title: 'Előző oldal',
                    var $thead = $('<thead></thead>');
        css: {
                    $headerRow.detach().appendTo($thead);
            position: 'fixed',
                    $table.prepend($thead);
            bottom: '60px',  // a "Tetejére" gomb fölé kerül
                }
            right: '20px',
                $table.DataTable({
            padding: '10px 15px',
                    language: { url: '//cdn.datatables.net/plug-ins/2.1.8/i18n/hu.json' },
            'font-size': '14px',
                    pageLength: 10,
            'background-color': '#547454ff',
                    columnDefs: [{ targets: '_all', defaultContent: '' }]
            color: 'white',
            border: 'none',
            'border-radius': '10px',
            cursor: 'pointer',
            display: 'none',
            width: '100px',
            'z-index': 1000
        },
        click: function() {
            window.history.back();
        }
    });
 
    // Hozzáadás a DOM-hoz
    $('body').append($backBtn);
 
    // Megjelenítés görgetés után
    $(window).scroll(function() {
        if ($(window).scrollTop() > 100) {
            $backBtn.fadeIn();
        } else {
            $backBtn.fadeOut();
        }
    });
});
 
/* Taxobox ikonok megnyitása új lapon */
$(document).ready(function() {
    $('.taxobox-icons a').attr('target', '_blank');
});
 
/**
* DataTables 2.1.8 integráció - MediaWiki javított verzió
*/
mw.loader.using( ['jquery', 'mediawiki.util'] ).done( function () {
 
     if ( $( '.datatable-hook' ).length > 0 ) {
 
        // DataTables JS betöltése
         $.getScript( 'https://cdn.datatables.net/2.1.8/js/dataTables.min.js' )
            .done( function() {
 
                $( '.datatable-hook' ).each( function() {
                    var $table = $(this);
 
                    // 1. LÉPÉS: A MediaWiki hibás struktúrájának javítása
                    // Megkeressük az első sort, amiben TH (fejléc) cellák vannak
                    var $headerRow = $table.find( 'tr:has(th)' ).first();
 
                    if ( $headerRow.length > 0 ) {
                        // Létrehozunk egy THEAD-et és belemozgatjuk a fejléc sort
                        var $thead = $( '<thead></thead>' );
                        $headerRow.detach().appendTo( $thead );
                        $table.prepend( $thead );
                    }
 
                    // 2. LÉPÉS: Inicializálás a javított táblázaton
                    $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,
                        // Biztonsági beállítás: ne álljon le hibával, ha mégis eltérés lenne
                        columnDefs: [ { targets: '_all', defaultContent: '' } ]
                    });
                 });
                 });
            })
            .fail( function() {
                console.error( 'Hiba: Nem sikerült betölteni a DataTables szkriptet.' );
             });
             });
        });
     }
     }
});
mw.hook('wikipage.content').add(function () {
    const regex = /^Szukkulens határozó: .+/;
    document.querySelectorAll('a').forEach(a => {
        const linkText = a.textContent.trim();
        if (regex.test(linkText)) {
            a.classList.add("hatarozo-custom-btn");
        }
    });
});
});

A lap 2026. május 24., 09:40-kori változata

/* LightGallery + Commons API Integráció */
(function() {
    // Csak akkor fusson, ha van galéria az oldalon
    if ($('.wiki-dynamic-gallery').length === 0) return;

    // Erőforrások betöltése mw.loader-rel
    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')
        .done(function() {
            console.log('LightGallery 2.4.0 inicializálva.');
            initWikiDynamicGallery();
        });

    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'
                        });
                    }
                }
            });
        });
    }
})();


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

/* Az ide elhelyezett JavaScript kód minden felhasználó számára lefut az oldalak betöltésekor. */
// Fülek elrejtése anonim felhasználók számára
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';

        // Ha mindkét elem megtalálható, leállítjuk az ismétlést
        if (el1 || el2) clearInterval(observer);
    };

    // 100ms-onként ellenőrizzük, hogy megjelentek-e a fülek
    var observer = setInterval(hideTabs, 100);
}

/* MediaWikiben az alapértelmezett viselkedés az, hogy a külső hivatkozások (pl. [https://példa.hu link szövege]) ugyanazon a lapon nyílnak meg.
Ahhoz, hogy ezek új lapon nyíljanak meg:*/
$(function () {
  $('a.external').attr('target', '_blank');
});

// Egy "Tetejére" gomb megjelenítése és kattintáskor scrollozás az oldal tetejére
$(function() {
    // Létrehozzuk a gombot
    var $btn = $('<button/>', {
        //text: '⬆ Tetejére',
        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',   // alapból rejtve
            width: '100px',
            'z-index': 1000
        },
        click: function() {
            window.scrollTo({top: 0, behavior: 'smooth'});
        }
    });

    // A body végére tesszük a gombot
    $('body').append($btn);

    // Megjelenítés, ha az oldal le van görgetve 100px-nél
    $(window).scroll(function() {
        if ($(window).scrollTop() > 100) {
            $btn.fadeIn();
        } else {
            $btn.fadeOut();
        }
    });
});

// Egy "Vissza" gomb megjelenítése, ami az előző oldalra mutat
$(function() {
    // Vissza gomb létrehozása
    var $backBtn = $('<button/>', {
//      text: '⬅ Vissza',
        html: '<i class="bi bi-arrow-left-square"></i> Vissza',
        id: 'backBtn',
        title: 'Előző oldal',
        css: {
            position: 'fixed',
            bottom: '60px',  // a "Tetejére" gomb fölé kerül
            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();
        }
    });

    // Hozzáadás a DOM-hoz
    $('body').append($backBtn);

    // Megjelenítés görgetés után
    $(window).scroll(function() {
        if ($(window).scrollTop() > 100) {
            $backBtn.fadeIn();
        } else {
            $backBtn.fadeOut();
        }
    });
});

/* Taxobox ikonok megnyitása új lapon */
$(document).ready(function() {
    $('.taxobox-icons a').attr('target', '_blank');
});

/**
 * DataTables 2.1.8 integráció - MediaWiki javított verzió
 */
mw.loader.using( ['jquery', 'mediawiki.util'] ).done( function () {

    if ( $( '.datatable-hook' ).length > 0 ) {

        // DataTables JS betöltése
        $.getScript( 'https://cdn.datatables.net/2.1.8/js/dataTables.min.js' )
            .done( function() {

                $( '.datatable-hook' ).each( function() {
                    var $table = $(this);

                    // 1. LÉPÉS: A MediaWiki hibás struktúrájának javítása
                    // Megkeressük az első sort, amiben TH (fejléc) cellák vannak
                    var $headerRow = $table.find( 'tr:has(th)' ).first();

                    if ( $headerRow.length > 0 ) {
                        // Létrehozunk egy THEAD-et és belemozgatjuk a fejléc sort
                        var $thead = $( '<thead></thead>' );
                        $headerRow.detach().appendTo( $thead );
                        $table.prepend( $thead );
                    }

                    // 2. LÉPÉS: Inicializálás a javított táblázaton
                    $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,
                        // Biztonsági beállítás: ne álljon le hibával, ha mégis eltérés lenne
                        columnDefs: [ { targets: '_all', defaultContent: '' } ]
                    });
                });

            })
            .fail( function() {
                console.error( 'Hiba: Nem sikerült betölteni a DataTables szkriptet.' );
            });
    }
});

mw.hook('wikipage.content').add(function () {
    const regex = /^Szukkulens határozó: .+/;

    document.querySelectorAll('a').forEach(a => {
        const linkText = a.textContent.trim();

        if (regex.test(linkText)) {
            a.classList.add("hatarozo-custom-btn");
        }
    });
});