174 lines
5.6 KiB
JavaScript
174 lines
5.6 KiB
JavaScript
jQuery(document).ready(function($) {
|
|
|
|
"use strict";
|
|
|
|
/**
|
|
* Sophia After Dark Preloader
|
|
*/
|
|
if ($('#preloader-background').length) {
|
|
setTimeout(function() {
|
|
$('#preloader-background').hide();
|
|
}, 600);
|
|
}
|
|
|
|
/**
|
|
* Masonry grid initialization
|
|
*/
|
|
const grid = document.querySelector('.sophia-after-dark-content-masonry');
|
|
if (grid && typeof Masonry !== 'undefined' && typeof imagesLoaded !== 'undefined') {
|
|
imagesLoaded(grid, function() {
|
|
new Masonry(grid, {
|
|
itemSelector: '.hentry'
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Header Search script
|
|
*/
|
|
const $searchIcon = $('.sad-menu-search .sad-search-icon');
|
|
$searchIcon.click(function() {
|
|
$('.sad-form-wrap').toggleClass('search-activate').find('.search-field').focus();
|
|
const $element = $('.sad-form-wrap.search-activate');
|
|
if ($element.length) {
|
|
$(document).on('keydown', function(e) {
|
|
const focusable = $element.find('input, button, [href], select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
const firstFocusable = focusable[0];
|
|
const lastFocusable = focusable[focusable.length - 1];
|
|
sophia_after_dark_focus_trap(firstFocusable, lastFocusable, e);
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Focus trap in popup.
|
|
*/
|
|
const KEYCODE_TAB = 9;
|
|
|
|
function sophia_after_dark_focus_trap(firstFocusable, lastFocusable, e) {
|
|
if (e.key === 'Tab' || e.keyCode === KEYCODE_TAB) {
|
|
if (e.shiftKey && document.activeElement === firstFocusable) {
|
|
lastFocusable.focus();
|
|
e.preventDefault();
|
|
} else if (!e.shiftKey && document.activeElement === lastFocusable) {
|
|
firstFocusable.focus();
|
|
e.preventDefault();
|
|
}
|
|
}
|
|
}
|
|
|
|
$('.sad-form-wrap .sad-form-close').click(function() {
|
|
$('.sad-form-wrap').toggleClass('search-activate');
|
|
$(this).parents('.sad-menu-search').find('.sad-search-icon a').focus();
|
|
});
|
|
|
|
/**
|
|
* Close popups on escape key.
|
|
*/
|
|
$(document).on('keydown', function(event) {
|
|
if (event.keyCode === 27) {
|
|
event.preventDefault();
|
|
$('.sad-menu-search .sad-form-wrap').removeClass('search-activate');
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Settings about WOW animation
|
|
*/
|
|
if (sophia_after_darkObject.wow_effect === 'on') {
|
|
new WOW().init();
|
|
}
|
|
|
|
/**
|
|
* Settings about sticky menu
|
|
*/
|
|
if (sophia_after_darkObject.menu_sticky === 'on') {
|
|
const wpAdminBar = $('#wpadminbar').length ? $('#wpadminbar') : 0;
|
|
$(".sad-social-menu-wrapper").sticky({
|
|
topSpacing: wpAdminBar.length ? wpAdminBar.height() : 0
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Scroll To Top
|
|
*/
|
|
$(window).scroll(function() {
|
|
if ($(this).scrollTop() > 1000) {
|
|
$('#sad-scrollup').fadeIn('slow');
|
|
} else {
|
|
$('#sad-scrollup').fadeOut('slow');
|
|
}
|
|
});
|
|
|
|
$('#sad-scrollup').click(function() {
|
|
$("html, body").animate({
|
|
scrollTop: 0
|
|
}, 600);
|
|
return false;
|
|
});
|
|
|
|
/**
|
|
* Slider scripts
|
|
*/
|
|
function initializeSlider(selector, rtl = true) {
|
|
$(selector).lightSlider({
|
|
pager: false,
|
|
auto: false,
|
|
loop: true,
|
|
item: 1,
|
|
controls: true,
|
|
slideMargin: 0,
|
|
rtl: rtl,
|
|
nextHtml: '<span class="icon-prev"><i class="fa fa-angle-left"></i></span>',
|
|
prevHtml: '<span class="icon-next"><i class="fa fa-angle-right"></i></span>',
|
|
onSliderLoad: function() {
|
|
$(selector).removeClass('cS-hidden');
|
|
}
|
|
});
|
|
}
|
|
|
|
initializeSlider('.front-slider');
|
|
initializeSlider('.sad-gallery-slider', false);
|
|
|
|
/**
|
|
* Responsive menu
|
|
*/
|
|
$('.sad-social-menu-wrapper .menu-toggle').click(function() {
|
|
$('#site-navigation').toggleClass('isActive').slideToggle('slow');
|
|
const $element = $('.sad-header-menu-wrap');
|
|
if ($element.length) {
|
|
$(document).on('keydown', function(e) {
|
|
if ($('#site-navigation.isActive').length) {
|
|
const focusable = $element.find('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
|
|
const firstFocusable = focusable[0];
|
|
const lastFocusable = focusable[focusable.length - 1];
|
|
sophia_after_dark_focus_trap(firstFocusable, lastFocusable, e);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Responsive sub menu toggle
|
|
*/
|
|
$('<a href="javascript:void(0);" class="sub-toggle"><i class="fa fa-angle-right"></i></a>').insertAfter('#site-navigation .menu-item-has-children>a, #site-navigation .page_item_has_children>a');
|
|
|
|
$('#site-navigation .sub-toggle').click(function() {
|
|
$(this).parent('.menu-item-has-children').children('ul.sub-menu').first().slideToggle(1000);
|
|
$(this).parent('.page_item_has_children').children('ul.children').first().slideToggle(1000);
|
|
$(this).children('.fa-angle-right').first().toggleClass('fa-angle-down');
|
|
});
|
|
|
|
/**
|
|
* Slider Section dynamic height script
|
|
*/
|
|
$(window).on('load', function() {
|
|
if ($(window).width() > 839) {
|
|
$(".front-slider-wrapper").each(function() {
|
|
const imageHeight = $(this).height();
|
|
$(this).find(".slider-post-wrap, .front-slider").css('height', imageHeight);
|
|
});
|
|
}
|
|
});
|
|
|
|
}); |