File manager - Edit - /home/webapp69.cm.in.th/u69319090029/Project SME/js/nav_sound_swal.js
Back
/* ============================================================ CMTC Smart Dining - Global SweetAlert2 & Navigation Sound FX Engine ============================================================ */ (function() { 'use strict'; // 1. Navigation Sound System (Web Audio API Synthesizer) let soundEnabled = localStorage.getItem('cmtc_nav_sound_enabled') === 'true'; window.playNavSound = function(type) { if (!soundEnabled) return; try { const AudioCtx = window.AudioContext || window.webkitAudioContext; if (!AudioCtx) return; const ctx = new AudioCtx(); const osc = ctx.createOscillator(); const gain = ctx.createGain(); osc.connect(gain); gain.connect(ctx.destination); if (type === 'tab' || type === 'nav') { osc.type = 'sine'; osc.frequency.setValueAtTime(523.25, ctx.currentTime); // C5 osc.frequency.exponentialRampToValueAtTime(659.25, ctx.currentTime + 0.08); // E5 gain.gain.setValueAtTime(0.12, ctx.currentTime); gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.08); osc.start(); osc.stop(ctx.currentTime + 0.08); } else if (type === 'toggle') { osc.type = 'triangle'; osc.frequency.setValueAtTime(440, ctx.currentTime); osc.frequency.exponentialRampToValueAtTime(880, ctx.currentTime + 0.1); gain.gain.setValueAtTime(0.18, ctx.currentTime); gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.1); osc.start(); osc.stop(ctx.currentTime + 0.1); } else if (type === 'success') { osc.type = 'sine'; osc.frequency.setValueAtTime(523.25, ctx.currentTime); osc.frequency.setValueAtTime(659.25, ctx.currentTime + 0.1); osc.frequency.setValueAtTime(783.99, ctx.currentTime + 0.2); // G5 gain.gain.setValueAtTime(0.2, ctx.currentTime); gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.35); osc.start(); osc.stop(ctx.currentTime + 0.35); } else { // soft click osc.type = 'sine'; osc.frequency.setValueAtTime(600, ctx.currentTime); osc.frequency.exponentialRampToValueAtTime(300, ctx.currentTime + 0.05); gain.gain.setValueAtTime(0.08, ctx.currentTime); gain.gain.exponentialRampToValueAtTime(0.001, ctx.currentTime + 0.05); osc.start(); osc.stop(ctx.currentTime + 0.05); } } catch(e) {} }; window.toggleNavSound = function() { soundEnabled = !soundEnabled; localStorage.setItem('cmtc_nav_sound_enabled', soundEnabled ? 'true' : 'false'); if (soundEnabled) { window.playNavSound('toggle'); } window.updateNavSoundUI(); if (typeof Swal !== 'undefined') { Swal.fire({ icon: 'info', title: soundEnabled ? '🔊 เปิดเสียงนำทางแล้ว' : '🔇 ปิดเสียงนำทางแล้ว', text: soundEnabled ? 'ระบบจะเล่นเสียงประกอบเอฟเฟกต์เมื่อคลิกเปลี่ยนเมนู' : 'ปิดการเล่นเสียงประกอบการนำทางแล้ว', timer: 1500, showConfirmButton: false }); } }; window.updateNavSoundUI = function() { const btns = document.querySelectorAll('.nav-sound-toggle-btn'); btns.forEach(btn => { btn.innerHTML = soundEnabled ? '🔊 เสียงนำทาง: เปิด' : '🔇 เสียงนำทาง: ปิด'; btn.style.background = soundEnabled ? 'rgba(0, 229, 255, 0.2)' : 'rgba(255, 255, 255, 0.08)'; btn.style.color = soundEnabled ? '#00E5FF' : '#94a3b8'; btn.style.borderColor = soundEnabled ? '#00E5FF' : 'rgba(255, 255, 255, 0.2)'; }); }; // 2. SweetAlert2 Window Alert Override Helper const nativeAlert = window.alert; window.alert = function(msg) { if (typeof Swal !== 'undefined') { Swal.fire({ title: 'แจ้งเตือนระบบ', text: msg, icon: 'info', confirmButtonColor: '#00E5FF', confirmButtonText: 'ตกลง' }); } else { nativeAlert(msg); } }; // Global SweetAlert2 Confirmation helper window.swalConfirm = function(options) { const title = options.title || 'ยืนยันการทำรายการ?'; const text = options.text || ''; const icon = options.icon || 'warning'; const confirmText = options.confirmText || 'ยืนยัน'; const cancelText = options.cancelText || 'ยกเลิก'; const confirmColor = options.confirmColor || '#00E5FF'; if (typeof Swal !== 'undefined') { return Swal.fire({ title: title, text: text, icon: icon, showCancelButton: true, confirmButtonText: confirmText, cancelButtonText: cancelText, confirmButtonColor: confirmColor, cancelButtonColor: '#475569', reverseButtons: true }); } else { return Promise.resolve({ isConfirmed: confirm(title + (text ? '\n' + text : '')) }); } }; // 3. Auto Intercept all inline onclick="confirm(...)" elements and replace with SweetAlert2 document.addEventListener('click', function(e) { const el = e.target.closest('[onclick*="confirm"]'); if (el && !el.dataset.swalBypassed) { e.preventDefault(); e.stopPropagation(); let msg = 'คุณต้องการยืนยันการทำรายการนี้ใช่หรือไม่?'; const onclickAttr = el.getAttribute('onclick') || ''; const match = onclickAttr.match(/confirm\((['"])(.*?)\1\)/); if (match && match[2]) { msg = match[2].replace(/\\n/g, '<br>').replace(/\\'/g, "'"); } if (typeof Swal !== 'undefined') { Swal.fire({ title: 'ยืนยันการทำรายการ', html: msg, icon: 'warning', showCancelButton: true, confirmButtonText: 'ยืนยัน', cancelButtonText: 'ยกเลิก', confirmButtonColor: '#00E5FF', cancelButtonColor: '#475569', reverseButtons: true }).then(result => { if (result.isConfirmed) { el.dataset.swalBypassed = 'true'; if (el.tagName === 'A' && el.href) { location.href = el.href; } else if (el.type === 'submit' || el.tagName === 'BUTTON') { const form = el.closest('form'); if (form) { if (el.name) { const hidden = document.createElement('input'); hidden.type = 'hidden'; hidden.name = el.name; hidden.value = el.value; form.appendChild(hidden); } form.submit(); } else { el.click(); } } else { el.click(); } } }); } else { if (confirm(msg.replace(/<br>/g, '\n'))) { el.dataset.swalBypassed = 'true'; el.click(); } } } }, true); // Auto Bind Event Listeners on DOM Loaded document.addEventListener('DOMContentLoaded', function() { window.updateNavSoundUI(); // Audio delegation for navigation links & buttons document.body.addEventListener('click', function(e) { const target = e.target.closest('.menu-btn, .mobile-nav-btn, .sidebar-category-header, .tab-btn, .nav-link, .btn-primary, .btn-secondary, .btn-sm, .nav-sound-trigger'); if (target && !target.classList.contains('nav-sound-toggle-btn')) { window.playNavSound('tab'); } }); }); })();
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings