(function($, window){ var ProfiTheme = window.ProfiTheme || {}; var _global = ProfiTheme.Global, _menu = ProfiTheme.Menu = {}, debounce = null; _menu.$element = $(".navbar.main-menu"); _menu.$asideDropdown = $(" .depth-1 ", _menu.$element); $(document).ready(function() { _menu.$element.find('#main-menu-nav li > a').each(function () { var $this = $(this), href = $this.attr('href').match(/#[^\/]*/), $row = false; if (href) { $this.parent().removeClass('active'); href = href[0]; } try { $row = $(href); } catch (error) { $row = false; } if ($row && $row.length) { $this.click(function (event) { event.preventDefault(); _menu.$element.removeClass('_menu-open'); var top = $row.offset().top; TweenMax.to($(window), .8, { scrollTo: { y: top }, ease: Power1.easeOut }); }); } }); }); $(window).load(function(){ var ckeckAsideDropDown = function ckeckAsideDropDown(){ _menu.$asideDropdown.each(function(num, item){ var $item = $(item); var $parent = $item.parent(0); $item.addClass('push__left'); var offsetParentPanel = _global.windowWidth - $parent.offset().left - $parent.width(); var offsetAsidePanel = _global.windowWidth - $item.offset().left - $item.width(); if(offsetParentPanel < 20 + $item.width()) { // lol 20 is tolerance's threshold $item.removeClass('push__left push__bottom'); $item.css({'left': -$item.width() + 1, 'top': 0}); }else{ $item.removeClass('push__bottom'); $item.css({ 'left': '', 'top': ''}); $item.addClass('push__left'); } if(_global.windowWidth <= 1024){ $item.css({'left': '', 'top': ''}); $item.removeClass('push__left'); $item.addClass('push__bottom'); } }); } ckeckAsideDropDown(); $(window).on('resize',function () { clearTimeout(debounce); debounce = setTimeout(ckeckAsideDropDown, 100) }) }); _menu.check = function() { if (_global.windowWidth > 1024) { if (_global.latestKnownScrollY > 100) { _menu.$element.addClass("navbar-fixed"); } else { _menu.$element.removeClass("navbar-fixed"); } } } $(window).on("scroll", _menu.check); })(jQuery, window);