Skip to content

Commit

Permalink
Fix sidebar menu not hiding when toggling to small menu
Browse files Browse the repository at this point in the history
  • Loading branch information
christianesperar committed May 28, 2016
1 parent 280f959 commit 44fddfd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 65 deletions.
23 changes: 9 additions & 14 deletions build/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ $(document).ready(function() {
var $li = $(this).parent();

if ($li.is('.active')) {
$li.removeClass('active');
$li.removeClass('active active-sm');
$('ul:first', $li).slideUp(function() {
setContentHeight();
});
} else {
// prevent closing menu if we are on child menu
if (!$li.parent().is('.child_menu')) {
$SIDEBAR_MENU.find('li').removeClass('active');
$SIDEBAR_MENU.find('li').removeClass('active active-sm');
$SIDEBAR_MENU.find('li ul').slideUp();
}

Expand All @@ -58,19 +58,15 @@ $(document).ready(function() {
// toggle small or large menu
$MENU_TOGGLE.on('click', function() {
if ($BODY.hasClass('nav-md')) {
$BODY.removeClass('nav-md').addClass('nav-sm');

if ($SIDEBAR_MENU.find('li').hasClass('active')) {
$SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
}
$SIDEBAR_MENU.find('li.active ul').hide();
$SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
} else {
$BODY.removeClass('nav-sm').addClass('nav-md');

if ($SIDEBAR_MENU.find('li').hasClass('active-sm')) {
$SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
}
$SIDEBAR_MENU.find('li.active-sm ul').show();
$SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
}

$BODY.toggleClass('nav-md nav-sm');

setContentHeight();
});

Expand Down Expand Up @@ -137,7 +133,7 @@ $(document).ready(function() {

// Progressbar
if ($(".progress .progress-bar")[0]) {
$('.progress .progress-bar').progressbar(); // bootstrap 3
$('.progress .progress-bar').progressbar();
}
// /Progressbar

Expand Down Expand Up @@ -244,7 +240,6 @@ if (typeof NProgress != 'undefined') {
NProgress.done();
});
}

/**
* Resize function without multiple trigger
*
Expand Down
2 changes: 1 addition & 1 deletion build/js/custom.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 10 additions & 50 deletions src/js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ $(document).ready(function() {
var $li = $(this).parent();

if ($li.is('.active')) {
$li.removeClass('active');
$li.removeClass('active active-sm');
$('ul:first', $li).slideUp(function() {
setContentHeight();
});
} else {
// prevent closing menu if we are on child menu
if (!$li.parent().is('.child_menu')) {
$SIDEBAR_MENU.find('li').removeClass('active');
$SIDEBAR_MENU.find('li').removeClass('active active-sm');
$SIDEBAR_MENU.find('li ul').slideUp();
}

Expand All @@ -58,19 +58,15 @@ $(document).ready(function() {
// toggle small or large menu
$MENU_TOGGLE.on('click', function() {
if ($BODY.hasClass('nav-md')) {
$BODY.removeClass('nav-md').addClass('nav-sm');

if ($SIDEBAR_MENU.find('li').hasClass('active')) {
$SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
}
$SIDEBAR_MENU.find('li.active ul').hide();
$SIDEBAR_MENU.find('li.active').addClass('active-sm').removeClass('active');
} else {
$BODY.removeClass('nav-sm').addClass('nav-md');

if ($SIDEBAR_MENU.find('li').hasClass('active-sm')) {
$SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
}
$SIDEBAR_MENU.find('li.active-sm ul').show();
$SIDEBAR_MENU.find('li.active-sm').addClass('active').removeClass('active-sm');
}

$BODY.toggleClass('nav-md nav-sm');

setContentHeight();
});

Expand Down Expand Up @@ -137,7 +133,7 @@ $(document).ready(function() {

// Progressbar
if ($(".progress .progress-bar")[0]) {
$('.progress .progress-bar').progressbar(); // bootstrap 3
$('.progress .progress-bar').progressbar();
}
// /Progressbar

Expand Down Expand Up @@ -243,40 +239,4 @@ if (typeof NProgress != 'undefined') {
$(window).load(function () {
NProgress.done();
});
}

/**
* Resize function without multiple trigger
*
* Usage:
* $(window).smartresize(function(){
* // code here
* });
*/
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;

return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}

if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);

timeout = setTimeout(delayed, threshold || 100);
};
};

// smartresize
jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };

})(jQuery,'smartresize');
}
35 changes: 35 additions & 0 deletions src/js/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Resize function without multiple trigger
*
* Usage:
* $(window).smartresize(function(){
* // code here
* });
*/
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;

return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
}

if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);

timeout = setTimeout(delayed, threshold || 100);
};
};

// smartresize
jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };

})(jQuery,'smartresize');

0 comments on commit 44fddfd

Please sign in to comment.