MediaWiki:Common.js: различия между версиями
Pok (обсуждение | вклад) Нет описания правки Метки: с мобильного устройства из мобильной версии через расширенный мобильный режим |
Pok (обсуждение | вклад) Нет описания правки Метки: с мобильного устройства из мобильной версии через расширенный мобильный режим |
||
| Строка 1137: | Строка 1137: | ||
function buildWikitext(text, projectName) { | function buildWikitext(text, projectName) { | ||
return '{{#vardefine:JsonPath|' + projectName + '}}' + text; | return '{{#vardefine:JsonPath|' + projectName + '}}' + text; | ||
} | |||
function refreshForProject(projectName) { | |||
setCurrentJsonPath(projectName); | |||
var root = getContentRoot(); | |||
if (!root) return; | |||
var placeholder = createPlaceholderWithSpinner(); | |||
root.innerHTML = ''; | |||
root.appendChild(placeholder); | |||
getPageWikitext() | |||
.then(function (sourceText) { | |||
var wikitext = buildWikitext(sourceText, projectName); | |||
return parseAndInjectWikiText(wikitext, { | |||
placeholder: placeholder, | |||
targetRoot: root | |||
}); | |||
}) | |||
.fail(function () { | |||
placeholder.textContent = 'Ошибка загрузки страницы.'; | |||
}); | |||
} | } | ||
| Строка 1168: | Строка 1193: | ||
} | } | ||
form.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); | |||
}); | |||
} | |||
return form; | return form; | ||
} | } | ||
function | function getTargetContainers() { | ||
var targets = []; | |||
var portletList = document.querySelector('#mw-content .mw-portlet-body ul'); | var portletList = document.querySelector('#mw-content .mw-portlet-body ul'); | ||
if (portletList) { | if (portletList) { | ||
targets.push(portletList); | |||
} | } | ||
var associatedPages = document.querySelector('#p-associated-pages'); | |||
var | if (associatedPages) { | ||
if ( | targets.push(associatedPages); | ||
} else { | |||
var associatedPagesRoot = document.querySelector('#p-associated-pages'); | |||
if (associatedPagesRoot) { | |||
targets.push(associatedPagesRoot); | |||
} | |||
} | |||
return targets; | |||
} | } | ||
| Строка 1262: | Строка 1263: | ||
} | } | ||
var | var targets = getTargetContainers(); | ||
for (var t = 0; t < targets.length; t++) { | |||
targets[t].appendChild(createProjectMenu(projects, activeProject)); | |||
} | |||
if (preferredProject && preferredNorm !== 'corvax') { | if (preferredProject && preferredNorm !== 'corvax') { | ||