MediaWiki:Common.js: различия между версиями

Нет описания правки
Нет описания правки
Строка 634: Строка 634:
var processing = false;
var processing = false;


// HTML для спиннера (анимация загрузки)
var loadingImgHTML = '<img alt="Файл:Silva-loading.gif" src="/images/4/45/Silva-loading.gif?20260316201152" decoding="async" width="16" height="16" data-file-width="16" data-file-height="16" style="vertical-align:middle;margin-right:6px">';
var loadingImgHTML = '<img alt="Файл:Silva-loading.gif" src="/images/4/45/Silva-loading.gif?20260316201152" decoding="async" width="16" height="16" data-file-width="16" data-file-height="16" style="vertical-align:middle;margin-right:6px">';


Строка 725: Строка 724:
var loadingText = (loadingEl && (loadingEl.textContent || loadingEl.innerText || "").trim()) || "Загрузка...";
var loadingText = (loadingEl && (loadingEl.textContent || loadingEl.innerText || "").trim()) || "Загрузка...";


// Если есть элемент .ajax-load-loading — можно удалить (как в оригинале),
// но плейсхолдер мы всё равно создаём с картинкой + текстом.
if (loadingEl && loadingEl.parentNode) {
if (loadingEl && loadingEl.parentNode) {
loadingEl.parentNode.removeChild(loadingEl);
loadingEl.parentNode.removeChild(loadingEl);
Строка 735: Строка 732:
var placeholder = document.createElement("span");
var placeholder = document.createElement("span");
placeholder.className = "ajax-load-placeholder";
placeholder.className = "ajax-load-placeholder";
// Добавляем картинку в начало и текст после неё
placeholder.innerHTML = loadingImgHTML + '<span class="ajax-load-text">' + (text || '') + '</span>';
placeholder.innerHTML = loadingImgHTML + '<span class="ajax-load-text">' + (text || '') + '</span>';
return placeholder;
return placeholder;
Строка 931: Строка 927:
function registerCheckboxExpander(checkboxId, options) {
function registerCheckboxExpander(checkboxId, options) {
options = options || {};
options = options || {};
// если нужно — использовать только expand (по умолчанию false = делаем и collapse)
var onlyExpand = !!options.onlyExpand;
var onlyExpand = !!options.onlyExpand;


var checkbox = document.getElementById(checkboxId);
var checkbox = document.getElementById(checkboxId);
if (!checkbox) {
if (!checkbox) {
// Если чекбокс ещё не на странице — попробуем навесить через делегирование (MutationObserver опционально)
console.warn('registerCheckboxExpander: checkbox not found by id:', checkboxId);
console.warn('registerCheckboxExpander: checkbox not found by id:', checkboxId);
return;
return;
Строка 992: Строка 986:
if (checkbox.checked) {
if (checkbox.checked) {
try { expandAll(); } catch (err) { console.error(err); }
try { expandAll(); } catch (err) { console.error(err); }
}
}
//
// Для "Шаблон:ProjectSelectionGenerator"
function initProjectSelectionGenerator() {
var containers = document.getElementsByClassName('js-project-selection-generator');
function normalizeIdPart(s) {
return String(s === undefined || s === null ? '' : s)
.trim()
.replace(/\s+/g, '-')
.replace(/[^A-Za-z0-9_\-\u0400-\u04FF]/g, '');
}
for (var ci = 0; ci < containers.length; ci++) {
var container = containers[ci];
if (container.getAttribute('data-project-selection-initialized') === '1') {
continue;
}
var rawText = container.textContent || '';
var items = rawText.split(',');
var projects = [];
for (var i = 0; i < items.length; i++) {
var item = items[i].trim();
if (item) {
projects.push(item);
}
}
// Если значение одно — ничего не создаём
if (projects.length <= 1) {
container.setAttribute('data-project-selection-initialized', '1');
continue;
}
var form = document.createElement('form');
for (var j = 0; j < projects.length; j++) {
var projectName = projects[j];
var projectId = 'project-' + normalizeIdPart(projectName);
var div = document.createElement('div');
var input = document.createElement('input');
input.type = 'radio';
input.name = 'project-selection';
input.value = projectName;
input.id = projectId;
// Первый вариант отмечаем по умолчанию
if (j === 0) {
input.checked = true;
}
var label = document.createElement('label');
label.htmlFor = projectId;
label.textContent = projectName;
div.appendChild(input);
div.appendChild(label);
form.appendChild(div);
}
container.textContent = '';
container.appendChild(form);
container.setAttribute('data-project-selection-initialized', '1');
}
}
}
}
Строка 1093: Строка 1156:
if (checkboxExist.length > 0) {
if (checkboxExist.length > 0) {
initCheckboxCreator();
initCheckboxCreator();
}
var projectSelectionExist = document.querySelectorAll('.js-project-selection-generator');
if (projectSelectionExist.length > 0) {
initProjectSelectionGenerator();
}
}
registerCheckboxExpander('js-checkbox-mw-collapsible');
registerCheckboxExpander('js-checkbox-mw-collapsible');