From 56be8a6c5806632cf031dcea76c5cd1101058d3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9?= <34602360+opnsenseuser@users.noreply.github.com> Date: Sat, 12 Feb 2022 09:52:28 +0100 Subject: [PATCH] sidebar - optimization (#5570) Removed unnecessary code for better performance --- src/opnsense/www/js/opnsense_theme.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/opnsense/www/js/opnsense_theme.js b/src/opnsense/www/js/opnsense_theme.js index 128022fb3..f5734e871 100644 --- a/src/opnsense/www/js/opnsense_theme.js +++ b/src/opnsense/www/js/opnsense_theme.js @@ -32,7 +32,6 @@ $(document).ready(function () { // traverse loaded css files var toggle_sidebar_loaded = false, - $window = $(window), winHeight = $(window).height(), mouse = 'mouseenter mouseleave', layer1_a = $('#mainmenu > div > a'), @@ -45,7 +44,7 @@ $(document).ready(function () { footH = $('.page-foot').height(), headerH = $('.navbar').height(), li_itemH = $('a.list-group-item').height(), - navHeight = (countA * 70) + ((footH + headerH) - (20 + countA)), + navHeight = (countA * 70) + ((footH + headerH) - (li_itemH + countA)), events = { mouseenter: function () { $('#navigation.col-sidebar-left').css('width', '415px'); @@ -53,16 +52,14 @@ $(document).ready(function () { if (that.next('div').hasClass('in')) { /* no action needed */ } else { - var offsetTop = that.offset().top; - var winscrTop = $window.scrollTop(); - var divHeight = that.next('div').height(); - var divTop = (offsetTop - winscrTop); - var currentHeight = (divTop + divHeight); - var thatTrigger = that.trigger('click'); + var divHeight = that.next('div').height(), + divTop = that.offset().top, + currentHeight = (divTop + divHeight), + thatTrigger = that.trigger('click'); close_submenu(this); if (currentHeight > (winHeight - li_itemH)) { - var divPos = ((divHeight - li_itemH) > divTop) ? -(((divHeight - li_itemH) - divTop)) : 3; - var viewresult = that.next('div').css('margin-top', -divHeight - (that.is('a') ? divPos : 0)); + var divPos = (divHeight > divTop) ? - ((divHeight - divTop) - li_itemH) : 3, + viewresult = that.next('div').css('margin-top', - divHeight - divPos); } } },