MediaWiki:Common.js: відмінності між версіями
Admin (обговорення | внесок) Немає опису редагування |
Admin (обговорення | внесок) Немає опису редагування |
||
| Рядок 75: | Рядок 75: | ||
}); | }); | ||
// Profile | // Profile icons - grayscale if no URL, clickable if has URL | ||
document.querySelectorAll('.profile-icon').forEach(function(icon) { | document.querySelectorAll('.profile-icon').forEach(function(icon) { | ||
var url = icon.getAttribute('data-url'); | var url = icon.getAttribute('data-url'); | ||
| Рядок 83: | Рядок 83: | ||
window.open(url, '_blank'); | window.open(url, '_blank'); | ||
}); | }); | ||
icon.addEventListener('mouseenter', function() { | |||
icon.style.background = '#444'; | |||
}); | |||
icon.addEventListener('mouseleave', function() { | |||
icon.style.background = '#333'; | |||
}); | |||
} else { | |||
icon.style.opacity = '0.3'; | |||
icon.style.filter = 'grayscale(100%)'; | |||
icon.style.cursor = 'default'; | |||
} | } | ||
}); | }); | ||
Версія за 01:19, 9 грудня 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 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;
}
}
$('html, body').animate({scrollTop: scrollTo}, 300);
});
$(window).on('scroll', function() {
var scrollPos = $(window).scrollTop() + 100;
var current = null;
for (var i = 0; i < sections.length; i++) {
var checkPos = sections[i].target ? sections[i].target.offset().top : 0;
if (checkPos <= scrollPos) {
current = sections[i].item;
}
}
items.removeClass('active');
if (current) {
current.addClass('active');
}
});
$(window).trigger('scroll');
});
// Profile icons - grayscale if no URL, clickable if has URL
document.querySelectorAll('.profile-icon').forEach(function(icon) {
var url = icon.getAttribute('data-url');
if (url && url.trim() !== '') {
icon.style.cursor = 'pointer';
icon.addEventListener('click', function() {
window.open(url, '_blank');
});
icon.addEventListener('mouseenter', function() {
icon.style.background = '#444';
});
icon.addEventListener('mouseleave', function() {
icon.style.background = '#333';
});
} else {
icon.style.opacity = '0.3';
icon.style.filter = 'grayscale(100%)';
icon.style.cursor = 'default';
}
});