MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Нет описания правки |
Pok (обсуждение | вклад) Нет описания правки |
||
| (не показано 11 промежуточных версий этого же участника) | |||
| Строка 664: | Строка 664: | ||
mw.hook('wikipage.content').fire(root); | mw.hook('wikipage.content').fire(root); | ||
initAjaxLoader(root); | initAjaxLoader(root); | ||
} | } | ||
| Строка 708: | Строка 707: | ||
} | } | ||
}); | }); | ||
} | |||
function createPlaceholderWithSpinner(text) { | |||
if (!text) { | |||
loadingImgHTML = '<img alt="Файл:Silva-loading.gif" src="/images/4/45/Silva-loading.gif" decoding="async" width="16" height="16" style="vertical-align:middle;margin-right:6px">'; | |||
text = loadingImgHTML + '<span class="ajax-load-text">Пожалуйста, подождите, содержимое загружается...</span>'; | |||
} | |||
var placeholder = document.createElement("span"); | |||
placeholder.className = "ajax-load-placeholder"; | |||
placeholder.innerHTML = text; | |||
return placeholder; | |||
} | } | ||
| Строка 718: | Строка 730: | ||
var queue = []; | var queue = []; | ||
var processing = false; | var processing = false; | ||
function processQueue() { | function processQueue() { | ||
| Строка 744: | Строка 754: | ||
nextBatch(); | nextBatch(); | ||
} | } | ||
| Строка 762: | Строка 765: | ||
if (!wikiText) return; | if (!wikiText) return; | ||
var | var loadingHTML = loadingEl ? (loadingEl.innerHTML || "").trim() : ""; | ||
if (loadingEl && loadingEl.parentNode) { | if (loadingEl && loadingEl.parentNode) { | ||
loadingEl.parentNode.removeChild(loadingEl); | loadingEl.parentNode.removeChild(loadingEl); | ||
} | } | ||
| Строка 776: | Строка 778: | ||
container.dataset.ajaxLoaded = "1"; | container.dataset.ajaxLoaded = "1"; | ||
var placeholder = createPlaceholderWithSpinner( | var placeholder = createPlaceholderWithSpinner(loadingHTML); | ||
if (container && container.parentNode) { | if (container && container.parentNode) { | ||
| Строка 788: | Строка 790: | ||
}, { once: true }); | }, { once: true }); | ||
} else { | } else { | ||
var placeholder = createPlaceholderWithSpinner( | var placeholder = createPlaceholderWithSpinner(loadingHTML); | ||
if (contentEl && contentEl.parentNode) { | if (contentEl && contentEl.parentNode) { | ||
| Строка 1019: | Строка 1021: | ||
} | } | ||
} | } | ||
// Для "Шаблон: | // Для "Шаблон:Переключатель_проекта" | ||
function initProjectSelectionGenerator() { | function initProjectSelectionGenerator() { | ||
var containers = document.getElementsByClassName('js-project-selection-generator'); | var containers = document.getElementsByClassName('js-project-selection-generator'); | ||
| Строка 1066: | Строка 1068: | ||
function stripProjectSelectionTemplate(text) { | function stripProjectSelectionTemplate(text) { | ||
return String(text || '').replace(/\{\{\s* | return String(text || '').replace(/\{\{\s*переключатель проекта\b[\s\S]*?\}\}/ig, ''); | ||
} | } | ||
function buildWikitext(text, projectName) { | function buildWikitext(text, projectName) { | ||
return '{{#vardefine: | return '{{#vardefine:JsonPath|' + projectName + '}}\n' + stripProjectSelectionTemplate(text); | ||
} | } | ||
function refreshForProject(projectName | function refreshForProject(projectName) { | ||
var root = getContentRoot(); | var root = getContentRoot(); | ||
if (!root) return; | if (!root) return; | ||
var placeholder = createPlaceholderWithSpinner(); | |||
var placeholder = | |||
root.innerHTML = ''; | root.innerHTML = ''; | ||
root.appendChild(placeholder); | root.appendChild(placeholder); | ||
getPageWikitext() | getPageWikitext() | ||
.then(function (sourceText) { | .then(function (sourceText) { | ||
var wikitext = buildWikitext(sourceText, projectName); | var wikitext = buildWikitext(sourceText, projectName); | ||
return parseAndInjectWikiText(wikitext, { | return parseAndInjectWikiText(wikitext, { | ||
placeholder: placeholder, | placeholder: placeholder, | ||
targetRoot: root | targetRoot: root | ||
}); | }); | ||
}) | }) | ||
.fail(function () { | .fail(function () { | ||
placeholder.textContent = | placeholder.textContent = 'Ошибка загрузки страницы.'; | ||
}); | }); | ||
} | } | ||
| Строка 1152: | Строка 1144: | ||
} | } | ||
var portletList = document.querySelector('#mw-content .mw-portlet-body ul'); | |||
if (portletList) { | |||
portletList.appendChild(form); | |||
} | |||
(function (menuNode) { | (function (menuNode) { | ||
var | menuNode.addEventListener('change', function (event) { | ||
var target = event.target; | |||
if (!target || target.tagName !== 'INPUT') return; | |||
if (target.type !== 'radio') return; | |||
if (target.name !== 'js-project-selection') return; | |||
if (!target.checked) return; | |||
})( | refreshForProject(target.value); | ||
}); | |||
})(form); | |||
} | } | ||
} | } | ||