Немає опису редагування
Немає опису редагування
Рядок 29: Рядок 29:
     items.each(function() {
     items.each(function() {
         var href = $(this).find('a').attr('href');
         var href = $(this).find('a').attr('href');
         if (href && href.startsWith('#')) {
         if (href && href.indexOf('#') === 0) {
             var target = $(href.replace(/\./g, '\\.'));
             var id = decodeURIComponent(href.substring(1));
             if (target.length) {
            var target = document.getElementById(id);
                 sections.push({item: $(this), target: target});
             if (target) {
                 sections.push({item: $(this), target: $(target)});
             }
             }
         }
         }
Рядок 41: Рядок 42:
         var current = null;
         var current = null;
          
          
         sections.forEach(function(s) {
         for (var i = 0; i < sections.length; i++) {
             if (s.target.offset().top <= scrollPos) {
             if (sections[i].target.offset().top <= scrollPos) {
                 current = s.item;
                 current = sections[i].item;
             }
             }
         });
         }
          
          
         items.removeClass('active');
         items.removeClass('active');

Версія за 19:41, 8 грудня 2025

$(document).ready(function() {
    var apiUrl = mw.config.get('wgScriptPath') + '/api.php';
    $.getJSON(apiUrl, {
        action: 'query',
        format: 'json',
        list: 'random',
        rnnamespace: '0',
        rnlimit: '5',  // fetch five random articles
        prop: 'extracts',
        exchars: '250',  // limit the preview to 250 characters
        exlimit: 'max',
        explaintext: true
    }, function(data) {
        var html = '';
        $.each(data.query.random, function(i, article) {
            html += '<div class="random-article-preview">';
            html += '<h2><a href="/wiki/' + encodeURIComponent(article.title) + '">' + article.title + '</a></h2>';
            html += '<p>' + article.extract + '</p>';
            html += '</div>';
        });
        $('#random-articles-container').html(html);
    });
});

$(function() {
    var items = $('.l-box-item');
    var sections = [];
    
    items.each(function() {
        var href = $(this).find('a').attr('href');
        if (href && href.indexOf('#') === 0) {
            var id = decodeURIComponent(href.substring(1));
            var target = document.getElementById(id);
            if (target) {
                sections.push({item: $(this), target: $(target)});
            }
        }
    });
    
    $(window).on('scroll', function() {
        var scrollPos = $(window).scrollTop() + 100;
        var current = null;
        
        for (var i = 0; i < sections.length; i++) {
            if (sections[i].target.offset().top <= scrollPos) {
                current = sections[i].item;
            }
        }
        
        items.removeClass('active');
        if (current) {
            current.addClass('active');
        }
    });
});