feat(프로젝트): 시각 고르기를 공용 시각 팝업으로 — 옵션 알림 시각·긴급 공지 띄울 시각
- project.js openTimePopover·enhanceTimeInput(PJLib): 날짜 팝업 모양, 시 00~23·분 5분 단위, 끝에서 멈춤 - 모달 dialog 안이면 그 창 안 popover, 아니면 body Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,88 +63,12 @@
|
||||
btn.classList.toggle("is-empty", !v);
|
||||
}
|
||||
|
||||
// ── 시각 고르기 팝업(2026-11-11) — 날짜 팝업(.pj-datepop)과 같은 카드·꼬리·파란 선택.
|
||||
// 시(00~23)·분(00~55, 5분 단위) 두 열, 브라우저 기본 시계처럼 돌아가지 않고 끝에서 멈춘다.
|
||||
// 모달 창 위에 떠야 해서 popover(top layer) — 단 옵션 창(dialog) **안에** 붙인다: 모달이 열려 있으면 창 밖 요소는
|
||||
// inert 라 body 에 붙이면 휠·마우스 오버·클릭이 모두 안 먹었다(2026-11-11). 시 = 바꾸고 열어 둠, 분 = 바꾸고 닫음.
|
||||
// [확인] = 지금 값 저장 후 닫기, [지우기] = 시각 비우고 닫기(저장 버튼을 눌러야 서버에 반영).
|
||||
let timePop = null, timePopOff = null;
|
||||
function closeTimePop() {
|
||||
if (!timePop) return;
|
||||
if (timePopOff) timePopOff();
|
||||
try { timePop.hidePopover(); } catch (_) {}
|
||||
timePop.remove(); timePop = timePopOff = null;
|
||||
}
|
||||
function pad2(n) { return (n < 10 ? "0" : "") + n; }
|
||||
// 시각 고르기 = 프로젝트 공용 날짜 팝업 모양 시각 팝업(project.js openTimePopover — 옵션 창 안에 붙어 휠·클릭이 먹음)
|
||||
function openTimePop(btn) {
|
||||
closeTimePop();
|
||||
const cur = btn.dataset.value || "";
|
||||
let h = cur ? cur.slice(0, 2) : "", m = cur ? cur.slice(3, 5) : "";
|
||||
const pop = document.createElement("div");
|
||||
pop.className = "pj-datepop pj-timepop";
|
||||
pop.setAttribute("popover", "manual");
|
||||
function col(kind, list, sel) {
|
||||
return '<div class="pj-tp-col" data-kind="' + kind + '">' + list.map(function (v) {
|
||||
return '<button type="button" class="pj-tp-item' + (v === sel ? " is-selected" : "") + '" data-v="' + v + '">' + v + "</button>";
|
||||
}).join("") + "</div>";
|
||||
}
|
||||
const hours = [], mins = [];
|
||||
for (let i = 0; i < 24; i++) hours.push(pad2(i));
|
||||
for (let i = 0; i < 60; i += 5) mins.push(pad2(i));
|
||||
function paintHead() { pop.querySelector(".pj-tp-value").textContent = (h || "--") + ":" + (m || "--"); }
|
||||
pop.innerHTML = '<div class="pj-dp-fields"><span class="pj-dp-field is-active pj-tp-value"></span></div>' +
|
||||
'<div class="pj-tp-heads"><span>시</span><span>분</span></div>' +
|
||||
'<div class="pj-tp-cols">' + col("h", hours, h) + col("m", mins, m) + "</div>" +
|
||||
'<div class="pj-dp-foot"><button type="button" class="pj-dp-link" data-tp="clear">지우기</button>' +
|
||||
'<button type="button" class="pj-dp-link" data-tp="ok">확인</button></div>';
|
||||
paintHead();
|
||||
dialog.appendChild(pop);
|
||||
try { pop.showPopover(); } catch (_) {}
|
||||
function commit() { if (h) setTimeBtn(btn, h + ":" + (m || "00")); }
|
||||
pop.addEventListener("click", function (e) {
|
||||
const it = e.target.closest(".pj-tp-item");
|
||||
if (it) {
|
||||
const kind = it.parentNode.dataset.kind;
|
||||
it.parentNode.querySelectorAll(".is-selected").forEach(function (x) { x.classList.remove("is-selected"); });
|
||||
it.classList.add("is-selected");
|
||||
if (kind === "h") { h = it.dataset.v; if (!m) m = "00"; } else { m = it.dataset.v; if (!h) h = "09"; }
|
||||
paintHead(); commit();
|
||||
if (kind === "m") closeTimePop();
|
||||
return;
|
||||
}
|
||||
const act = e.target.closest("[data-tp]");
|
||||
if (!act) return;
|
||||
if (act.dataset.tp === "clear") { h = m = ""; setTimeBtn(btn, ""); }
|
||||
else commit();
|
||||
closeTimePop(); btn.focus();
|
||||
});
|
||||
// 자리 — 앵커 아래(자리 없으면 위), 꼬리가 앵커 가운데(날짜 팝업 place 와 같음).
|
||||
// 화면 배율(.pj-ui-scale zoom) 안이면 left/top 값도 배율만큼 줄어 보이므로 나눠 준다(currentCSSZoom).
|
||||
const z = pop.currentCSSZoom || 1;
|
||||
const r = btn.getBoundingClientRect();
|
||||
const vw = document.documentElement.clientWidth, vh = document.documentElement.clientHeight;
|
||||
const w = pop.offsetWidth * z, ph = pop.offsetHeight * z, ax = r.left + r.width / 2;
|
||||
const left = Math.min(Math.max(8, ax - w / 2), vw - w - 8);
|
||||
const below = r.bottom + 10 + ph <= vh - 8 || r.top - 10 - ph < 8;
|
||||
pop.classList.toggle("is-above", !below);
|
||||
pop.style.left = left / z + "px";
|
||||
pop.style.top = (below ? r.bottom + 10 : r.top - 10 - ph) / z + "px";
|
||||
pop.style.setProperty("--pj-dp-tail", Math.min(Math.max(ax - left, 16), w - 16) / z + "px");
|
||||
// 고른 값이 보이게 — 열 안에서만 스크롤(맨 위 00 부터, 끝에서 멈춤)
|
||||
pop.querySelectorAll(".pj-tp-col").forEach(function (c) {
|
||||
const sel = c.querySelector(".is-selected");
|
||||
if (sel) c.scrollTop = sel.offsetTop - c.offsetTop - (c.clientHeight - sel.offsetHeight) / 2;
|
||||
});
|
||||
function onDown(e) { if (!pop.contains(e.target) && !btn.contains(e.target)) closeTimePop(); }
|
||||
function onKey(e) { if (e.key === "Escape") { e.preventDefault(); e.stopPropagation(); closeTimePop(); btn.focus(); } }
|
||||
document.addEventListener("pointerdown", onDown, true);
|
||||
document.addEventListener("keydown", onKey, true);
|
||||
timePop = pop;
|
||||
timePopOff = function () {
|
||||
document.removeEventListener("pointerdown", onDown, true);
|
||||
document.removeEventListener("keydown", onKey, true);
|
||||
};
|
||||
if (!window.PJLib || !window.PJLib.openTimePopover) return;
|
||||
window.PJLib.openTimePopover(btn, { value: btn.dataset.value || "", onChange: function (v) { setTimeBtn(btn, v); } });
|
||||
}
|
||||
function closeTimePop() { if (window.PJLib && window.PJLib.closeTimePopover) window.PJLib.closeTimePopover(); }
|
||||
function renumberTimes() {
|
||||
if (!timesBox) return;
|
||||
Array.from(timesBox.children).forEach(function (li, i) { li.firstChild.textContent = "알림 " + (i + 1); });
|
||||
@@ -158,7 +82,7 @@
|
||||
const tb = li.querySelector(".pj-time-btn"), del = li.querySelector(".pj-time-del");
|
||||
setTimeBtn(tb, v);
|
||||
tb.disabled = del.disabled = !sys;
|
||||
tb.addEventListener("click", function () { if (timePop) closeTimePop(); else openTimePop(tb); });
|
||||
tb.addEventListener("click", function () { if (document.querySelector(".pj-timepop")) closeTimePop(); else openTimePop(tb); });
|
||||
del.addEventListener("click", function () { closeTimePop(); li.remove(); renumberTimes(); });
|
||||
timesBox.appendChild(li);
|
||||
renumberTimes();
|
||||
|
||||
Reference in New Issue
Block a user