((function ($) { 'use strict'; let windowWidth= $(window).width(); $( window ).resize(function() { windowWidth = $(window).width(); }); $('.main-navigation').superfish( { delay: 200, animation: { opacity: 'show', }, speed: 'fast', speedOut: 'fast', cssArrows: false, onBeforeShow: function() { if ( ! this.is( '.main-navigation>li:not(.themeoo-mega-menu)>ul' ) ) { const self = this; const parentLi = self.parent(); const parentWidth = parentLi.width(); const subMenuRight = parentLi.offset()?.left + parentWidth + self.width(); if ( subMenuRight > windowWidth ) { self.css({'left': 'auto', 'right': parentWidth+'px'}); } else { self.css({'left': '', 'right': ''}); } } }, } ); }))(jQuery);