Dantes (обсуждение | вклад) (Отмена правки 17597, сделанной Dantes (обсуждение)) Метка: отмена |
Dantes (обсуждение | вклад) Нет описания правки |
||
| Строка 124: | Строка 124: | ||
/* Sidebar для ролей */ | /* Sidebar для ролей */ | ||
var | var jobsTable = document.getElementById('IdJobsTableContainer2'); | ||
if ( | if (jobsTable) { | ||
var | var originalOffset = jobsTable.getBoundingClientRect().top + window.pageYOffset; | ||
if ( | var originalLeft = jobsTable.offsetLeft; | ||
var originalWidth = jobsTable.offsetWidth; | |||
var placeholder = document.createElement('div'); | |||
var isFixed = false; | |||
function updateSidebar() { | |||
var scrollTop = window.pageYOffset || document.documentElement.scrollTop; | |||
var containerBottom = jobsTable.offsetHeight + scrollTop; | |||
var documentHeight = document.documentElement.scrollHeight; | |||
if (scrollTop > originalOffset && !isFixed) { | |||
jobsTable.style.position = 'fixed'; | |||
jobsTable.style.top = '20px'; | |||
jobsTable.style.left = originalLeft + 'px'; | |||
jobsTable.style.width = originalWidth + 'px'; | |||
placeholder.style.height = jobsTable.offsetHeight + 'px'; | |||
jobsTable.parentNode.insertBefore(placeholder, jobsTable); | |||
isFixed = true; | |||
} else if (scrollTop <= originalOffset && isFixed) { | |||
jobsTable.style.position = ''; | |||
jobsTable.style.top = ''; | |||
jobsTable.style.left = ''; | |||
jobsTable.style.width = ''; | |||
placeholder.parentNode.removeChild(placeholder); | |||
isFixed = false; | |||
} | |||
if (isFixed) { | |||
var maxTop = documentHeight - jobsTable.offsetHeight - 20; | |||
if (containerBottom > maxTop) { | |||
jobsTable.style.top = (maxTop - scrollTop) + 'px'; | |||
} else { | |||
jobsTable.style.top = '20px'; | |||
} | |||
} | |||
} | |||
function onResize() { | |||
originalLeft = jobsTable.offsetLeft; | |||
originalWidth = jobsTable.offsetWidth; | |||
if (isFixed) { | |||
jobsTable.style.left = originalLeft + 'px'; | |||
jobsTable.style.width = originalWidth + 'px'; | |||
} | |||
} | |||
window.addEventListener('scroll', function() { | |||
requestAnimationFrame(updateSidebar); | |||
}); | |||
window.addEventListener('resize', function() { | |||
requestAnimationFrame(onResize); | |||
}); | |||
} | } | ||
Версия от 19:09, 28 марта 2025
/* Подгрузка внешних css js */
mw.loader.using('mediawiki.util', function() {
var params = mw.util.getParamValue('use'),
basePath = mw.config.get('wgServer').replace(/^http:/, 'https:')
+ mw.config.get('wgScript')
+ '?action=raw&ctype=text/',
userPrefix = 'User:' + (mw.config.get('wgUserName') || '') + '/',
validExtensions = {js:1, css:1};
if (!params) return;
params.split('|').forEach(function(param) {
var file = param.trim(),
isSystem = /^MediaWiki:/i.test(file),
parts = file.split('.'),
ext = parts[parts.length-1].toLowerCase();
if (!validExtensions[ext]) return;
if (!/^[\w\-\/\.]+$/.test(file)) return;
var prefix = isSystem ? 'MediaWiki:' : userPrefix;
var fullName = file.indexOf(':') > -1 ? file : prefix + file;
var url = basePath
+ (ext === 'js' ? 'javascript' : 'css')
+ '&title=' + encodeURIComponent(fullName);
mw.loader.load(url, 'text/' + ext);
});
});
/* Лого сайта */
(function() {
var createLogo = function(url, imgSrc, title) {
var container = document.createElement('div'),
link = document.createElement('a'),
img = document.createElement('img');
link.className = 'mw-logo citizen-header__button';
link.href = mw.util.getUrl(url);
link.title = title;
img.className = 'mw-logo-icon';
img.src = imgSrc;
img.alt = '';
img.setAttribute('aria-hidden', 'true');
img.width = 32;
img.height = 32;
link.appendChild(img);
container.appendChild(link);
return container;
};
var logoContainer = document.querySelector('.citizen-header__logo');
if (logoContainer) {
// Очистка существующего содержимого
while (logoContainer.firstChild) {
logoContainer.removeChild(logoContainer.firstChild);
}
var logo1 = createLogo(
'Заглавная_страница',
mw.config.get('wgScriptPath') + '/resources/assets/logo.png',
'Перейти на заглавную страницу'
);
logo1.className = 'logo1';
var logo2 = createLogo(
'Colonial_Marines',
mw.config.get('wgScriptPath') + '/images/0/0d/CMlog.png',
'Перейти на CM'
);
logo2.className = 'logo2';
// Добавление в DOM
logoContainer.appendChild(logo1);
logoContainer.appendChild(logo2);
}
})();
/* Перенос page-info в footer-places */
var footerPlaces = document.getElementById('footer-places');
var pageInfo = document.querySelector('.page-info');
if (footerPlaces && pageInfo) {
footerPlaces.insertAdjacentElement('afterend', pageInfo.cloneNode(true));
pageInfo.parentNode.removeChild(pageInfo);
}
/* Логика цвета через headerColor */
var headerColorElement = document.querySelector('.headerColor');
if (headerColorElement) {
var isValidColor = function(color) {
var s = new Option().style;
s.color = color;
return s.color !== '';
};
var content = headerColorElement.textContent.split('|');
if (content.length === 2 && isValidColor(content[0]) && isValidColor(content[1])) {
var applyStyles = function() {
var headers = document.querySelectorAll('.citizen-section-heading, .citizen-section-heading--collapsed');
for (var i = 0; i < headers.length; i++) {
var header = headers[i],
indicator = header.querySelector('.citizen-section-indicator'),
headline = header.querySelector('.mw-headline');
if (header.classList.contains('citizen-section-heading--collapsed')) {
if (indicator) {
indicator.style.cssText = 'background: black; box-shadow: unset;';
}
} else if (indicator && headline) {
indicator.style.cssText = 'background: ' + content[1] + '; box-shadow: 0 0 20px 0px ' + content[1] + 'cc;';
headline.style.cssText = 'border-image: linear-gradient(to right top, ' + content[0] + ', black); border-image-slice: 1;';
}
}
};
applyStyles();
document.body.addEventListener('click', applyStyles, false);
}
}
/* Sidebar для ролей */
var jobsTable = document.getElementById('IdJobsTableContainer2');
if (jobsTable) {
var originalOffset = jobsTable.getBoundingClientRect().top + window.pageYOffset;
var originalLeft = jobsTable.offsetLeft;
var originalWidth = jobsTable.offsetWidth;
var placeholder = document.createElement('div');
var isFixed = false;
function updateSidebar() {
var scrollTop = window.pageYOffset || document.documentElement.scrollTop;
var containerBottom = jobsTable.offsetHeight + scrollTop;
var documentHeight = document.documentElement.scrollHeight;
if (scrollTop > originalOffset && !isFixed) {
jobsTable.style.position = 'fixed';
jobsTable.style.top = '20px';
jobsTable.style.left = originalLeft + 'px';
jobsTable.style.width = originalWidth + 'px';
placeholder.style.height = jobsTable.offsetHeight + 'px';
jobsTable.parentNode.insertBefore(placeholder, jobsTable);
isFixed = true;
} else if (scrollTop <= originalOffset && isFixed) {
jobsTable.style.position = '';
jobsTable.style.top = '';
jobsTable.style.left = '';
jobsTable.style.width = '';
placeholder.parentNode.removeChild(placeholder);
isFixed = false;
}
if (isFixed) {
var maxTop = documentHeight - jobsTable.offsetHeight - 20;
if (containerBottom > maxTop) {
jobsTable.style.top = (maxTop - scrollTop) + 'px';
} else {
jobsTable.style.top = '20px';
}
}
}
function onResize() {
originalLeft = jobsTable.offsetLeft;
originalWidth = jobsTable.offsetWidth;
if (isFixed) {
jobsTable.style.left = originalLeft + 'px';
jobsTable.style.width = originalWidth + 'px';
}
}
window.addEventListener('scroll', function() {
requestAnimationFrame(updateSidebar);
});
window.addEventListener('resize', function() {
requestAnimationFrame(onResize);
});
}
/* Хронология */
if (window.jQuery) {
jQuery(function($) {
$('.timeline-header').on('click', function() {
$(this).next('.timeline-content').slideToggle();
}).trigger('click');
});
}