/* SF State Home main.js
* This script will be the default js file to ship with the SF State Home theme.
*/
(function($) {
Drupal.behaviors.drupaldeveloper = {
attach: function (context) {
/* Mega menu fix */
$("a.mega-group-title").replaceWith(function(){
return $("
" + $(this).html() + "
");
});
$('.nav > li.mega').hover(function() {
if(!$(this).hasClass('open')){
$(this).addClass('open');
} else {
$(this).removeClass('open');
}
$(this).prevAll('.nav > li.mega').removeClass('open');
$(this).nextAll('.nav > li.mega').removeClass('open');
})
$('.nav > li.mega').click(function() {
if(!$(this).hasClass('open')){
$(this).addClass('open');
} else {
$(this).removeClass('open');
}
$(this).prevAll('.nav > li.mega').removeClass('open');
$(this).nextAll('.nav > li.mega').removeClass('open');
})
$('.nav > li.mega').focusout(function() {
$(this).prevAll('.nav > li.mega').removeClass('open');
$(this).nextAll('.nav > li.mega').removeClass('open');
})
$('.nav > li.mega').focusin(function() {
$(this).prevAll('.nav > li.mega').removeClass('open');
$(this).nextAll('.nav > li.mega').removeClass('open');
})
$('.nav > li.mega').keyup(function(e) {
if (e.keyCode == 27) {
$(this).removeClass('open');
$(this).find('a').attr("tabindex", 0).focus();
}
})
$('.nav > li, li.mega').tab(function(event) {
event.stopPropagation();
})
$("a[href='#main-content']").click(function(event){
event.stopPropagation();
$('#main-content').attr("tabindex", 0).focus();
});
$("a[href='#main-navigation']").click(function(event){
event.stopPropagation();
$('#main-navigation').attr("tabindex", 0).focus();
});
/* END Mega menu */
/* Carousel position calculation */
if($('#featured-image').length) {
$(window).on('load resize', function() {
var offTop = $('.item.active .carousel-caption').offset().top;
var offHead = $('#header').offset().top;
var offEmergency = $('#block-views-emergency-notification-block').height();
if($(window).width()>991) {
var indTop = offTop -90 - offHead - offEmergency;
$('#featured-image .carousel-indicators').css({"top":indTop});
}else if($(window).width()>480 && $(window).width()<768) {
var indTop = offTop -130 - offHead - offEmergency;
$('#featured-image .carousel-indicators').css({"top":indTop});
}else if($(window).width()>767 && $(window).width()<992) {
var indTop = offTop -100 - offHead - offEmergency;
$('#featured-image .carousel-indicators').css({"top":indTop});
}else {
$('#featured-image .carousel-indicators').css({"top":30});
}
}).trigger('resize');
}
/* END Carousel position */
/* Footer position calculation */
if($('#main').length) {
$(window).on('load resize', function() {
/* Get heights of the elements */
var headerHeight = $('#header').outerHeight();
var footerHeight = $('.footer').outerHeight();
var mainTopMargin = parseInt($('#main').css('marginTop'));
var footerTopMargin = parseInt($('.footer').css('marginTop'));
var mainHeight = $(window).height() - mainTopMargin - headerHeight - footerHeight - footerTopMargin;
/* Set min height for Main div and content area*/
$('#main').css({"min-height":mainHeight});
$('#main section[role="main"]').css({"min-height":mainHeight});
}).trigger('resize');
}
/* END Footer position calculation */
}
}
})(jQuery);