csdsolutions-csdjs
Version:
Libreria per i progetti di CSD Solutions
57 lines (50 loc) • 1.88 kB
JavaScript
/**
* SSR-Safe Utility per csdsolutions-csdjs
* Questo file fornisce funzioni sicure per l'ambiente SSR
*/
// Wrapper per $CSD in ambiente SSR
const createSsrSafe$CSD = () => {
// In ambiente SSR, restituisce un oggetto fittizio che non fa nulla
const ssrSafe$CSD = function() {
return {
elements: [],
length: 0,
each: function() { return this; },
find: function() { return this; },
addClass: function() { return this; },
removeClass: function() { return this; },
toggleClass: function() { return this; },
hasClass: function() { return false; },
attr: function() { return this; },
removeAttr: function() { return this; },
data: function() { return this; },
css: function() { return this; },
html: function() { return ""; },
text: function() { return ""; },
append: function() { return this; },
prepend: function() { return this; },
on: function() { return this; },
off: function() { return this; },
closest: function() { return this; },
is: function() { return false; }
};
};
// Aggiunge metodi statici
ssrSafe$CSD.ready = function(callback) { /* noop */ };
ssrSafe$CSD.extend = function() { return {}; };
ssrSafe$CSD.each = function() { return null; };
return ssrSafe$CSD;
};
// Esporta una versione sicura per SSR di $CSD
let globalSafe$CSD;
if (typeof window === 'undefined') {
// Ambiente SSR: usa la versione safe
globalSafe$CSD = createSsrSafe$CSD();
} else {
// Ambiente Browser: usa la versione reale se disponibile o crea un placeholder
// che sarà sostituito dalla versione reale quando verrà caricata
globalSafe$CSD = typeof $CSD !== 'undefined' ? $CSD : createSsrSafe$CSD();
}
// Esporta per uso nei moduli che dipendono da $CSD
export const $CSD = globalSafe$CSD;
export default globalSafe$CSD;