jQuery(document).ready(function($) {
// Responsive Menu
$('.menu-toggle').click(function() {
$(this).toggleClass('active');
$(this).parent().find('ul.nav-menu').slideToggle();
$(this).parent().find('div.nav-menu > ul').slideToggle();
});
$('.dropdown-toggle').click(function() {
$(this).toggleClass('active');
$(this).parent().find('.sub-menu').first().slideToggle();
$(this).parent().find('.children').first().slideToggle();
});
if( $(window).width() < 1024 ) {
$('#site-navigation .nav-menu').find("li").last().bind( 'keydown', function(e) {
if( !e.shiftKey && e.which === 9 ) {
e.preventDefault();
$('.site-header').find('.menu-toggle').focus();
}
});
}
else {
$('#site-navigation .nav-menu').find("li").unbind('keydown');
}
$(window).resize(function() {
if( $(window).width() < 1024 ) {
$('#site-navigation .nav-menu').find("li").last().bind( 'keydown', function(e) {
if( !e.shiftKey && e.which === 9 ) {
e.preventDefault();
$('.site-header').find('.menu-toggle').focus();
}
});
}
else {
$('#site-navigation .nav-menu').find("li").unbind('keydown');
}
});
$('.menu-toggle').on('keydown', function (e) {
var tabKey = e.keyCode === 9;
var shiftKey = e.shiftKey;
if( $('.menu-toggle').hasClass('active') ) {
if ( shiftKey && tabKey ) {
e.preventDefault();
$('#site-navigation .nav-menu').find("li:last-child > a").focus();
$('#site-navigation .nav-menu').find("li").last().bind( 'keydown', function(e) {
if( !e.shiftKey && e.which === 9 ) {
e.preventDefault();
$('.site-header').find('.menu-toggle').focus();
}
});
}
}
});
// Adds a search icon.
$('.search-form input[type="submit"]').replaceWith('');
// Sets scroll to top.
var scroll = $(window).scrollTop();
var scrollup = $('.to-top');
$(window).scroll(function() {
if ($(this).scrollTop() > 1) {
scrollup.css({bottom:"25px"});
}
else {
scrollup.css({bottom:"-100px"});
}
});
scrollup.click(function() {
$('html, body').animate({scrollTop: '0px'}, 800);
return false;
});
});
jQuery(document).ready(function() {
jQuery(".homepage-temp h2").each(function() {
var t = jQuery(this).text();
var splitT = t.split(" ");
var totalWords = splitT.length;
// If there are fewer than 2 words, do nothing
if (totalWords < 2) return;
// Calculate the index of the first word to style
var startIndex = totalWords - 2;
var newText = "";
// Iterate over the words
for (var i = 0; i < splitT.length; i++) {
if (i === startIndex) {
newText += "";
}
// Add the current word
newText += splitT[i] + " ";
if (i === totalWords - 1) {
newText += "";
}
}
jQuery(this).html(newText.trim()); // Use trim to remove any trailing space
});
});