File size: 5,560 Bytes
857cdcf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | /**
* Auth Dialog System - ระบบกล่องแจ้งเตือนล็อกอิน
* สำหรับแจ้งเตือนเมื่อผู้ใช้ยังไม่ได้ล็อกอิน
*/
class AuthDialog {
constructor() {
this.createStyles();
}
createStyles() {
const styles = `
.auth-dialog-overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.8);
backdrop-filter: blur(5px);
display: flex;
align-items: center;
justify-content: center;
z-index: 15000;
animation: auth-dialog-fade-in 0.3s ease-out;
}
.auth-dialog-box {
background: linear-gradient(135deg, #1a1a1a 0%, #0a0a0a 100%);
border: 2px solid #333;
border-radius: 12px;
padding: 30px;
max-width: 400px;
width: 90%;
box-shadow:
0 20px 40px rgba(0, 0, 0, 0.5),
0 0 0 1px rgba(255, 255, 255, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.1);
animation: auth-dialog-slide-up 0.3s ease-out;
text-align: center;
}
.auth-dialog-header {
color: #e0e0e0;
font-size: 18px;
font-weight: 600;
margin-bottom: 8px;
padding-bottom: 15px;
border-bottom: 1px solid #333;
}
.auth-dialog-message {
color: #b0b0b0;
font-size: 16px;
line-height: 1.5;
margin-bottom: 25px;
margin-top: 15px;
}
.auth-dialog-button {
background: linear-gradient(135deg, #0ea5e9, #0284c7);
border: none;
color: white;
padding: 12px 24px;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(14, 165, 233, 0.3);
min-width: 100px;
}
.auth-dialog-button:hover {
background: linear-gradient(135deg, #0284c7, #0369a1);
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(14, 165, 233, 0.4);
}
.auth-dialog-button:active {
transform: translateY(0);
}
@keyframes auth-dialog-fade-in {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes auth-dialog-slide-up {
from {
opacity: 0;
transform: translateY(30px) scale(0.9);
}
to {
opacity: 1;
transform: translateY(0) scale(1);
}
}
`;
// เพิ่ม CSS styles
if (!document.getElementById('auth-dialog-styles')) {
const styleElement = document.createElement('style');
styleElement.id = 'auth-dialog-styles';
styleElement.textContent = styles;
document.head.appendChild(styleElement);
}
}
show(options = {}) {
const {
title = 'ข้อความจาก chahuadev.com',
message = 'กรุณาล็อกอินก่อนใช้งาน',
buttonText = 'ตกลง'
} = options;
// ลบ dialog เก่าถ้ามี
this.hide();
// สร้าง dialog overlay
const overlay = document.createElement('div');
overlay.className = 'auth-dialog-overlay';
overlay.id = 'auth-dialog-overlay';
// สร้าง dialog box
const dialog = document.createElement('div');
dialog.className = 'auth-dialog-box';
dialog.innerHTML = `
<div class="auth-dialog-header">${title}</div>
<div class="auth-dialog-message">${message}</div>
<button class="auth-dialog-button" onclick="authDialog.hide()">${buttonText}</button>
`;
overlay.appendChild(dialog);
document.body.appendChild(overlay);
// ปิด dialog เมื่อคลิกข้างนอก
overlay.addEventListener('click', (e) => {
if (e.target === overlay) {
this.hide();
}
});
// ปิด dialog ด้วย ESC key
const escapeHandler = (e) => {
if (e.key === 'Escape') {
this.hide();
document.removeEventListener('keydown', escapeHandler);
}
};
document.addEventListener('keydown', escapeHandler);
}
hide() {
const overlay = document.getElementById('auth-dialog-overlay');
if (overlay) {
overlay.style.animation = 'auth-dialog-fade-in 0.2s ease-out reverse';
setTimeout(() => {
overlay.remove();
}, 200);
}
}
}
// สร้าง instance ของ AuthDialog
window.authDialog = new AuthDialog(); |