(새 문서: (function () { 'use strict'; var ROOT_SELECTOR = '.clbi-nations-panel-stack, .clbi-nations-globe-window, .nation-link-editor, .doc-panel, .doc-tab-bar'; function keyOf(event) { return String(event && event.key || '').toLowerCase(); } function hasCtrlOrMeta(event) { return !!(event && (event.ctrlKey || event.metaKey)); } function isEditableTarget(target) { var tag; if (!target) return false; if (target.isCon...) |
편집 요약 없음 |
||
| 130번째 줄: | 130번째 줄: | ||
showMatchingPanels(panels, 'data-continent-panel', continent, 'is-active'); | showMatchingPanels(panels, 'data-continent-panel', continent, 'is-active'); | ||
return true; | return true; | ||
} | |||
function isVisibleElement(element) { | |||
var rect; | |||
var style; | |||
if (!element || !element.getClientRects || !element.getClientRects().length) return false; | |||
style = window.getComputedStyle ? window.getComputedStyle(element) : null; | |||
if (style && (style.display === 'none' || style.visibility === 'hidden')) return false; | |||
rect = element.getBoundingClientRect(); | |||
return rect.width > 0 && rect.height > 0; | |||
} | |||
function switchNationEra(direction) { | |||
var selector = direction < 0 ? '.clbi-nations-era-side-button-left' : '.clbi-nations-era-side-button-right'; | |||
var buttons = Array.from(document.querySelectorAll(selector)); | |||
var visibleButton; | |||
if (!buttons.length) return false; | |||
visibleButton = buttons.find(function (button) { | |||
return isVisibleElement(button); | |||
}); | |||
if (!visibleButton) visibleButton = buttons[0]; | |||
return clickElement(visibleButton); | |||
} | } | ||
| 185번째 줄: | 213번째 줄: | ||
} else if (hasCtrlOrMeta(event) && !event.shiftKey && !event.altKey) { | } else if (hasCtrlOrMeta(event) && !event.shiftKey && !event.altKey) { | ||
handled = switchNationContinent(direction); | handled = switchNationContinent(direction); | ||
} else if (!event.shiftKey && !event.ctrlKey && !event.metaKey && !event.altKey) { | |||
handled = switchNationEra(direction); | |||
} | } | ||
| 217번째 줄: | 247번째 줄: | ||
window.Shortcuts = window.Shortcuts || {}; | window.Shortcuts = window.Shortcuts || {}; | ||
window.Shortcuts.version = '20260704- | window.Shortcuts.version = '20260704-4'; | ||
window.Shortcuts.scope = ROOT_SELECTOR; | window.Shortcuts.scope = ROOT_SELECTOR; | ||
}()); | }()); | ||
2026년 7월 4일 (토) 22:10 판
(function () {
'use strict';
var ROOT_SELECTOR = '.clbi-nations-panel-stack, .clbi-nations-globe-window, .nation-link-editor, .doc-panel, .doc-tab-bar';
function keyOf(event) {
return String(event && event.key || '').toLowerCase();
}
function hasCtrlOrMeta(event) {
return !!(event && (event.ctrlKey || event.metaKey));
}
function isEditableTarget(target) {
var tag;
if (!target) return false;
if (target.isContentEditable) return true;
if (target.closest && target.closest('[contenteditable="true"]')) return true;
tag = String(target.tagName || '').toUpperCase();
return tag === 'INPUT' || tag === 'TEXTAREA' || tag === 'SELECT';
}
function clickElement(element) {
if (!element || element.disabled) return false;
element.click();
return true;
}
function prevent(event) {
event.preventDefault();
event.stopPropagation();
if (event.stopImmediatePropagation) event.stopImmediatePropagation();
}
function findNationLinkEditorSave(target) {
var root = target && target.closest ? target.closest('.nation-link-editor') : null;
if (!root) root = document.querySelector('.nation-link-editor');
if (!root) return null;
return root.querySelector('.nation-link-save');
}
function findWikiEditSave() {
return document.querySelector('#wpSave, input[name="wpSave"], button[name="wpSave"]');
}
function handleSaveShortcut(event) {
var saveButton;
if (!hasCtrlOrMeta(event) || event.shiftKey || event.altKey || keyOf(event) !== 's') return false;
saveButton = findNationLinkEditorSave(event.target) || findWikiEditSave();
if (!saveButton) return false;
prevent(event);
clickElement(saveButton);
return true;
}
function setActiveButton(buttons, activeButton, activeClass) {
buttons.forEach(function (button) {
var isActive = button === activeButton;
button.classList.toggle(activeClass || 'is-active', isActive);
button.setAttribute('aria-selected', isActive ? 'true' : 'false');
button.setAttribute('tabindex', isActive ? '0' : '-1');
});
}
function showMatchingPanels(panels, attrName, value, activeClass) {
panels.forEach(function (panel) {
var isActive = panel.getAttribute(attrName) === value;
panel.classList.toggle(activeClass || 'is-active', isActive);
if (isActive) {
panel.removeAttribute('hidden');
} else {
panel.setAttribute('hidden', 'hidden');
}
});
}
function switchNationHistoryYear(direction) {
var buttons = Array.from(document.querySelectorAll('.clbi-nations-history-year-button[data-year]'));
var panels = Array.from(document.querySelectorAll('.clbi-nations-history-page[data-year-panel]'));
var activeIndex;
var nextIndex;
var nextButton;
var year;
if (!buttons.length || !panels.length) return false;
activeIndex = buttons.findIndex(function (button) {
return button.classList.contains('is-active') || button.getAttribute('aria-selected') === 'true';
});
if (activeIndex < 0) activeIndex = 0;
nextIndex = (activeIndex + direction + buttons.length) % buttons.length;
nextButton = buttons[nextIndex];
year = nextButton.getAttribute('data-year');
setActiveButton(buttons, nextButton, 'is-active');
showMatchingPanels(panels, 'data-year-panel', year, 'is-active');
return true;
}
function switchNationContinent(direction) {
var tabs = Array.from(document.querySelectorAll('.clbi-nations-tabpanel-tab[data-continent]'));
var panels = Array.from(document.querySelectorAll('.clbi-nations-tabpanel-continent[data-continent-panel]'));
var activeIndex;
var nextIndex;
var nextTab;
var continent;
if (!tabs.length || !panels.length) return false;
activeIndex = tabs.findIndex(function (tab) {
return tab.classList.contains('is-active') || tab.getAttribute('aria-selected') === 'true';
});
if (activeIndex < 0) activeIndex = 0;
nextIndex = (activeIndex + direction + tabs.length) % tabs.length;
nextTab = tabs[nextIndex];
continent = nextTab.getAttribute('data-continent');
setActiveButton(tabs, nextTab, 'is-active');
showMatchingPanels(panels, 'data-continent-panel', continent, 'is-active');
return true;
}
function isVisibleElement(element) {
var rect;
var style;
if (!element || !element.getClientRects || !element.getClientRects().length) return false;
style = window.getComputedStyle ? window.getComputedStyle(element) : null;
if (style && (style.display === 'none' || style.visibility === 'hidden')) return false;
rect = element.getBoundingClientRect();
return rect.width > 0 && rect.height > 0;
}
function switchNationEra(direction) {
var selector = direction < 0 ? '.clbi-nations-era-side-button-left' : '.clbi-nations-era-side-button-right';
var buttons = Array.from(document.querySelectorAll(selector));
var visibleButton;
if (!buttons.length) return false;
visibleButton = buttons.find(function (button) {
return isVisibleElement(button);
});
if (!visibleButton) visibleButton = buttons[0];
return clickElement(visibleButton);
}
function switchDocTab(direction) {
var bar = document.querySelector('.doc-tab-bar');
var tabs;
var panel;
var display;
var activeIndex;
var nextIndex;
var nextTab;
var ref;
var source;
if (!bar) return false;
tabs = Array.from(bar.querySelectorAll('.doc-tab'));
if (!tabs.length) return false;
panel = bar.closest('.doc-panel');
display = panel ? panel.querySelector('.doc-display') : null;
if (!display) display = document.getElementById('doc-main-display');
if (!display) return false;
activeIndex = tabs.findIndex(function (tab) {
return tab.classList.contains('active');
});
if (activeIndex < 0) activeIndex = 0;
nextIndex = (activeIndex + direction + tabs.length) % tabs.length;
nextTab = tabs[nextIndex];
tabs.forEach(function (tab, index) {
tab.classList.toggle('active', index === nextIndex);
});
ref = nextTab.dataset ? nextTab.dataset.ref : '';
source = ref ? document.getElementById(ref) : null;
display.innerHTML = source ? source.innerHTML : (nextTab.dataset ? (nextTab.dataset.content || '') : '');
return true;
}
function handleNationsShortcuts(event) {
var key = keyOf(event);
var direction;
var handled = false;
if (isEditableTarget(event.target)) return false;
if (key !== 'q' && key !== 'e') return false;
direction = key === 'q' ? -1 : 1;
if (event.shiftKey && !event.ctrlKey && !event.metaKey && !event.altKey) {
handled = switchNationHistoryYear(direction);
} else if (hasCtrlOrMeta(event) && !event.shiftKey && !event.altKey) {
handled = switchNationContinent(direction);
} else if (!event.shiftKey && !event.ctrlKey && !event.metaKey && !event.altKey) {
handled = switchNationEra(direction);
}
if (!handled) return false;
prevent(event);
return true;
}
function handleDocTabShortcuts(event) {
var key = keyOf(event);
var direction;
if (isEditableTarget(event.target)) return false;
if (event.ctrlKey || event.metaKey || event.shiftKey || event.altKey) return false;
if (key !== 'q' && key !== 'e') return false;
direction = key === 'q' ? -1 : 1;
if (!switchDocTab(direction)) return false;
prevent(event);
return true;
}
function handleKeydown(event) {
if (handleSaveShortcut(event)) return;
if (handleNationsShortcuts(event)) return;
handleDocTabShortcuts(event);
}
document.addEventListener('keydown', handleKeydown, true);
window.Shortcuts = window.Shortcuts || {};
window.Shortcuts.version = '20260704-4';
window.Shortcuts.scope = ROOT_SELECTOR;
}());