- Eliminado script de scroll en public-chat.blade.php (conflictaba con el del layout)
- Reescrito script en chat-publico.blade.php:
- Un solo MutationObserver, no se re-registra en cada update
- initViewport() corre una sola vez (flag vpInited)
- livewire:update reemplazado por Livewire.hook('message.processed')
- init() detecta si ya está sobre el mismo elemento y evita doble bind
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
213 lines
7.1 KiB
PHP
Executable File
213 lines
7.1 KiB
PHP
Executable File
<!DOCTYPE html>
|
|
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover">
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
<meta name="color-scheme" content="dark">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
<meta name="apple-mobile-web-app-title" content="Chat">
|
|
<title>Chat en vivo | {{ config('app.name') }}</title>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
|
|
<script src="https://cdn.tailwindcss.com"></script>
|
|
<style>
|
|
*, *::before, *::after { box-sizing: border-box; }
|
|
|
|
html, body {
|
|
margin: 0; padding: 0;
|
|
font-family: 'Inter', sans-serif;
|
|
-webkit-tap-highlight-color: transparent;
|
|
overscroll-behavior: none;
|
|
}
|
|
|
|
/* Móvil: pantalla completa */
|
|
body {
|
|
background: #111b21;
|
|
height: 100vh;
|
|
height: 100dvh;
|
|
height: -webkit-fill-available;
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* Desktop: fondo con gradiente + chat centrado como frame */
|
|
@media (min-width: 640px) {
|
|
body {
|
|
background: #0d1117;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
overflow: hidden;
|
|
}
|
|
}
|
|
|
|
/* El contenedor del chat */
|
|
#chat-root {
|
|
width: 100%;
|
|
height: 100vh;
|
|
height: 100dvh;
|
|
height: -webkit-fill-available;
|
|
display: flex;
|
|
flex-direction: column;
|
|
background: #111b21;
|
|
overflow: hidden;
|
|
}
|
|
|
|
@media (min-width: 640px) {
|
|
#chat-root {
|
|
width: 420px;
|
|
height: 90vh;
|
|
height: 90dvh;
|
|
max-height: 820px;
|
|
border-radius: 20px;
|
|
box-shadow: 0 24px 64px rgba(0,0,0,.6);
|
|
overflow: hidden;
|
|
}
|
|
}
|
|
|
|
/* Evita zoom en inputs iOS */
|
|
input, textarea, select { font-size: 16px !important; }
|
|
|
|
/* Scroll suave nativo */
|
|
.ios-scroll {
|
|
-webkit-overflow-scrolling: touch;
|
|
overscroll-behavior-y: contain;
|
|
}
|
|
|
|
/* Elimina appearance por defecto iOS */
|
|
input[type="tel"], input[type="text"],
|
|
input[type="email"], textarea {
|
|
-webkit-appearance: none;
|
|
appearance: none;
|
|
border-radius: 12px;
|
|
}
|
|
|
|
button {
|
|
-webkit-appearance: none;
|
|
touch-action: manipulation;
|
|
cursor: pointer;
|
|
}
|
|
|
|
/* Safe areas (solo afectan en iOS con viewport-fit=cover) */
|
|
.safe-top { padding-top: env(safe-area-inset-top, 0px); }
|
|
.safe-bottom { padding-bottom: env(safe-area-inset-bottom, 0px); }
|
|
.safe-left { padding-left: env(safe-area-inset-left, 0px); }
|
|
.safe-right { padding-right: env(safe-area-inset-right, 0px); }
|
|
</style>
|
|
@livewireStyles
|
|
</head>
|
|
<body>
|
|
|
|
<livewire:chat.public-chat />
|
|
|
|
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
|
|
@livewireScripts
|
|
|
|
<script>
|
|
(function () {
|
|
var msgsEl = null;
|
|
var isAtBottom = true;
|
|
var newMsgCount = 0;
|
|
var lastCount = 0;
|
|
var observer = null;
|
|
var vpInited = false;
|
|
|
|
function checkBottom() {
|
|
if (!msgsEl) return true;
|
|
return (msgsEl.scrollHeight - msgsEl.scrollTop - msgsEl.clientHeight) <= 100;
|
|
}
|
|
|
|
function scrollBottom() {
|
|
if (msgsEl) msgsEl.scrollTop = msgsEl.scrollHeight;
|
|
}
|
|
|
|
function updateBadge() {
|
|
var badge = document.getElementById('new-msg-badge');
|
|
var count = document.getElementById('new-msg-count');
|
|
if (!badge) return;
|
|
if (newMsgCount > 0 && !isAtBottom) {
|
|
if (count) count.textContent = newMsgCount;
|
|
badge.classList.remove('hidden');
|
|
badge.classList.add('flex');
|
|
} else {
|
|
badge.classList.add('hidden');
|
|
badge.classList.remove('flex');
|
|
}
|
|
}
|
|
|
|
function countMsgs() {
|
|
return msgsEl ? msgsEl.children.length : 0;
|
|
}
|
|
|
|
function init() {
|
|
var el = document.getElementById('pub-messages');
|
|
if (!el || el === msgsEl) return; // ya inicializado sobre el mismo elemento
|
|
|
|
msgsEl = el;
|
|
lastCount = countMsgs();
|
|
|
|
msgsEl.addEventListener('scroll', function () {
|
|
isAtBottom = checkBottom();
|
|
if (isAtBottom) { newMsgCount = 0; updateBadge(); }
|
|
}, { passive: true });
|
|
|
|
if (observer) observer.disconnect();
|
|
observer = new MutationObserver(function () {
|
|
var current = countMsgs();
|
|
var diff = current - lastCount;
|
|
lastCount = current;
|
|
if (diff <= 0) return;
|
|
if (isAtBottom) { scrollBottom(); }
|
|
else { newMsgCount += diff; updateBadge(); }
|
|
});
|
|
observer.observe(msgsEl, { childList: true });
|
|
|
|
var btn = document.getElementById('new-msg-badge-btn');
|
|
if (btn && !btn._bound) {
|
|
btn._bound = true;
|
|
btn.addEventListener('click', function () {
|
|
isAtBottom = true; newMsgCount = 0;
|
|
msgsEl.scrollTo({ top: msgsEl.scrollHeight, behavior: 'smooth' });
|
|
updateBadge();
|
|
});
|
|
}
|
|
|
|
scrollBottom();
|
|
}
|
|
|
|
/* Ajustar altura al teclado virtual (una sola vez) */
|
|
function initViewport() {
|
|
if (vpInited || !window.visualViewport) return;
|
|
vpInited = true;
|
|
var root = document.getElementById('chat-root');
|
|
if (!root) return;
|
|
function update() {
|
|
if (window.innerWidth < 640) {
|
|
root.style.height = window.visualViewport.height + 'px';
|
|
}
|
|
}
|
|
window.visualViewport.addEventListener('resize', update);
|
|
update();
|
|
}
|
|
|
|
/* Bajar al fondo cuando el componente emite scroll-chat */
|
|
window.addEventListener('scroll-chat', function () {
|
|
isAtBottom = true; newMsgCount = 0; updateBadge(); scrollBottom();
|
|
});
|
|
|
|
document.addEventListener('DOMContentLoaded', function () { init(); initViewport(); });
|
|
|
|
/* livewire:load: Livewire terminó de arrancar — re-init por si el DOM cambió */
|
|
document.addEventListener('livewire:load', function () {
|
|
init();
|
|
initViewport();
|
|
/* Usar hook oficial para scroll después de cada update */
|
|
Livewire.hook('message.processed', function () {
|
|
if (isAtBottom) scrollBottom();
|
|
});
|
|
});
|
|
})();
|
|
</script>
|
|
</body>
|
|
</html>
|