MediaWiki:Common.js: відмінності між версіями

нема опису редагування
Немає опису редагування
Немає опису редагування
Рядок 96: Рядок 96:
});
});


// Виправлення пошуку - прямий перехід замість overlay
$(document).ready(function() {
$(document).ready(function() {
     // Затримка щоб DOM повністю завантажився
     var apiUrl = mw.config.get('wgScriptPath') + '/api.php';
     setTimeout(function() {
     $.getJSON(apiUrl, {
         var $searchInput = $('#searchInput');
        action: 'query',
        var $searchBox = $('.minerva-header .search-box');
        format: 'json',
         var $searchForm = $('.minerva-search-form');
        list: 'random',
        rnnamespace: '0',
        rnlimit: '5',
        prop: 'extracts',
        exchars: '250',
        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);
    });
});
 
// L-box navigation
$(function() {
    var items = $('.l-box-item');
    var sections = [];
   
    items.each(function() {
         var target = $(this).data('target');
        if (target === 'top') {
            sections.push({item: $(this), target: null, offset: 0});
        } else {
            var el = document.getElementById(target);
            if (el) {
                sections.push({item: $(this), target: $(el), offset: $(el).offset().top});
            }
        }
    });
   
    items.on('click', function() {
        var target = $(this).data('target');
        var scrollTo = 0;
       
        if (target === 'top') {
            scrollTo = 0;
        } else {
            var el = document.getElementById(target);
            if (el) {
                scrollTo = $(el).offset().top - 40;
            }
        }
          
          
         // Прибираємо readonly
         $('html, body').animate({scrollTop: scrollTo}, 300);
        $searchInput.removeAttr('readonly');
    });
   
    $(window).on('scroll', function() {
        var scrollPos = $(window).scrollTop() + 100;
        var current = null;
          
          
         // Прибираємо класи тригера
         for (var i = 0; i < sections.length; i++) {
        $searchInput.removeClass('skin-minerva-search-trigger');
            var checkPos = sections[i].target ? sections[i].target.offset().top : 0;
            if (checkPos <= scrollPos) {
                current = sections[i].item;
            }
        }
          
          
         // Блокуємо стандартну поведінку форми
         items.removeClass('active');
         $searchForm.off('click submit');
        if (current) {
         $searchBox.off('click');
            current.addClass('active');
        }
    });
   
    $(window).trigger('scroll');
});
 
// Profile icons
$(document).ready(function() {
    $('.profile-icon').each(function() {
         var icon = $(this);
        var url = icon.attr('data-url');
        if (url && url.trim() !== '') {
            icon.css('cursor', 'pointer');
            icon.on('click', function() {
                window.open(url, '_blank');
            });
        } else {
            icon.css({
                'opacity': '0.3',
                'filter': 'grayscale(100%)',
                '-webkit-filter': 'grayscale(100%)',
                'cursor': 'default'
            });
         }
    });
});
 
// ==================================================
// ВИПРАВЛЕННЯ ПОШУКУ - БЕЗ OVERLAY
// ==================================================
$(document).ready(function() {
    var $searchInput = $('#searchInput');
    var $body = $('body');
   
    // Змінюємо placeholder (опціонально)
    $searchInput.attr('placeholder', 'Пошук...');
   
    // Прибираємо readonly
    $searchInput.prop('readonly', false);
    $searchInput.removeAttr('readonly');
   
    // Прибираємо класи тригера
    $searchInput.removeClass('skin-minerva-search-trigger');
   
    // Блокуємо overlay при фокусі
    $searchInput.on('focus click', function(e) {
        e.stopPropagation();
          
          
         // Блокуємо перехід на #/search
         // Прибираємо overlay класи з body
         $searchInput.on('click', function(e) {
         $body.removeClass('overlay-enabled search-enabled');
            e.stopPropagation();
            e.preventDefault();
            $(this).focus();
        });
          
          
         // При натисканні Enter - перехід на сторінку пошуку
         // Закриваємо overlay якщо відкрився
         $searchInput.on('keypress', function(e) {
         $('.overlay, .search-overlay').hide();
            if (e.which === 13) { // Enter
                e.preventDefault();
                var query = $(this).val();
                if (query) {
                    window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query);
                }
            }
        });
          
          
         // Блокуємо всі інші обробники на формі
         // Прибираємо hash з URL
         $searchForm.on('submit', function(e) {
        if (window.location.hash === '#/search') {
            history.replaceState(null, null, window.location.pathname);
        }
    });
   
    // При введенні тексту
    $searchInput.on('input', function() {
        $body.removeClass('overlay-enabled search-enabled');
         $('.overlay, .search-overlay').hide();
    });
   
    // При натисканні Enter
    $searchInput.on('keypress', function(e) {
        if (e.which === 13) {
             e.preventDefault();
             e.preventDefault();
             var query = $searchInput.val();
             var query = $(this).val();
             if (query) {
             if (query) {
                 window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query);
                 window.location.href = '/index.php?title=Спеціальна:Пошук&search=' + encodeURIComponent(query);
            }
        }
    });
   
    // Слідкуємо за змінами класів body
    var observer = new MutationObserver(function(mutations) {
        mutations.forEach(function(mutation) {
            if (mutation.attributeName === 'class') {
                if ($body.hasClass('overlay-enabled')) {
                    $body.removeClass('overlay-enabled');
                }
             }
             }
         });
         });
       
     });
     }, 100);
   
});
    observer.observe(document.body, { attributes: true });
 
   
$(document).ready(function() {
    // Блокуємо hashchange
    $('#searchInput').attr('placeholder', 'Пошук...');
    $(window).on('hashchange', function() {
        if (window.location.hash === '#/search') {
            history.replaceState(null, null, window.location.pathname);
            $body.removeClass('overlay-enabled');
            $('.overlay, .search-overlay').hide();
        }
    });
});
});