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

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


function syncRightNavigation() {
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 initGrassDividers() {
var observer;
 
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 (parts.checkbox && parts.checkbox.checked) {
return true;
}
 
if (
parts.menu.classList.contains('vector-menu-dropdown-active') ||
parts.menu.classList.contains('pvz-cactions-open')
) {
return true;
}
 
if (parts.label) {
return parts.label.getAttribute('aria-expanded') === 'true';
}
 
return false;
}
 
function closeCactions(parts) {
if (!parts) {
return;
}
 
if (parts.checkbox) {
parts.checkbox.checked = false;
parts.checkbox.dispatchEvent(
new Event('change', { bubbles: true })
);
}
 
parts.menu.classList.remove(
'pvz-cactions-open',
'vector-menu-dropdown-active'
);
 
if (parts.label) {
parts.label.setAttribute('aria-expanded', 'false');
}
 
if (parts.content) {
parts.content.setAttribute('aria-hidden', 'true');
}
}
 
function handleCactionsClick(event) {
var parts = getCactionsParts();
var label;
 
if (!parts) {
return;
}
 
label = event.target.closest(
'#p-cactions-label, #p-cactions > .vector-menu-heading'
);
 
if (label && isCactionsOpen(parts)) {
event.preventDefault();
event.stopImmediatePropagation();
closeCactions(parts);
return;
}
 
if (
isCactionsOpen(parts) &&
!event.target.closest('#p-cactions')
) {
closeCactions(parts);
}
}
 
function syncV35Layout() {
var content = document.querySelector('#content');
var content = document.querySelector('#content');
var navigation = document.getElementById('right-navigation');
var leftNavigation = document.getElementById('left-navigation');
var views;
var rightNavigation = document.getElementById('right-navigation');
var actions;
var search = document.getElementById('pvz-content-search');
var rightGap;
var rightGap;
var navigationTop;


if (!content || !navigation) {
if (!content || !leftNavigation) {
return;
return;
}
}
365번째 줄: 568번째 줄:
window.innerWidth - content.getBoundingClientRect().right
window.innerWidth - content.getBoundingClientRect().right
);
);
navigationTop =
leftNavigation.getBoundingClientRect().top +
window.scrollY;
if (!Number.isFinite(navigationTop)) {
navigationTop = CONTENT_TOP;
}


document.documentElement.style.setProperty(
document.documentElement.style.setProperty(
371번째 줄: 582번째 줄:
);
);


navigation.style.setProperty('position', 'absolute', 'important');
document.documentElement.style.setProperty(
navigation.style.setProperty('top', '30px', 'important');
'--pvz-navigation-top',
navigation.style.setProperty('right', rightGap + 'px', 'important');
navigationTop + 'px'
navigation.style.setProperty('left', 'auto', 'important');
);
navigation.style.setProperty('display', 'flex', 'important');
navigation.style.setProperty('justify-content', 'flex-end', 'important');
navigation.style.setProperty('align-items', 'flex-end', 'important');
navigation.style.setProperty('width', 'max-content', 'important');
navigation.style.setProperty('float', 'none', 'important');
navigation.style.setProperty('margin', '0', 'important');
navigation.style.setProperty('transform', 'none', 'important');


views = navigation.querySelector('#p-views');
if (rightNavigation) {
actions = navigation.querySelector('#p-cactions');
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'
);
}


[views, actions].forEach(function (menu) {
if (search) {
if (!menu) {
search.style.setProperty(
return;
'position',
}
'absolute',
 
'important'
menu.style.setProperty('float', 'none', 'important');
);
menu.style.setProperty('right', 'auto', 'important');
search.style.setProperty(
menu.style.setProperty('left', 'auto', 'important');
'top',
menu.style.setProperty('margin-right', '0', 'important');
(navigationTop + SEARCH_DOWN_OFFSET) + 'px',
menu.style.setProperty('transform', 'none', 'important');
'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 initRightNavigationAlignment() {
function initV35Layout() {
var observer;
var observer;


syncRightNavigation();
syncV35Layout();
 
document.addEventListener(
'click',
handleCactionsClick,
true
);
 
window.addEventListener(
'resize',
syncV35Layout,
{ passive: true }
);


window.addEventListener('resize', syncRightNavigation, { passive: true });
window.addEventListener(
window.addEventListener(
'orientationchange',
'orientationchange',
syncRightNavigation,
syncV35Layout,
{ passive: true }
{ passive: true }
);
);


observer = new MutationObserver(function () {
observer = new MutationObserver(function () {
window.requestAnimationFrame(syncRightNavigation);
window.requestAnimationFrame(syncV35Layout);
});
});


424번째 줄: 710번째 줄:
document.addEventListener(
document.addEventListener(
'DOMContentLoaded',
'DOMContentLoaded',
initRightNavigationAlignment,
initV35Layout,
{ once: true }
{ once: true }
);
);
} else {
} else {
initRightNavigationAlignment();
initV35Layout();
}
}
}());
}());