미디어위키:Gadget-Vector.js: 두 판 사이의 차이

식물 vs 좀비 위키
편집 요약 없음
태그: 수동 되돌리기 되돌려진 기여
편집 요약 없음
태그: 수동 되돌리기
 
(같은 사용자의 중간 판 14개는 보이지 않습니다)
255번째 줄: 255번째 줄:
'use strict';
'use strict';


function removeIds(root) {
function removeObsoleteInterface() {
var nodes;
var ids = [
'pvz-related-toggle',
'pvz-related-menu',
'pvz-right-panel',
'pvz-left-panel-toggle',
'pvz-right-panel-toggle'
];


if (!root) {
ids.forEach(function (id) {
var element = document.getElementById(id);
 
if (element) {
element.remove();
}
});
}
 
function restoreLogoToPanel(panel) {
var wrapper = document.getElementById('pvz-sidebar-logo');
var logo =
(wrapper && wrapper.querySelector('#p-logo')) ||
document.querySelector('#p-logo');
 
if (!panel || !logo) {
return;
return;
}
}


if (root.hasAttribute && root.hasAttribute('id')) {
if (logo.parentNode !== panel) {
root.removeAttribute('id');
panel.insertBefore(logo, panel.firstChild);
}
 
if (wrapper) {
wrapper.remove();
}
}
}
function syncPanelTop() {
var content = document.querySelector('.skin-vector-legacy #content');
var top;
if (!content) {
return;
}
top = content.getBoundingClientRect().top + window.scrollY;
document.documentElement.style.setProperty('--pvz-content-top', top + 'px');
}
function syncSearchLeft() {
var content = document.querySelector('.skin-vector-legacy #content');
var left;
if (!content) {
return;
}
left = content.getBoundingClientRect().left + window.scrollX;
document.documentElement.style.setProperty('--pvz-content-left', left + 'px');
}
function installV27Interface() {
var panel = document.querySelector('.skin-vector-legacy #mw-panel');
removeObsoleteInterface();
restoreLogoToPanel(panel);
syncPanelTop();
syncSearchLeft();
}
function initV27Interface() {
installV27Interface();
window.addEventListener('resize', function () {
syncPanelTop();
syncSearchLeft();
}, { passive: true });


nodes = root.querySelectorAll('[id], [aria-labelledby], [aria-controls]');
window.addEventListener('orientationchange', function () {
syncPanelTop();
syncSearchLeft();
}, { passive: true });
}


Array.prototype.forEach.call(nodes, function (node) {
if (document.readyState === 'loading') {
node.removeAttribute('id');
document.addEventListener('DOMContentLoaded', initV27Interface, { once: true });
node.removeAttribute('aria-labelledby');
} else {
node.removeAttribute('aria-controls');
initV27Interface();
}
}());
 
 
(function () {
'use strict';
 
function installGrassDividers(root) {
var scope = root || document;
var wrappers;
var legacyHeadings;
 
wrappers = scope.querySelectorAll(
'.skin-vector-legacy .mw-parser-output .mw-heading2'
);
 
Array.prototype.forEach.call(wrappers, function (wrapper) {
var divider;
 
wrapper.classList.add('pvz-grass-heading');
 
divider = wrapper.querySelector(
':scope > .pvz-grass-divider'
);
 
if (!divider) {
divider = document.createElement('span');
divider.className = 'pvz-grass-divider';
divider.setAttribute('aria-hidden', 'true');
wrapper.appendChild(divider);
}
});
 
legacyHeadings = scope.querySelectorAll(
'.skin-vector-legacy .mw-parser-output > h2'
);
 
Array.prototype.forEach.call(legacyHeadings, function (heading) {
var divider;
 
if (heading.closest('.mw-heading2')) {
return;
}
 
heading.classList.add('pvz-grass-heading');
 
divider = heading.querySelector(
':scope > .pvz-grass-divider'
);
 
if (!divider) {
divider = document.createElement('span');
divider.className = 'pvz-grass-divider';
divider.setAttribute('aria-hidden', 'true');
heading.appendChild(divider);
}
});
});
}
}


function moveLogoOutsidePanel(panel) {
function initGrassDividers() {
var logo = panel && panel.querySelector('#p-logo');
var observer;
var wrapper = document.getElementById('pvz-sidebar-logo');
 
installGrassDividers(document);
 
observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
Array.prototype.forEach.call(
mutation.addedNodes,
function (node) {
if (node.nodeType !== Node.ELEMENT_NODE) {
return;
}
 
if (
node.matches(
'.mw-heading2, .mw-parser-output > h2'
)
) {
installGrassDividers(node.parentNode);
return;
}
 
installGrassDividers(node);
}
);
});
});
 
observer.observe(document.body, {
childList: true,
subtree: true
});
}
 
if (document.readyState === 'loading') {
document.addEventListener(
'DOMContentLoaded',
initGrassDividers,
{ once: true }
);
} else {
initGrassDividers();
}
}());
 
 
(function () {
'use strict';
 
var ACTION_OFFSET = 230;
var SEARCH_WIDTH = 205;
var SEARCH_DOWN_OFFSET = 5;
var CONTENT_TOP = 24;
 
function getCactionsParts() {
var menu = document.getElementById('p-cactions');
 
if (!menu) {
return null;
}
 
return {
menu: menu,
label:
document.getElementById('p-cactions-label') ||
menu.querySelector('.vector-menu-heading'),
checkbox: menu.querySelector(
'input.vector-menu-checkbox, input[type="checkbox"]'
),
content: menu.querySelector('.vector-menu-content')
};
}
 
function isCactionsOpen(parts) {
if (!parts) {
return false;
}


if (!logo || !document.body) {
if (parts.checkbox && parts.checkbox.checked) {
return;
return true;
}
}


if (!wrapper) {
if (
wrapper = document.createElement('div');
parts.menu.classList.contains('vector-menu-dropdown-active') ||
wrapper.id = 'pvz-sidebar-logo';
parts.menu.classList.contains('pvz-cactions-open')
document.body.appendChild(wrapper);
) {
return true;
}
}


if (logo.parentNode !== wrapper) {
if (parts.label) {
wrapper.appendChild(logo);
return parts.label.getAttribute('aria-expanded') === 'true';
}
}
return false;
}
}


function buildRightPanel(panel) {
function closeCactions(parts) {
var rightPanel = document.getElementById('pvz-right-panel');
if (!parts) {
var portals;
 
if (!panel || !document.body) {
return;
return;
}
}


if (!rightPanel) {
if (parts.checkbox) {
rightPanel = document.createElement('aside');
parts.checkbox.checked = false;
rightPanel.id = 'pvz-right-panel';
parts.checkbox.dispatchEvent(
rightPanel.setAttribute('aria-label', '오른쪽 보조 메뉴');
new Event('change', { bubbles: true })
document.body.appendChild(rightPanel);
);
}
}


rightPanel.textContent = '';
parts.menu.classList.remove(
portals = panel.querySelectorAll('.vector-menu-portal, .portal');
'pvz-cactions-open',
'vector-menu-dropdown-active'
);
 
if (parts.label) {
parts.label.setAttribute('aria-expanded', 'false');
}


Array.prototype.forEach.call(portals, function (portal) {
if (parts.content) {
var clone = portal.cloneNode(true);
parts.content.setAttribute('aria-hidden', 'true');
removeIds(clone);
}
rightPanel.appendChild(clone);
});
}
}


function syncPanelTop() {
function handleCactionsClick(event) {
var content = document.querySelector('.skin-vector-legacy #content');
var parts = getCactionsParts();
var top;
var label;
 
if (!parts) {
return;
}
 
label = event.target.closest(
'#p-cactions-label, #p-cactions > .vector-menu-heading'
);


if (!content) {
if (label && isCactionsOpen(parts)) {
event.preventDefault();
event.stopImmediatePropagation();
closeCactions(parts);
return;
return;
}
}


top = content.getBoundingClientRect().top + window.scrollY;
if (
document.documentElement.style.setProperty('--pvz-content-top', top + 'px');
isCactionsOpen(parts) &&
!event.target.closest('#p-cactions')
) {
closeCactions(parts);
}
}
}


function installSidePanels() {
function syncV35Layout() {
var panel = document.querySelector('.skin-vector-legacy #mw-panel');
var content = document.querySelector('#content');
var leftNavigation = document.getElementById('left-navigation');
var rightNavigation = document.getElementById('right-navigation');
var search = document.getElementById('pvz-content-search');
var rightGap;
var navigationTop;


if (!panel) {
if (!content || !leftNavigation) {
return;
return;
}
}


moveLogoOutsidePanel(panel);
rightGap = Math.max(
buildRightPanel(panel);
0,
syncPanelTop();
window.innerWidth - content.getBoundingClientRect().right
);
 
navigationTop =
leftNavigation.getBoundingClientRect().top +
window.scrollY;
 
if (!Number.isFinite(navigationTop)) {
navigationTop = CONTENT_TOP;
}
 
document.documentElement.style.setProperty(
'--pvz-content-right-gap',
rightGap + 'px'
);
 
document.documentElement.style.setProperty(
'--pvz-navigation-top',
navigationTop + 'px'
);
 
if (rightNavigation) {
rightNavigation.style.setProperty(
'position',
'absolute',
'important'
);
rightNavigation.style.setProperty(
'top',
navigationTop + 'px',
'important'
);
rightNavigation.style.setProperty(
'right',
(rightGap + ACTION_OFFSET) + 'px',
'important'
);
rightNavigation.style.setProperty(
'left',
'auto',
'important'
);
rightNavigation.style.setProperty(
'display',
'flex',
'important'
);
rightNavigation.style.setProperty(
'align-items',
'flex-end',
'important'
);
rightNavigation.style.setProperty(
'justify-content',
'flex-end',
'important'
);
rightNavigation.style.setProperty(
'width',
'max-content',
'important'
);
rightNavigation.style.setProperty(
'margin',
'0',
'important'
);
rightNavigation.style.setProperty(
'transform',
'none',
'important'
);
}
 
if (search) {
search.style.setProperty(
'position',
'absolute',
'important'
);
search.style.setProperty(
'top',
(navigationTop + SEARCH_DOWN_OFFSET) + 'px',
'important'
);
search.style.setProperty(
'right',
rightGap + 'px',
'important'
);
search.style.setProperty(
'left',
'auto',
'important'
);
search.style.setProperty(
'width',
SEARCH_WIDTH + 'px',
'important'
);
search.style.setProperty(
'max-width',
SEARCH_WIDTH + 'px',
'important'
);
}
}
}


function initSidePanels() {
function initV35Layout() {
installSidePanels();
var observer;
window.addEventListener('resize', syncPanelTop, { passive: true });
 
window.addEventListener('orientationchange', syncPanelTop, { passive: true });
syncV35Layout();
 
document.addEventListener(
'click',
handleCactionsClick,
true
);
 
window.addEventListener(
'resize',
syncV35Layout,
{ passive: true }
);
 
window.addEventListener(
'orientationchange',
syncV35Layout,
{ passive: true }
);
 
observer = new MutationObserver(function () {
window.requestAnimationFrame(syncV35Layout);
});
 
observer.observe(document.body, {
childList: true,
subtree: true
});
}
}


if (document.readyState === 'loading') {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initSidePanels, { once: true });
document.addEventListener(
'DOMContentLoaded',
initV35Layout,
{ once: true }
);
} else {
} else {
initSidePanels();
initV35Layout();
}
}
}());
}());