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

식물 vs 좀비 위키
둘러보기로 이동 검색으로 이동
편집 요약 없음
태그: 수동 되돌리기 되돌려진 기여
Brokey (토론)의 436 판 편집을 되돌림
태그: 편집 취소
255번째 줄: 255번째 줄:
'use strict';
'use strict';


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


if (!root) {
ids.forEach(function (id) {
return;
var element = document.getElementById(id);
}
 
if (root.hasAttribute && root.hasAttribute('id')) {
root.removeAttribute('id');
}


nodes = root.querySelectorAll('[id], [aria-labelledby], [aria-controls]');
if (element) {
 
element.remove();
Array.prototype.forEach.call(nodes, function (node) {
}
node.removeAttribute('id');
node.removeAttribute('aria-labelledby');
node.removeAttribute('aria-controls');
});
});
}
}
294번째 줄: 286번째 줄:
}
}


function buildRightPanel(panel) {
function syncPanelTop() {
var rightPanel = document.getElementById('pvz-right-panel');
var content = document.querySelector('.skin-vector-legacy #content');
var portals;
var top;


if (!panel || !document.body) {
if (!content) {
return;
return;
}
}


if (!rightPanel) {
top = content.getBoundingClientRect().top + window.scrollY;
rightPanel = document.createElement('aside');
document.documentElement.style.setProperty('--pvz-content-top', top + 'px');
rightPanel.id = 'pvz-right-panel';
rightPanel.setAttribute('aria-label', '오른쪽 보조 메뉴');
document.body.appendChild(rightPanel);
}
 
rightPanel.textContent = '';
portals = panel.querySelectorAll('.vector-menu-portal, .portal');
 
Array.prototype.forEach.call(portals, function (portal) {
var clone = portal.cloneNode(true);
removeIds(clone);
rightPanel.appendChild(clone);
});
}
}


function syncPanelTop() {
function syncSearchLeft() {
var content = document.querySelector('.skin-vector-legacy #content');
var content = document.querySelector('.skin-vector-legacy #content');
var top;
var left;


if (!content) {
if (!content) {
327번째 줄: 306번째 줄:
}
}


top = content.getBoundingClientRect().top + window.scrollY;
left = content.getBoundingClientRect().left + window.scrollX;
document.documentElement.style.setProperty('--pvz-content-top', top + 'px');
document.documentElement.style.setProperty('--pvz-content-left', left + 'px');
}
}


function installSidePanels() {
function installV26Interface() {
var panel = document.querySelector('.skin-vector-legacy #mw-panel');
var panel = document.querySelector('.skin-vector-legacy #mw-panel');


if (!panel) {
removeRelatedInterface();
return;
 
if (panel) {
moveLogoOutsidePanel(panel);
}
}


moveLogoOutsidePanel(panel);
buildRightPanel(panel);
syncPanelTop();
syncPanelTop();
syncSearchLeft();
}
}


function initSidePanels() {
function initV26Interface() {
installSidePanels();
installV26Interface();
window.addEventListener('resize', syncPanelTop, { passive: true });
 
window.addEventListener('orientationchange', syncPanelTop, { passive: true });
window.addEventListener('resize', function () {
syncPanelTop();
syncSearchLeft();
}, { passive: true });
 
window.addEventListener('orientationchange', function () {
syncPanelTop();
syncSearchLeft();
}, { passive: true });
}
}


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

2026년 7월 29일 (수) 23:50 판

(function () {
	'use strict';

	var SPIN_CLASS = 'pvz-watch-spinning';
	var WATCHED_CLASS = 'pvz-watch-watched';
	var NOT_WATCHED_CLASS = 'pvz-watch-not-watched';
	var SPIN_TIME = 360;
	var cleanupTimer = 0;

	function getContainer() {
		return document.querySelector(
			'#ca-watch, #ca-unwatch, li.mw-watchlink, a.mw-watchlink'
		);
	}

	function getLink(container) {
		if (!container) {
			return null;
		}

		return container.matches('a') ? container : container.querySelector('a');
	}

	function applyState(isWatched) {
		var container = getContainer();

		if (!container) {
			return;
		}

		container.classList.toggle(WATCHED_CLASS, !!isWatched);
		container.classList.toggle(NOT_WATCHED_CLASS, !isWatched);
	}

	function syncFromMarkup() {
		var container = getContainer();
		var link = getLink(container);
		var href;

		if (!container || !link) {
			return;
		}

		href = link.getAttribute('href') || '';

		applyState(
			container.id === 'ca-unwatch' ||
			href.indexOf('action=unwatch') !== -1
		);
	}

	function spin() {
		var container = getContainer();

		if (!container) {
			return;
		}

		window.clearTimeout(cleanupTimer);
		container.classList.remove(SPIN_CLASS);
		void container.offsetWidth;
		container.classList.add(SPIN_CLASS);

		cleanupTimer = window.setTimeout(function () {
			container.classList.remove(SPIN_CLASS);
		}, SPIN_TIME + 40);
	}

	function handleClick(event) {
		var link = event.target.closest(
			'#ca-watch > a, #ca-unwatch > a, li.mw-watchlink > a, a.mw-watchlink'
		);

		if (link) {
			spin();
		}
	}

	function shortenHistoryLabel() {
		var historyLink = document.querySelector('#ca-history > a');

		if (!historyLink) {
			return;
		}

		Array.prototype.forEach.call(historyLink.childNodes, function (node) {
			if (node.nodeType === Node.TEXT_NODE) {
				node.nodeValue = node.nodeValue.replace(/역사 보기/g, '역사');
			}
		});

		if (historyLink.textContent.trim() === '역사 보기') {
			historyLink.textContent = '역사';
		}

		historyLink.setAttribute('title', '역사');
	}

	function init() {
		var observer;

		shortenHistoryLabel();
		syncFromMarkup();
		document.addEventListener('click', handleClick, true);

		observer = new MutationObserver(function () {
			shortenHistoryLabel();
			syncFromMarkup();
		});

		observer.observe(document.body, {
			subtree: true,
			childList: true,
			attributes: true,
			attributeFilter: ['id', 'href']
		});

		if (window.mw && mw.hook) {
			mw.hook('wikipage.watchlistChange').add(function (isWatched) {
				applyState(isWatched);
				spin();
			});
		}
	}

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


(function () {
	'use strict';

	function installSearchButtonIcon(wrapper) {
		var simpleSearch;
		var searchButton;
		var icon;

		if (!wrapper) {
			return;
		}

		simpleSearch = wrapper.querySelector('#simpleSearch');

		if (!simpleSearch) {
			return;
		}

		searchButton =
			simpleSearch.querySelector('#searchButton') ||
			simpleSearch.querySelector('.searchButton:not(#mw-searchButton)');

		if (!searchButton) {
			return;
		}

		searchButton.classList.add('pvz-primary-search-button');

		icon = simpleSearch.querySelector('.pvz-search-button-icon');

		if (!icon) {
			icon = document.createElement('span');
			icon.className = 'pvz-search-button-icon';
			icon.setAttribute('aria-hidden', 'true');
			simpleSearch.appendChild(icon);
		}
	}

	function installTopSearch() {
		var content = document.querySelector('.skin-vector-legacy #content');
		var form = document.querySelector('#searchform');
		var wrapper;

		if (!content || !form || !document.body) {
			return;
		}

		wrapper = document.getElementById('pvz-content-search');

		if (!wrapper) {
			wrapper = document.createElement('div');
			wrapper.id = 'pvz-content-search';
			wrapper.setAttribute('role', 'search');
			wrapper.setAttribute('aria-label', '사이트 검색');
		}

		if (wrapper.parentNode !== document.body) {
			document.body.insertBefore(wrapper, content);
		}

		if (form.parentNode !== wrapper) {
			wrapper.appendChild(form);
		}

		installSearchButtonIcon(wrapper);
		document.documentElement.classList.add('pvz-content-search-ready');
	}

	function initTopSearch() {
		var observer;

		installTopSearch();

		observer = new MutationObserver(function () {
			installTopSearch();
		});

		observer.observe(document.body, {
			childList: true,
			subtree: true
		});
	}

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


(function () {
	'use strict';

	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 initSearchAlignment() {
		syncSearchLeft();
		window.addEventListener('resize', syncSearchLeft, { passive: true });
		window.addEventListener('orientationchange', syncSearchLeft, { passive: true });
	}

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


(function () {
	'use strict';

	function removeRelatedInterface() {
		var ids = ['pvz-related-toggle', 'pvz-related-menu'];

		ids.forEach(function (id) {
			var element = document.getElementById(id);

			if (element) {
				element.remove();
			}
		});
	}

	function moveLogoOutsidePanel(panel) {
		var logo = panel && panel.querySelector('#p-logo');
		var wrapper = document.getElementById('pvz-sidebar-logo');

		if (!logo || !document.body) {
			return;
		}

		if (!wrapper) {
			wrapper = document.createElement('div');
			wrapper.id = 'pvz-sidebar-logo';
			document.body.appendChild(wrapper);
		}

		if (logo.parentNode !== wrapper) {
			wrapper.appendChild(logo);
		}
	}

	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 installV26Interface() {
		var panel = document.querySelector('.skin-vector-legacy #mw-panel');

		removeRelatedInterface();

		if (panel) {
			moveLogoOutsidePanel(panel);
		}

		syncPanelTop();
		syncSearchLeft();
	}

	function initV26Interface() {
		installV26Interface();

		window.addEventListener('resize', function () {
			syncPanelTop();
			syncSearchLeft();
		}, { passive: true });

		window.addEventListener('orientationchange', function () {
			syncPanelTop();
			syncSearchLeft();
		}, { passive: true });
	}

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