This is a handy way to not only load the native Oxygen toggles as closed on mobile, but also close and open when the browser is resized.
jQuery(document).ready(function () {
/*if (window.matchMedia('(max-width: 767px)').matches) {
customCloseToggles();
}*/
var isMobile = window.matchMedia("only screen and (max-width: 767px)");
isMobile.onchange = toggleDecide;
if (isMobile.matches) {
toggleMobile();
}
function toggleDecide() {
if (isMobile.matches) {
toggleMobile();
} else {
toggleDesktop();
}
};
function toggleMobile() {
jQuery('.off-canvas-menu__inner-menu .oxy-toggle').each(function () {
var toggle_target = jQuery(this).attr('data-oxy-toggle-target'),
active_class = jQuery(this).attr('data-oxy-toggle-active-class');
if (!toggle_target) {
jQuery(this).next().hide();
} else {
jQuery(toggle_target).hide();
}
jQuery(this).children('.oxy-expand-collapse-icon').addClass('oxy-eci-collapsed');
jQuery(this).removeClass(active_class);
});
};
function toggleDesktop() {
jQuery('.off-canvas-menu__inner-menu .oxy-toggle').each(function () {
var toggle_target = jQuery(this).attr('data-oxy-toggle-target'),
active_class = jQuery(this).attr('data-oxy-toggle-active-class');
if (!toggle_target) {
jQuery(this).next().show();
} else {
jQuery(toggle_target).show();
}
jQuery(this).children('.oxy-expand-collapse-icon').removeClass('oxy-eci-collapsed');
jQuery(this).addClass(active_class);
});
};
});
Code language: JavaScript (javascript)