{% block javascripts %}
{{ encore_entry_script_tags('app') }}
<script src="{{ asset('assets/front/js/bootstrap.bundle.js') }}"></script>
{# <script src="{{ asset('assets/front/js/bootstrap.js') }}"></script>#}
<script src="https://cdn.jsdelivr.net/npm/jquery@3.4.1/dist/jquery.min.js"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/trumbowyg.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/langs/fr.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/plugins/emoji/trumbowyg.emoji.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/emoji/trumbowyg.emoji.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/fontsize/trumbowyg.fontsize.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/history/trumbowyg.history.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/indent/trumbowyg.indent.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/insertaudio/trumbowyg.insertaudio.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/lineheight/trumbowyg.lineheight.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/noembed/trumbowyg.noembed.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/upload/trumbowyg.upload.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/cleanpaste/trumbowyg.cleanpaste.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/pasteimage/trumbowyg.pasteimage.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/pasteembed/trumbowyg.pasteembed.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/fontfamily/trumbowyg.fontfamily.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/trumbowyg-main/dist/plugins/colors/trumbowyg.colors.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/owlcarousel/dist/owl.carousel.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/bootstrap-datetimepicker/js/bootstrap-datepicker.js') }}"></script>
<script src="{{ asset('assets/front/vendor/jquery-mousewheel/jquery.mousewheel.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/select2/dist/js/select2.full.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/select2/dist/js/i18n/fr.js') }}"></script>
<script src="{{ asset('assets/front/vendor/datetimepicker/build/jquery.datetimepicker.full.min.js') }}"></script>
<script src="{{ asset('assets/front/init/init-owl-carousel.js') }}"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>
{# <script src="{{ asset('assets/front/init/contact.js') }}"></script> #}
<script src="{{ asset('assets/front/vendor/jquery-ui/jquery-ui.js') }}"></script>
<!--<script src="{{ asset('assets/front/vendor/aos/aos.js') }}"></script>
<script>
AOS.init();
</script>-->
<script src="{{ asset('assets/front/vendor/cropperjs/dist/cropper.js') }}"></script>
<script src="{{ asset('assets/front/vendor/jquery-cropper/dist/jquery-cropper.js') }}"></script>
<script src="{{ asset('assets/front/vendor/video-js/video.min.js') }}"></script>
<script src="{{ asset('assets/front/vendor/wizard.js') }}"></script>
{# <script src="https://cdn.jsdelivr.net/gh/AdrianVillamayor/Wizard-JS@1.8/src/wizard.min.js" integrity="sha256-vVk0T+7qGD5K2sLJywOcqKmnJerAFRaOI1FWJNH3YYg=" crossorigin="anonymous"></script>#}
<script src="{{ asset('assets/front/init/flatpickr.js') }}"></script>
<script src="{{ asset('assets/front/vendor/jquery.mousedirection.js') }}"></script>
{# <script src="{{ asset('assets/front/init/countDown.js') }}"></script> #}
<script src="{{ asset('assets/front/vendor/fullcalendar/dist/index.global.js') }}"></script>
<script src="{{ asset('assets/front/vendor/color-thief/dist/color-thief.umd.js') }}"></script>
<script src="{{ asset('assets/front/vendor/evento/evo-calendar/js/evo-calendar.js') }}"></script>
{# <script src="https://cdn.jsdelivr.net/npm/evo-calendar@1.1.2/evo-calendar/js/evo-calendar.min.js"></script>#}
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="{{ asset('assets/front/vendor/eventjs/dist/jquery.bs.calendar.js') }}"></script>
<script src="{{ asset('assets/front/js/pdf.js') }}"></script>
<script src="{{ asset('assets/front/vendor/jquery-toaster/jquery.toaster.js') }}"></script>
<script src="{{ asset('assets/front/vendor/tel-input/build/js/intlTelInput-jquery.js') }}"></script>
<script src="https://unpkg.com/dropzone@5/dist/min/dropzone.min.js"></script>
<script type="module" >
import { initializeApp } from 'https://www.gstatic.com/firebasejs/9.23.0/firebase-app.js'
import { getMessaging, getToken, onMessage, deleteToken } from 'https://www.gstatic.com/firebasejs/9.23.0/firebase-messaging.js'
const originalFetch = window.fetch;
window.responseInterceptor = async (response) => {
if (response.url.includes("/config/firebase")) {
console.log("interceptor")
if (response.ok) {
{% if app.request.cookies.get('firebase_config_iv') and app.request.cookies.get('firebase_config_data') %}
{% set decryptedData = decrypt(app.request.cookies.get('firebase_config_iv'), app.request.cookies.get('firebase_config_data')) %}
const decryptedData = '{{ decryptedData }}'
const jsonString = decryptedData.replace(/"/g, '"')
response.json = async () => JSON.parse(jsonString);
{% endif %}
}
console.log("end of interceptor")
}
return response;
}
window.fetch = async (...args) => {
let response = await originalFetch(...args);
response = await responseInterceptor(response); // Await here ensures the interception completes
return response;
};
async function fetchFirebaseConfigRequest() {
const response = await window.fetch('/config/firebase');
if (!response.ok) {
throw new Error('Failed to fetch configuration');
}
return await response.json();
}
const firebaseResponse = await fetchFirebaseConfigRequest();
const firebaseConfig = {
apiKey: firebaseResponse.apiKey,
authDomain: firebaseResponse.authDomain,
projectId: firebaseResponse.projectId,
storageBucket: firebaseResponse.storageBucket,
messagingSenderId: firebaseResponse.messagingSenderId,
appId: firebaseResponse.appId,
measurementId: firebaseResponse.measurementId
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const vapidKey = firebaseResponse.vapidKey;
let messaging = getMessaging(app);
function deleteFirebaseToken() {
deleteToken(messaging, { vapidKey: vapidKey }).then(() => {
console.log('Token deleted.');
}).catch((err) => {
console.log('Unable to delete token. ', err);
});
}
onMessage(messaging, (payload) => {
console.log('Message received. ', payload);
});
Notification.requestPermission().then((permission) => {
if (permission === 'granted') {
console.log('Notification permission granted.');
} else {
console.log('Unable to get permission to notify.');
}
});
async function getOrRegisterServiceWorker(){
if ('serviceWorker' in navigator) {
const serviceWorker = await window.navigator.serviceWorker
.getRegistration('/firebase-cofina-notification-scope');
if (serviceWorker) return serviceWorker;
return window.navigator.serviceWorker.register('/firebase-messaging-sw.js', {
scope: '/firebase-cofina-notification-scope',
});
}
throw new Error('The browser doesn`t support service worker.');
}
function registerFirebaseToken(token){
const firebaseToken = localStorage.getItem("firebaseToken")
const firebaseTokenIsUsed = localStorage.getItem("firebaseTokenIsUsed")
if(firebaseTokenIsUsed !== undefined && firebaseTokenIsUsed && firebaseToken !== undefined &&firebaseToken == token){
console.log("Cofina Notifications")
}else{
localStorage.setItem("firebaseToken", token)
localStorage.setItem("firebaseTokenIsUsed", false)
}
}
getOrRegisterServiceWorker().then(serviceWorkerRegistration => {
getToken(messaging, { vapidKey: vapidKey, serviceWorkerRegistration }).then((currentToken) => {
if (currentToken) {
registerFirebaseToken(currentToken)
} else {
console.log('No registration token available. Request permission to generate one.');
}
}).catch((err) => {
console.log('An error occurred while retrieving token. ', err);
});
})
</script>
<script src="{{ asset('assets/front/init/main.js') }}"></script>
{# <script src="{{ asset('assets/front/init/profileButton.js') }}"></script> #}
{% endblock %}