Andrei | рефакторинг проекта (почистил front-page.js от лишних скриптов и перенес их в другие файлы)

dev_10_refactoring
parent 4e784ded94
commit 5e1aa66dce
  1. 8
      wp-content/themes/cosmopet/modules/header/module-controller.php
  2. 3
      wp-content/themes/cosmopet/modules/layout/module-controller.php
  3. 180
      wp-content/themes/cosmopet/static/js/front-page.js
  4. 9
      wp-content/themes/cosmopet/static/js/header.js
  5. 12
      wp-content/themes/cosmopet/static/js/script.js

@ -1,4 +1,10 @@
<?php <?php
function header_enqueue_scripts() {
wp_enqueue_script( 'gp-header-script', get_template_directory_uri() . '/static/js/header.js', array(), null, true );
}
add_action('wp_enqueue_scripts', 'header_enqueue_scripts');
function is_home_page_posts_archive() { function is_home_page_posts_archive() {
// 1. Если главная страница - это страница записей // 1. Если главная страница - это страница записей
if (get_option('show_on_front') == 'posts') { if (get_option('show_on_front') == 'posts') {
@ -76,4 +82,6 @@ add_filter('timber/context', function($context) {
return $context; return $context;
}); });
?> ?>

@ -1,9 +1,8 @@
<?php <?php
function global_enqueue_scripts() { function global_enqueue_scripts() {
wp_enqueue_style('gp-global-style', get_template_directory_uri() . '/static/css/style.css'); wp_enqueue_style('gp-global-style', get_template_directory_uri() . '/static/css/style.css');
wp_enqueue_script( 'gp-global-script', get_template_directory_uri() . '/static/js/script.js', array(), null, true );
} }
add_action('wp_enqueue_scripts', 'global_enqueue_scripts'); add_action('wp_enqueue_scripts', 'global_enqueue_scripts');

@ -1,185 +1,6 @@
// Scroll for <a href="#{targer_id}"> by class "scroll_link"
const smoothLinks = document.querySelectorAll('.scroll_link');
for (let smoothLink of smoothLinks) {
smoothLink.addEventListener('click', function (e) {
e.preventDefault();
const id = smoothLink.getAttribute('href');
document.querySelector(id).scrollIntoView({
behavior: 'smooth',
block: 'start'
});
});
};
// Header menu
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
let body = document.querySelector('body');
let header = document.querySelector('.header');
jQuery('.header-lang').on('click', function(){
jQuery(this).find('ul').toggle()
})
/* Здесь было открытие/закрытие моб.меню */
// let headerBars = document.querySelector('.header_bars');
// let headerClose = document.querySelector('.header_close');
// jQuery(".header_bars").on('click', function(){jQuery('.header_navs').toggleClass('active')})
// headerBars.addEventListener('click', function () {
// header.classList.add('mobile-open');
// body.classList.add('no-scroll');
// });
// function removeActiveClass() {
// header.classList.remove('mobile-open');
// body.classList.remove('no-scroll');
// }
// headerClose.addEventListener('click', removeActiveClass);
jQuery(".header_bars").on('click', function(){jQuery('.header_navs').toggleClass('active')})
/* start: aboutSlider */
// var slider = carousel_init();
// function carousel_init() {
// var carousel = document.querySelectorAll('.carousel');
// if (window.innerWidth > 421) {
// var options = {
// numVisible: 5,
// // indicators: true,
// }
// } else if (window.innerWidth < 421) {
// var options = {
// numVisible: 3,
// // indicators: true,
// }
// }
// var instances = M.Carousel.init(carousel, options);
// document.querySelectorAll('.about_slider_nav').forEach(btn => {
// btn.addEventListener('click', function (e) {
// // window.t = e.target.closest('button')
// // console.log(t)
// if (e.target.closest('button').classList.contains('next')) {
// instances[0].next();
// }else{
// instances[0].prev();
// }
// });
// });
// return instances;
// }
/* GP | Start: Анимация в блоке "Отзывы ветеринаров" */
// const reviewsItems = jQuery('.reviews_item')
// setInterval(() => {
// if (jQuery(reviewsItems[0]).is(':visible')) {
// jQuery(reviewsItems[0]).hide()
// jQuery(reviewsItems[1]).show()
// } else {
// jQuery(reviewsItems[0]).show()
// jQuery(reviewsItems[1]).hide()
// }
// setTimeout(() => {
// if (jQuery(reviewsItems[2]).is(':visible')) {
// jQuery(reviewsItems[2]).hide()
// jQuery(reviewsItems[3]).show()
// } else {
// jQuery(reviewsItems[2]).show()
// jQuery(reviewsItems[3]).hide()
// }
// }, 3000);
// setTimeout(() => {
// if (jQuery(reviewsItems[4]).is(':visible')) {
// jQuery(reviewsItems[4]).hide()
// jQuery(reviewsItems[5]).show()
// } else {
// jQuery(reviewsItems[4]).show()
// jQuery(reviewsItems[5]).hide()
// }
// }, 6000);
// }, 9000);
/* GP | End: Анимация в блоке "Отзывы ветеринаров" */
/* GP | Start: blogosphere__swiper */
// function carousel_init_new() {
// const carousel = document.querySelector('.blogosphere__swiper');
// let options = {}; // Переменная для хранения текущих параметров
// // Функция для обновления настроек в зависимости от размера экрана
// function setOptions() {
// if (window.innerWidth > 421) {
// options = {
// numVisible: 5,
// onCycleTo: (el) => {
// const slides = carousel.querySelectorAll('.carousel-item');
// slides.forEach((slide) => {
// const video = slide.querySelector('video');
// if (video) {
// video.pause();
// }
// });
// }
// };
// } else {
// options = {
// numVisible: 3,
// };
// }
// }
// // Инициализация карусели с текущими параметрами
// function initCarousel() {
// setOptions(); // Устанавливаем параметры при инициализации
// M.Carousel.init(carousel, options); // Инициализация карусели с новыми параметрами
// }
// // Инициализация карусели при загрузке страницы
// initCarousel();
// // Обновляем карусель при изменении размера окна
// window.addEventListener('resize', function () {
// // Уничтожаем старую карусель и создаем новую с обновленными параметрами
// if (carousel) {
// carousel.M_Carousel.destroy();
// }
// initCarousel();
// });
// // Прямое добавление обработчиков на кнопки
// const nextBtn = document.querySelector('.blogosphere__btn.next');
// const prevBtn = document.querySelector('.blogosphere__btn.prev');
// if (nextBtn && prevBtn) {
// nextBtn.addEventListener('click', (e) => {
// e.preventDefault();
// e.stopPropagation();
// if (carousel) {
// carousel.M_Carousel.next();
// }
// });
// prevBtn.addEventListener('click', (e) => {
// e.preventDefault();
// e.stopPropagation();
// if (carousel) {
// carousel.M_Carousel.prev();
// }
// });
// }
// }
// // Инициализация карусели
// carousel_init_new();
/* GP | End: */
let home = new Swiper(".home__swiper ", { let home = new Swiper(".home__swiper ", {
slidesPerView: 1, slidesPerView: 1,
spaceBetween: 1000, spaceBetween: 1000,
@ -439,7 +260,6 @@ document.addEventListener('DOMContentLoaded', function () {
}) })
}); });
document.addEventListener('DOMContentLoaded', function () { document.addEventListener('DOMContentLoaded', function () {
const sliders = document.querySelectorAll('.reviews_item-swiper'); const sliders = document.querySelectorAll('.reviews_item-swiper');
sliders.forEach((slider, index) => { sliders.forEach((slider, index) => {

@ -0,0 +1,9 @@
document.addEventListener('DOMContentLoaded', function () {
let body = document.querySelector('body');
let header = document.querySelector('.header');
jQuery('.header-lang').on('click', function(){
jQuery(this).find('ul').toggle()
})
jQuery(".header_bars").on('click', function(){jQuery('.header_navs').toggleClass('active')})
})

@ -0,0 +1,12 @@
const smoothLinks = document.querySelectorAll('.scroll_link');
for (let smoothLink of smoothLinks) {
smoothLink.addEventListener('click', function (e) {
e.preventDefault();
const id = smoothLink.getAttribute('href');
document.querySelector(id).scrollIntoView({
behavior: 'smooth',
block: 'start'
});
});
};
Loading…
Cancel
Save