From da85eda127ec2a89bf26a6fe79af21b392465f5c Mon Sep 17 00:00:00 2001 From: AndreiCN Date: Thu, 15 Feb 2018 17:30:58 +0200 Subject: [PATCH] #563 Dynamic URL navigation problem --- build/js/custom.js | 22 +++++++++++++++++++--- build/js/custom.min.js | 2 +- src/js/custom.js | 22 +++++++++++++++++++--- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/build/js/custom.js b/build/js/custom.js index 7ff07f1c..c65db6ac 100644 --- a/build/js/custom.js +++ b/build/js/custom.js @@ -108,11 +108,27 @@ $(document).ready(function() { }); // check active menu - $SIDEBAR_MENU.find('a[href="' + CURRENT_URL + '"]').parent('li').addClass('current-page'); - $SIDEBAR_MENU.find('a').filter(function () { + var $cur_menu = $SIDEBAR_MENU.find('a').filter(function () { // find nav element with exact match return this.href == CURRENT_URL; - }).parent('li').addClass('current-page').parents('ul').slideDown(function() { + }); + + if ($cur_menu.length == 0) { // if no exact match, try to find best match + var $cur_menu = $SIDEBAR_MENU.find('a').filter(function () { + return CURRENT_URL.startsWith(this.href) && this.href != ''; + }); + + if ($cur_menu.length > 1) { // get ONLY one with longest href as best match + var l = 0; + for (var i = 0; i < $cur_menu.length; i++) { + if ($cur_menu.eq(l).attr('href').length < $cur_menu.eq(i).attr('href').length) l = i; + } + $cur_menu = $cur_menu.eq(l); + } + } + + // original code below, but executed for $cur_menu + $cur_menu.parent('li').addClass('current-page').parents('ul').slideDown(function() { setContentHeight(); }).parent().addClass('active'); diff --git a/build/js/custom.min.js b/build/js/custom.min.js index ec4e0032..50c5602d 100644 --- a/build/js/custom.min.js +++ b/build/js/custom.min.js @@ -1 +1 @@ -function countChecked(){"all"===checkState&&$(".bulk_action input[name='table_records']").iCheck("check"),"none"===checkState&&$(".bulk_action input[name='table_records']").iCheck("uncheck");var e=$(".bulk_action input[name='table_records']:checked").length;e?($(".column-title").hide(),$(".bulk-actions").show(),$(".action-cnt").html(e+" Records Selected")):($(".column-title").show(),$(".bulk-actions").hide())}!function(e,t){var n=function(e,t,n){var i;return function(){function c(){n||e.apply(a,o),i=null}var a=this,o=arguments;i?clearTimeout(i):n&&e.apply(a,o),i=setTimeout(c,t||100)}};jQuery.fn[t]=function(e){return e?this.bind("resize",n(e)):this.trigger(t)}}(jQuery,"smartresize");var CURRENT_URL=window.location.href,$BODY=$("body"),$MENU_TOGGLE=$("#menu_toggle"),$SIDEBAR_MENU=$("#sidebar-menu"),$SIDEBAR_FOOTER=$(".sidebar-footer"),$LEFT_COL=$(".left_col"),$RIGHT_COL=$(".right_col"),$NAV_MENU=$(".nav_menu"),$FOOTER=$("footer");$(document).ready(function(){var e=function(){$RIGHT_COL.css("min-height",$(window).height());var e=$BODY.outerHeight(),t=$BODY.hasClass("footer_fixed")?-10:$FOOTER.height(),n=$LEFT_COL.eq(1).height()+$SIDEBAR_FOOTER.height(),i=e:first-child"),"+"==$expand.text()?$expand.text("-"):$expand.text("+")})}),"undefined"!=typeof NProgress&&($(document).ready(function(){NProgress.start()}),$(window).on("load",function(){NProgress.done()})); \ No newline at end of file +function countChecked(){"all"===checkState&&$(".bulk_action input[name='table_records']").iCheck("check"),"none"===checkState&&$(".bulk_action input[name='table_records']").iCheck("uncheck");var e=$(".bulk_action input[name='table_records']:checked").length;e?($(".column-title").hide(),$(".bulk-actions").show(),$(".action-cnt").html(e+" Records Selected")):($(".column-title").show(),$(".bulk-actions").hide())}!function(e,t){var n=function(e,t,n){var i;return function(){function c(){n||e.apply(a,o),i=null}var a=this,o=arguments;i?clearTimeout(i):n&&e.apply(a,o),i=setTimeout(c,t||100)}};jQuery.fn[t]=function(e){return e?this.bind("resize",n(e)):this.trigger(t)}}(jQuery,"smartresize");var CURRENT_URL=window.location.href,$BODY=$("body"),$MENU_TOGGLE=$("#menu_toggle"),$SIDEBAR_MENU=$("#sidebar-menu"),$SIDEBAR_FOOTER=$(".sidebar-footer"),$LEFT_COL=$(".left_col"),$RIGHT_COL=$(".right_col"),$NAV_MENU=$(".nav_menu"),$FOOTER=$("footer");$(document).ready(function(){var e=function(){$RIGHT_COL.css("min-height",$(window).height());var e=$BODY.outerHeight(),t=$BODY.hasClass("footer_fixed")?-10:$FOOTER.height(),n=$LEFT_COL.eq(1).height()+$SIDEBAR_FOOTER.height(),i=e1){for(var n=0,i=0;i:first-child"),"+"==$expand.text()?$expand.text("-"):$expand.text("+")})}),"undefined"!=typeof NProgress&&($(document).ready(function(){NProgress.start()}),$(window).on("load",function(){NProgress.done()})); \ No newline at end of file diff --git a/src/js/custom.js b/src/js/custom.js index aa960cc8..2cce9147 100644 --- a/src/js/custom.js +++ b/src/js/custom.js @@ -73,11 +73,27 @@ $(document).ready(function() { }); // check active menu - $SIDEBAR_MENU.find('a[href="' + CURRENT_URL + '"]').parent('li').addClass('current-page'); - $SIDEBAR_MENU.find('a').filter(function () { + var $cur_menu = $SIDEBAR_MENU.find('a').filter(function () { // find nav element with exact match return this.href == CURRENT_URL; - }).parent('li').addClass('current-page').parents('ul').slideDown(function() { + }); + + if ($cur_menu.length == 0) { // if no exact match, try to find best match + var $cur_menu = $SIDEBAR_MENU.find('a').filter(function () { + return CURRENT_URL.startsWith(this.href) && this.href != ''; + }); + + if ($cur_menu.length > 1) { // get ONLY one with longest href as best match + var l = 0; + for (var i = 0; i < $cur_menu.length; i++) { + if ($cur_menu.eq(l).attr('href').length < $cur_menu.eq(i).attr('href').length) l = i; + } + $cur_menu = $cur_menu.eq(l); + } + } + + // original code below, but executed for $cur_menu + $cur_menu.parent('li').addClass('current-page').parents('ul').slideDown(function() { setContentHeight(); }).parent().addClass('active');