jQuery(document).ready(function ($) {
// Top Search Bar Opening/Closing
$('.open-top-bar-search').on('click', function() {
$(this).hide();
$('.close-top-bar-search').show();
$('.top-search-bar-container').addClass('opened');
});
$('.close-top-bar-search').on('click', function () {
$(this).hide();
$('.open-top-bar-search').show();
$('.top-search-bar-container').removeClass('opened');
});
// Blog cards size equalizer
function equalizeArticleCardsHeights() {
if(php_vars.enable_posts_height_equalizer) {
$('.articles-list .row').each(function (index) {
if ($(this).css('display') == "inline") {
$('.article-card-container .article-meta').css('height', 'auto');
} else {
var max_height = 0;
$(this).find('.article-card-container').each(function () {
var height = $(this).find('.article-meta').outerHeight();
if (height > max_height) {
max_height = height;
}
});
$(this).find('.article-card-container').find('.article-meta').css('height', max_height + 'px')
}
});
}
}
equalizeArticleCardsHeights();
// Rewrite Search Widget
$('.widget_search .search-field').attr('type', 'text');
$('.widget_search .search-submit').remove();
$('.widget_search .search-form').append('');
// Rewrite Meow Search Block
$('.mwt-search .mwt-search').attr('type', 'text');
$('.mwt-search .search-submit').remove();
$('.mwt-search form.search-form').append('');
// Mobile Navigation Init
$('.mobile-navigation').css('margin-top', - $('.mobile-navigation').outerHeight() + 'px')
// Mobile Navigation Toggle
$('.mobile-navigation-toggle').on('click', function() {
if($(this).hasClass('active')) {
$('.mobile-navigation').animate({ marginTop: - $('.mobile-navigation').outerHeight() + 'px'}, 200);
$(this).removeClass('active')
} else {
$('.mobile-navigation').animate({ marginTop: 0 }, 200);
$(this).addClass('active')
}
})
// On window resize
var resizeTimer
$(window).on('resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function () {
$('.article-card-container .article-meta').css('height', 'auto');
equalizeArticleCardsHeights();
}, 250);
})
// On infinite scroll loading more posts
$(document.body).on('post-load', function () {
equalizeArticleCardsHeights();
});
// Scroll back to top button
if ($('.scroll-back-to-top-btn').length > -1) {
$(window).on('scroll', function() {
var scrollTop = $(this).scrollTop();
if(scrollTop > 100) {
$('.scroll-back-to-top-btn').addClass('visible');
}
if(scrollTop <= 100) {
$('.scroll-back-to-top-btn').removeClass('visible');
}
});
$('.scroll-back-to-top-btn').on('click', function() {
$("html, body").animate({ scrollTop: 0 }, 300);
})
}
});