layout.js: añade favicon dinámico (icono del logo en la pestaña)
This commit is contained in:
60
js/layout.js
60
js/layout.js
@@ -1,39 +1,45 @@
|
|||||||
/* ...
|
/* ...
|
||||||
AQUÍ ARRIBA ESTÁ TODO TU CÓDIGO ORIGINAL DEL LAYOUT
|
AQUÍ ARRIBA ESTÁ TODO TU CÓDIGO ORIGINAL DEL LAYOUT
|
||||||
(El que dibuja el sidebar, el header, el menú, etc.)
|
(El que dibuja el sidebar, el header, el menú, etc.)
|
||||||
... */
|
... */
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 🎨 INYECTOR DE LOGO CORPORATIVO Y PWA (ICONOS APP)
|
// 🎨 INYECTOR DE LOGO CORPORATIVO Y PWA (ICONOS APP)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|
||||||
// 1. INYECCIÓN SÚPER RÁPIDA (Para engañar a los iPhone 🍏)
|
// Crea (o reutiliza) un <link> de icono en el <head> y le pone la URL indicada
|
||||||
|
function setIconLink(rel, href) {
|
||||||
|
let link = document.querySelector(`link[rel='${rel}']`);
|
||||||
|
if (!link) {
|
||||||
|
link = document.createElement('link');
|
||||||
|
link.rel = rel;
|
||||||
|
document.head.appendChild(link);
|
||||||
|
}
|
||||||
|
link.href = href;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. INYECCIÓN SÚPER RÁPIDA (Para engañar a los iPhone 🍏 y pintar ya la pestaña del navegador)
|
||||||
// Miramos si ya tenemos el logo guardado en la memoria del móvil
|
// Miramos si ya tenemos el logo guardado en la memoria del móvil
|
||||||
const savedLogo = localStorage.getItem("company_logo");
|
const savedLogo = localStorage.getItem("company_logo");
|
||||||
if (savedLogo) {
|
if (savedLogo) {
|
||||||
let appleIcon = document.querySelector("link[rel='apple-touch-icon']");
|
setIconLink('apple-touch-icon', savedLogo);
|
||||||
if (!appleIcon) {
|
setIconLink('icon', savedLogo);
|
||||||
appleIcon = document.createElement('link');
|
|
||||||
appleIcon.rel = 'apple-touch-icon';
|
|
||||||
document.head.appendChild(appleIcon);
|
|
||||||
}
|
|
||||||
appleIcon.href = savedLogo;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. DESCARGA DESDE EL SERVIDOR Y CABECERA
|
// 2. DESCARGA DESDE EL SERVIDOR Y CABECERA
|
||||||
setTimeout(async () => {
|
setTimeout(async () => {
|
||||||
if (!localStorage.getItem("token")) return;
|
if (!localStorage.getItem("token")) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
const TRACK_API = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1'
|
||||||
? 'http://localhost:3000'
|
? 'http://localhost:3000'
|
||||||
: 'https://integrarepara-api.integrarepara.es';
|
: 'https://integrarepara-api.integrarepara.es';
|
||||||
|
|
||||||
const res = await fetch(`${TRACK_API}/config/company`, {
|
const res = await fetch(`${TRACK_API}/config/company`, {
|
||||||
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
|
||||||
});
|
});
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
if (data.ok && data.config && data.config.company_logo) {
|
if (data.ok && data.config && data.config.company_logo) {
|
||||||
const logoUrl = data.config.company_logo;
|
const logoUrl = data.config.company_logo;
|
||||||
|
|
||||||
@@ -44,29 +50,25 @@ setTimeout(async () => {
|
|||||||
const headerIcon = document.querySelector('header .w-10.h-10.rounded-xl, #header-container .w-10.h-10');
|
const headerIcon = document.querySelector('header .w-10.h-10.rounded-xl, #header-container .w-10.h-10');
|
||||||
if (headerIcon) {
|
if (headerIcon) {
|
||||||
headerIcon.innerHTML = '';
|
headerIcon.innerHTML = '';
|
||||||
headerIcon.className = "w-10 h-10 flex shrink-0 items-center justify-center";
|
headerIcon.className = "w-10 h-10 flex shrink-0 items-center justify-center";
|
||||||
headerIcon.style.background = "transparent";
|
headerIcon.style.background = "transparent";
|
||||||
headerIcon.style.boxShadow = "none";
|
headerIcon.style.boxShadow = "none";
|
||||||
|
|
||||||
const img = document.createElement('img');
|
const img = document.createElement('img');
|
||||||
img.src = logoUrl;
|
img.src = logoUrl;
|
||||||
img.className = "max-w-full max-h-full object-contain drop-shadow-sm";
|
img.className = "max-w-full max-h-full object-contain drop-shadow-sm";
|
||||||
headerIcon.appendChild(img);
|
headerIcon.appendChild(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inyectamos el icono por si es la primera vez que entra
|
// Icono de la pestaña del navegador / favicon
|
||||||
let appleIcon = document.querySelector("link[rel='apple-touch-icon']");
|
setIconLink('icon', logoUrl);
|
||||||
if (!appleIcon) {
|
// Icono al añadir la app a la pantalla de inicio (iOS)
|
||||||
appleIcon = document.createElement('link');
|
setIconLink('apple-touch-icon', logoUrl);
|
||||||
appleIcon.rel = 'apple-touch-icon';
|
|
||||||
document.head.appendChild(appleIcon);
|
|
||||||
}
|
|
||||||
appleIcon.href = logoUrl;
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("No se pudo cargar la configuración visual de la empresa", e);
|
console.error("No se pudo cargar la configuración visual de la empresa", e);
|
||||||
}
|
}
|
||||||
}, 100);
|
}, 100);
|
||||||
|
|
||||||
// 🛑 RASTREADOR FANTASMA GPS (MODO DE CAMINO) DESACTIVADO TEMPORALMENTE 🛑
|
// 🛑 RASTREADOR FANTASMA GPS (MODO DE CAMINO) DESACTIVADO TEMPORALMENTE 🛑
|
||||||
// (Por petición del desarrollador, se ha eliminado el bloque setInterval del GPS)
|
// (Por petición del desarrollador, se ha eliminado el bloque setInterval del GPS)
|
||||||
|
|||||||
Reference in New Issue
Block a user