/** * GalleryFeed JavaScript - для getcourse.ru * * Как использовать: * 1. Подключите этот файл на странице: * 2. Вызовите функцию initGalleryFeed() после загрузки DOM */ function initGalleryFeed(selector, options = {}) { const containers = document.querySelectorAll(selector || '.gallery-feed'); containers.forEach(container => { const works = options.works || JSON.parse(container.getAttribute('data-works') || '[]'); const header = options.header || container.getAttribute('data-header') || ''; if (works.length === 0) { console.warn('GalleryFeed: Нет изображений для отображения'); return; } // Определяем класс грида в зависимости от количества элементов let gridClass = 'grid-4plus'; if (works.length === 1) { gridClass = 'grid-1'; } else if (works.length === 2) { gridClass = 'grid-2'; } else if (works.length === 3) { gridClass = 'grid-3'; } // Создаем HTML let html = ''; container.innerHTML = html; }); } // Автоматическая инициализация при загрузке страницы if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', function() { initGalleryFeed('.gallery-feed'); }); } else { initGalleryFeed('.gallery-feed'); } // Экспорт для использования в других скриптах if (typeof module !== 'undefined' && module.exports) { module.exports = { initGalleryFeed }; }