// save current window width to ensure resize events are actual resizing
var window_width;
// set current window width
$(window).ready(function () {
window_width = $(window).width();
});
// MOBILE NAVIGATION
function openNav() {
$("#mobileNav").css("height", $(document).height());
$('#mobileNavBtn').toggle(
function () {
$('#mobileSlide').animate({ left: 260 }, 'slow', function () {
});
},
function () {
$('#mobileSlide').animate({ left: 0 }, 'slow', function () {
});
}
);
}
function mobileMenu() {
$('.mobileBtnLvl2').click(function (e) {
e.preventDefault();
if (false == $(this).siblings('.level2').is(':visible')) {
$('.level2').slideUp(600);
}
$(this).siblings('.level2').slideToggle(600);
});
$('.siteHeader #mobileSearchBtn').click(function (e) {
e.preventDefault();
if (false == $(this).siblings('.siteHeader .searchWrapper').is(':visible')) {
$('.siteHeader .searchWrapper').slideUp(200);
}
$(this).siblings('.siteHeader .searchWrapper').slideToggle(200);
});
}
// ---------------------------------
// HOMEPAGE SLIDESHOW
function homeSlider() {
$(window).load(function () {
$('.flexslider').flexslider({
smoothHeight: true,
directionNav: false
});
});
}
// ---------------------------------
// HIDE VALUE ON INPUT CLICK
function hideValue() {
var el = $('input[type=text], textarea');
el.focus(function (e) {
if (e.target.value == e.target.defaultValue)
e.target.value = '';
});
el.blur(function (e) {
if (e.target.value == '')
e.target.value = e.target.defaultValue;
});
}
// ---------------------------------
// JQUERY UI FUNCTIONS
function jqueryUIs() {
$('.defaultAccordions, .faqAccordion').accordion({
collapsible: true,
heightStyle: "content",
active: false
});
$('.homeAccordion').accordion({
collapsible: true,
heightStyle: "content",
active: false
});
}
// ---------------------------------
// Tabs / Accordion Reversals
function updateTabsAccordions() {
if ($(window).width() < 850) {
// mobile view instructions
tabsToAccordions();
secondaryTabsToAccordions();
} else {
// desktop view instructions
accordionsToTabs();
accordionsToSecondaryTabs();
}
}
function tabsToAccordions() {
$('.tabs').each(function () {
var a = $('
');
var b = new Array();
$(this).find('>ul>li').each(function () {
b.push('
' + $(this).html() + '
');
});
var c = new Array();
$(this).find('>div').each(function () {
c.push('
' + $(this).html() + '
');
});
for (var i = 0; i < b.length; i++) {
a.append(b[i]).append(c[i]);
}
$(this).before(a);
$(this).remove();
})
$('.tabsAccordion').accordion({
collapsible: true,
heightStyle: "content",
active: false
})
}
function accordionsToTabs() {
$('.tabsAccordion').each(function () {
var a = $('
');
var count = 0;
var b = $('
');
$(this).find('>h3').each(function () {
count++;
b.append('- ' + $(this).text() + '
');
});
var count = 0;
var c = $('');
$(this).find('>div').each(function () {
count++;
c = c.add('' + $(this).html() + '
');
});
a.append(b).append(c);
$(this).before(a);
$(this).remove();
});
$('.tabs').tabs({
show: { effect: "fade", duration: 600 }
});
}
function secondaryTabsToAccordions() {
$('.tabs .secondaryTabs').each(function () {
var a = $('');
var b = new Array();
$(this).find('>ul>li').each(function () {
b.push('
' + $(this).html() + '
');
});
var c = new Array();
$(this).find('>div').each(function () {
c.push('
' + $(this).html() + '
');
});
for (var i = 0; i < b.length; i++) {
a.append(b[i]).append(c[i]);
}
$(this).before(a);
$(this).remove();
})
$('.tabsAccordion').accordion({
collapsible: true,
heightStyle: "content",
active: false
})
}
function accordionsToSecondaryTabs() {
$('.tabsAccordion').each(function () {
var a = $('
');
var count = 0;
var b = $('
');
$(this).find('>h3').each(function () {
count++;
b.append('- ' + $(this).text() + '
');
});
var count = 0;
var c = $('');
$(this).find('>div').each(function () {
count++;
c = c.add('' + $(this).html() + '
');
});
a.append(b).append(c);
$(this).before(a);
$(this).remove();
});
$('.tabs').tabs({
show: { effect: "fade", duration: 600 }
});
}
// ---------------------------------
// SELECT WRAPPER DIV
function selectWrapper() {
$("select").each(function () {
$(this).wrapAll("");
});
}
// ---------------------------------
// RESPONSIVE TABLES
function responsiveTables() {
$('table').addClass('table');
$(".table").each(function () {
$(this).not('.cleartable').wrapAll("");
});
$("table.table").click(function () {
$(".tableWrapper").toggleClass($(this).attr("class"));
});
}
// ---------------------------------
// RESPONSIVE LINKS
function responsiveLinks() {
if ($(window).width() < 760) {
$('a[target]').removeAttr('target');
}
}
// ---------------------------------
// RESPONSIVE VIDEOS
function responsiveVideos() {
$("iframe").each(function () {
$(this).wrapAll("");
});
}
// ---------------------------------
// POPUPS
function popups() {
$('.popup').magnificPopup({
disableOn: 759,
type: 'iframe'
});
$('.map-popup').magnificPopup({
type: 'image',
closeOnContentClick: true,
closeBtnInside: false,
fixedContentPos: true,
mainClass: 'mfp-no-margins mfp-with-zoom',
image: {
verticalFit: true
},
zoom: {
enabled: true,
duration: 300
}
});
}
// ---------------------------------
// Lightbox
function loadLightbox() {
var lbLinks = document.querySelectorAll('a.lb');
if (lbLinks.length) {
// Load lightbox assets if there is
var lightboxJs = document.createElement("script");
var lightboxCss = document.createElement("link");
lightboxJs.src = "/App_Themes/Default/lightbox/js/lightbox.min.js";
lightboxJs.type = "text/javascript";
lightboxCss.href = "/App_Themes/Default/lightbox/css/lightbox.min.css";
lightboxCss.type = "text/css";
lightboxCss.rel = "stylesheet";
document.body.appendChild(lightboxJs);
document.body.appendChild(lightboxCss);
}
for (var i = 0; i < lbLinks.length; i++) {
var groups = $.grep(lbLinks[i].className.split(" "), function (c) { return c.indexOf("lb-group-") > -1 });
lbLinks[i].setAttribute("rel", "lightbox");
if (groups.length) {
lbLinks[i].setAttribute("data-lightbox", groups[0]);
}
}
}
// ---------------------------------
function setupAnalyticsEvents() {
$('a.ui-tabs-anchor').click(function () {
var event = {
'eventCategory': 'General',
'eventAction': 'tab_click',
'eventLabel': this.innerHTML.trim()
};
if (location.host.indexOf('mncourts.gov') < 0) {
console.log('Event: ', event);
return;
}
ga('send', 'event', event);
return true;
});
}
function openDefaultTab() {
// Tabs collapse for display widths under 866px.
if ($(window).width() < 866 && location.hash.indexOf("#tab") === 0 && !window.mjbTabOppened) {
document.querySelector("[href='" + location.hash + "']").click();
window.mjbTabOppened = true;
}
}
// RESIZE EVENTS
$(window).on('resize', function () {
// check to see that the window was actually resized. On mobile, this function is triggered on some scroll events
if (window_width && (window_width != $(window).width() || document_height != $(document).height())) {
// this was an actual rezize, so check for width adjustments
if ($(window).width() >= 760) {
$('.siteHeader .searchWrapper').show();
$("#mobileSlide").css("left", "0");
}
else if ($(window).width() < 760) {
$('.siteHeader .searchWrapper').hide();
}
updateTabsAccordions();
// reset current_window width to the current width
window_width = $(window).width();
}
});
// ---------------------------------
// MJB - TOGGLE CHEVRON ICON
function mjbSetupToggleChevronIcon() {
// This is written to add a click event to elements with the mjb-toggle-chevron class.
$(".mjb-toggle-chevron").on("click", function(){
if ($(this).hasClass("mjbicon-chevron-right")) {
// Switch chevron right to chevron down.
$(this).removeClass("mjbicon-chevron-right").addClass("mjbicon-chevron-down");
}
else if ($(this).hasClass("mjbicon-chevron-down")) {
// Switch chevron down to chevron right.
$(this).removeClass("mjbicon-chevron-down").addClass("mjbicon-chevron-right");
}
});
}
// ---------------------------------
$(document).ready(function () {
openNav();
mobileMenu();
homeSlider();
// hideValue(); // 17 Mar 2022 - Joe DeGroot - Commenting this out to prevent text input and textarea elements from being automatically cleared on focus.
jqueryUIs();
selectWrapper();
responsiveTables();
responsiveVideos();
responsiveLinks();
popups();
updateTabsAccordions();
loadLightbox();
setupAnalyticsEvents();
mjbSetupToggleChevronIcon();
openDefaultTab();
});