document.addEventListener( DOMContentLoaded , function(event) { // Функція запуску галереї function initNeobluGallery() { $('.neoblu-lookbook-wrapper').magnificPopup({ delegate: 'a.img_popup', type: 'image', gallery: { enabled: true, navigateByImgClick: true, preload: [0,1], tPrev: 'Попереднє', tNext: 'Наступне', tCounter: '%curr% з %total%' }, mainClass: 'mfp-with-zoom', zoom: { enabled: true, duration: 300, easing: 'ease-in-out' } }); } // Перевіряємо та довантажуємо бібліотеки var checkLibs = setInterval(function () { if (typeof jQuery !== 'undefined') { clearInterval(checkLibs); // Перевіряємо, чи підключений Magnific Popup if (typeof jQuery.fn.magnificPopup === 'undefined') { console.log('Magnific Popup не знайдено. Завантажуємо...'); // 1. Додаємо CSS стилі var cssLink = document.createElement( link ); cssLink.rel = stylesheet ; cssLink.href = https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css ; document.head.appendChild(cssLink); // 2. Додаємо JS скрипт var script = document.createElement('script'); script.src = 'https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js'; script.onload = function () { // Коли завантажилось - запускаємо initNeobluGallery(); }; document.head.appendChild(script); } else { // Якщо вже є - просто запускаємо initNeobluGallery(); } } }, 100); });