Files
minecraft_launcher/views/op/datapack.ejs
claude-bot c0472bb57b site: 사이트 팝업창 ESC 로 닫기 지원
- listEditor: keydown(Escape) 시 열린 .modalOverlay 닫기. 별칭 모달은
  "돌아가기" 와 동일하게 입력값을 저장한 뒤 닫는다.
- datapack: pickModal 도 ESC 로 닫히게 추가.

(팝업 바깥 영역 클릭으로 닫기는 두 페이지 모두 기존부터 동작 중.)
2026-05-13 16:44:58 +09:00

135 lines
5.5 KiB
Plaintext

<!doctype html>
<html lang="ko">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title><%= t('datapack.browserTitle') %></title>
<link rel="stylesheet" href="/static/styles.css" />
</head>
<body class="siteBody">
<%- include('../partials/navbar', { userId }) %>
<main class="pageWrap">
<section class="dashboardHeader">
<div>
<a class="ghostLink" href="/op/dashboard"><%= t('common.back') %></a>
<h1 style="margin-top:20px;"><%= t('datapack.title') %></h1>
</div>
</section>
<p class="muted"><%= t('datapack.hint') %></p>
<section class="dpControls">
<button type="button" class="primaryButton" id="pickPackBtn"><%= t('datapack.pickPack') %></button>
<span class="muted" id="pickedLabel"><%= t('datapack.pickedNone') %></span>
</section>
<p class="muted" id="countLabel"></p>
<section class="dpActions" hidden id="dpActions">
<button type="button" class="secondaryButton" id="exportBtn"><%= t('datapack.export') %></button>
<button type="button" class="secondaryButton" id="copyBtn"><%= t('datapack.copy') %></button>
<span class="statusText" id="dp-status"></span>
</section>
<pre class="codeBlock" id="codeOut" hidden></pre>
</main>
<!-- 음악퀴즈 선택 팝업 -->
<div class="modalOverlay" id="pickModal" hidden>
<div class="modalCard">
<header><h3><%= t('datapack.modalPickTitle') %></h3>
<button class="modalClose" type="button" data-modal-close><%= t('common.close') %></button>
</header>
<div class="modalBody">
<div class="cardRow horizontalScroll" id="pickList">
<% items.forEach(function (item) { %>
<article class="packCard pickable"
data-key="<%= item.key %>"
data-name="<%= item.definition ? item.definition.name : item.key %>"
data-music-count="<%= item.musicCount %>">
<h2><%= item.definition ? item.definition.name : item.key %></h2>
<p class="muted"><%= item.key %>.json</p>
<% if (item.definition) { %>
<ul class="metaList">
<li><%= t('dashboard.mcShort') %> <%= item.definition.mcVersion %></li>
<li><%= t('site.platform') %> <%= item.definition.platform.type %></li>
</ul>
<% } %>
</article>
<% }) %>
</div>
</div>
</div>
</div>
<script>
var I18N = <%- JSON.stringify(localeDict.datapack) %>;
</script>
<script>
(function () {
var pickModal = document.getElementById('pickModal')
var pickedKey = ''
document.getElementById('pickPackBtn').addEventListener('click', function () {
pickModal.hidden = false
})
document.querySelectorAll('[data-modal-close]').forEach(function (b) {
b.addEventListener('click', function () { pickModal.hidden = true })
})
pickModal.addEventListener('click', function (e) {
if (e.target === pickModal) pickModal.hidden = true
})
// ESC 로 닫기.
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape' && !pickModal.hidden) {
pickModal.hidden = true
e.preventDefault()
}
})
document.querySelectorAll('#pickList .pickable').forEach(function (card) {
card.addEventListener('click', function () {
pickedKey = card.getAttribute('data-key')
var name = card.getAttribute('data-name')
var count = card.getAttribute('data-music-count') || '0'
document.getElementById('pickedLabel').textContent = I18N.pickedLabel.replace('{{name}}', name)
document.getElementById('countLabel').textContent = I18N.totalCount.replace('{{count}}', count)
pickModal.hidden = true
document.getElementById('dpActions').hidden = false
document.getElementById('dp-status').textContent = ''
document.getElementById('dp-status').classList.remove('error')
document.getElementById('codeOut').hidden = true
document.getElementById('codeOut').textContent = ''
})
})
document.getElementById('exportBtn').addEventListener('click', function () {
if (!pickedKey) return
var s = document.getElementById('dp-status')
s.textContent = I18N.exporting; s.classList.remove('error')
fetch('/op/datapack/' + encodeURIComponent(pickedKey) + '/generate')
.then(function (r) { return r.text().then(function (t) { return { ok: r.ok, text: t } }) })
.then(function (res) {
if (!res.ok) {
s.textContent = I18N.failed.replace('{{message}}', res.text); s.classList.add('error')
return
}
var out = document.getElementById('codeOut')
out.textContent = res.text
out.hidden = false
s.textContent = I18N.exported
})
.catch(function (err) { s.textContent = I18N.failed.replace('{{message}}', err.message); s.classList.add('error') })
})
document.getElementById('copyBtn').addEventListener('click', function () {
var out = document.getElementById('codeOut')
if (out.hidden) return
navigator.clipboard.writeText(out.textContent).then(function () {
var s = document.getElementById('dp-status')
s.textContent = I18N.copied
s.classList.remove('error')
})
})
})()
</script>
</body>
</html>