|
1 | 1 | /** |
2 | 2 | * HIG Lab — 챕터 커뮤니티 위젯 |
3 | 3 | * |
4 | | - * 포함: KakaoTalk 오픈채팅 배너 (QR 포함) + Giscus 댓글 |
| 4 | + * 포함: KakaoTalk 오픈채팅 배너 (QR 포함) + Giscus 댓글 + 카카오페이 후원 플로팅 버튼 |
5 | 5 | */ |
6 | 6 |
|
7 | 7 | (function () { |
|
18 | 18 | return depth <= 2 ? 'kakao-openchat-qr.jpg' : '../kakao-openchat-qr.jpg'; |
19 | 19 | } |
20 | 20 |
|
| 21 | + function getPayQRPath() { |
| 22 | + const depth = (window.location.pathname.match(/\//g) || []).length; |
| 23 | + return depth <= 2 ? 'kakao-pay-qr.jpg' : '../kakao-pay-qr.jpg'; |
| 24 | + } |
| 25 | + |
21 | 26 | function injectCSS() { |
22 | 27 | if (document.getElementById('hig-community-css')) return; |
23 | 28 | const s = document.createElement('style'); |
|
92 | 97 | color: #6e6e73; |
93 | 98 | margin-bottom: 1rem; |
94 | 99 | } |
| 100 | +
|
| 101 | +/* ── 후원 플로팅 버튼 ── */ |
| 102 | +.hig-sponsor-fab { |
| 103 | + position: fixed; |
| 104 | + bottom: 28px; |
| 105 | + right: 28px; |
| 106 | + z-index: 9999; |
| 107 | + display: flex; |
| 108 | + align-items: center; |
| 109 | + gap: 8px; |
| 110 | + background: #3C1E1E; |
| 111 | + color: #FEE500; |
| 112 | + border: none; |
| 113 | + border-radius: 100px; |
| 114 | + padding: 12px 20px 12px 16px; |
| 115 | + font-size: .9rem; |
| 116 | + font-weight: 700; |
| 117 | + font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; |
| 118 | + cursor: pointer; |
| 119 | + box-shadow: 0 6px 24px rgba(0,0,0,.22); |
| 120 | + transition: transform .2s, box-shadow .2s; |
| 121 | +} |
| 122 | +.hig-sponsor-fab:hover { |
| 123 | + transform: translateY(-3px); |
| 124 | + box-shadow: 0 12px 32px rgba(0,0,0,.28); |
| 125 | +} |
| 126 | +
|
| 127 | +/* ── 후원 모달 오버레이 ── */ |
| 128 | +.hig-sponsor-overlay { |
| 129 | + display: none; |
| 130 | + position: fixed; |
| 131 | + inset: 0; |
| 132 | + background: rgba(0,0,0,.5); |
| 133 | + z-index: 10000; |
| 134 | + align-items: center; |
| 135 | + justify-content: center; |
| 136 | + backdrop-filter: blur(4px); |
| 137 | +} |
| 138 | +.hig-sponsor-overlay.open { |
| 139 | + display: flex; |
| 140 | +} |
| 141 | +.hig-sponsor-modal { |
| 142 | + background: #fff; |
| 143 | + border-radius: 24px; |
| 144 | + padding: 32px 28px 28px; |
| 145 | + max-width: 320px; |
| 146 | + width: 90%; |
| 147 | + text-align: center; |
| 148 | + box-shadow: 0 24px 80px rgba(0,0,0,.18); |
| 149 | + position: relative; |
| 150 | + animation: hig-modal-in .25s ease; |
| 151 | +} |
| 152 | +@keyframes hig-modal-in { |
| 153 | + from { opacity: 0; transform: scale(.92) translateY(12px); } |
| 154 | + to { opacity: 1; transform: scale(1) translateY(0); } |
| 155 | +} |
| 156 | +.hig-sponsor-modal .hig-modal-close { |
| 157 | + position: absolute; |
| 158 | + top: 16px; right: 18px; |
| 159 | + background: none; border: none; |
| 160 | + font-size: 1.3rem; cursor: pointer; |
| 161 | + color: #999; line-height: 1; |
| 162 | +} |
| 163 | +.hig-sponsor-modal .hig-modal-title { |
| 164 | + font-size: 1.15rem; font-weight: 800; |
| 165 | + color: #1d1d1f; margin-bottom: 4px; |
| 166 | +} |
| 167 | +.hig-sponsor-modal .hig-modal-desc { |
| 168 | + font-size: .82rem; color: #6e6e73; |
| 169 | + margin-bottom: 20px; line-height: 1.6; |
| 170 | +} |
| 171 | +.hig-sponsor-modal .hig-modal-qr { |
| 172 | + width: 200px; height: 200px; |
| 173 | + border-radius: 16px; |
| 174 | + object-fit: cover; |
| 175 | + margin: 0 auto 12px; |
| 176 | + display: block; |
| 177 | + box-shadow: 0 4px 16px rgba(0,0,0,.1); |
| 178 | +} |
| 179 | +.hig-sponsor-modal .hig-modal-label { |
| 180 | + font-size: .78rem; color: #aaa; font-weight: 500; |
| 181 | +} |
95 | 182 | `; |
96 | 183 | document.head.appendChild(s); |
97 | 184 | } |
|
140 | 227 | script.crossOrigin = 'anonymous'; |
141 | 228 | script.async = true; |
142 | 229 | container.querySelector('.hig-community').appendChild(script); |
| 230 | + |
| 231 | + injectSponsorFab(); |
| 232 | + } |
| 233 | + |
| 234 | + function injectSponsorFab() { |
| 235 | + if (document.getElementById('hig-sponsor-fab')) return; |
| 236 | + |
| 237 | + const payQR = getPayQRPath(); |
| 238 | + |
| 239 | + // 플로팅 버튼 |
| 240 | + const fab = document.createElement('button'); |
| 241 | + fab.id = 'hig-sponsor-fab'; |
| 242 | + fab.className = 'hig-sponsor-fab'; |
| 243 | + fab.innerHTML = '<span style="font-size:1.2rem">☕</span> 후원하기'; |
| 244 | + document.body.appendChild(fab); |
| 245 | + |
| 246 | + // 모달 오버레이 |
| 247 | + const overlay = document.createElement('div'); |
| 248 | + overlay.id = 'hig-sponsor-overlay'; |
| 249 | + overlay.className = 'hig-sponsor-overlay'; |
| 250 | + overlay.innerHTML = ` |
| 251 | + <div class="hig-sponsor-modal"> |
| 252 | + <button class="hig-modal-close" id="hig-modal-close">✕</button> |
| 253 | + <div class="hig-modal-title">☕ HIG Lab 후원하기</div> |
| 254 | + <div class="hig-modal-desc">카카오페이로 소액 후원하시면<br>콘텐츠 제작에 큰 힘이 됩니다 🙏</div> |
| 255 | + <img class="hig-modal-qr" src="${payQR}" alt="카카오페이 후원 QR"/> |
| 256 | + <div class="hig-modal-label">카메라로 QR 스캔 · 카카오페이</div> |
| 257 | + </div> |
| 258 | + `; |
| 259 | + document.body.appendChild(overlay); |
| 260 | + |
| 261 | + fab.addEventListener('click', () => overlay.classList.add('open')); |
| 262 | + document.getElementById('hig-modal-close').addEventListener('click', () => overlay.classList.remove('open')); |
| 263 | + overlay.addEventListener('click', (e) => { |
| 264 | + if (e.target === overlay) overlay.classList.remove('open'); |
| 265 | + }); |
| 266 | + } |
| 267 | + |
| 268 | + function init() { |
| 269 | + render(); // community-widget 있는 페이지에서만 실행 |
| 270 | + injectSponsorFab(); // 모든 페이지에서 항상 실행 |
143 | 271 | } |
144 | 272 |
|
145 | 273 | if (document.readyState === 'loading') { |
146 | | - document.addEventListener('DOMContentLoaded', render); |
| 274 | + document.addEventListener('DOMContentLoaded', init); |
147 | 275 | } else { |
148 | | - render(); |
| 276 | + init(); |
149 | 277 | } |
150 | 278 | })(); |
0 commit comments