I made a sidebar that has a slide-out feature. When you click on it, it shows more items. I made it with JS and HTML but I think the code can be done more efficiently. How can I clean the code up?
$('.slide-out').on('click', function() {
let data = 'slideout-item';
if($(this).data(data)) {
let item = $('.slide-out-' + $(this).data(data));
if(item.hasClass('slideout-active')) {
item.hide("slide", { direction: "left" }, 250);
item.removeClass('slideout-active');
$('.slide-out-overlay').fadeOut()
} else {
item.show("slide", { direction: "left" }, 250);
item.addClass('slideout-active');
$('.slide-out-overlay').fadeIn()
}
}
});
$('.slide-out-overlay').on('click', function () {
let items = ['content', 'system', 'account', 'other'];
let item = '.slide-out-';
for (i = 0; i < items.length; i++) {
if($(item + items[i]).hasClass('slideout-active')) {
$(item + items[i]).hide("slide", { direction: "left"}, 250);
$(item + items[i]).removeClass('slideout-active');
$('.slide-out-overlay').fadeOut();
}
}
});
<ul class="list-unstyled">
<li class="sidebar-item title">{{ __('Information') }}</li>
<li class="sidebar-item"><a href="{{ route('home') }}" class="sidebar-link {{ Route::currentRouteNamed('home') ? 'sidebar-active' : '' }}">{{ __('Dashboard') }}</a></li>
<li class="sidebar-item title">{{ __('System') }}</li>
<li class="sidebar-item"><a href="#" class="sidebar-link slide-out" data-slideout-item="content">Content<i class="far fa-chevron-right" style="position:absolute; right: 0;"></i></a></li>
<li class="sidebar-item"><a href="#" class="sidebar-link slide-out" data-slideout-item="system">System<i class="far fa-chevron-right" style="position:absolute; right: 0;"></i></a></li>
<li class="sidebar-item"><a href="#" class="sidebar-link slide-out" data-slideout-item="account">Account<i class="far fa-chevron-right" style="position:absolute; right: 0;"></i></a></li>
<li class="sidebar-item"><a href="#" class="sidebar-link slide-out" data-slideout-item="other">Other<i class="far fa-chevron-right" style="position:absolute; right: 0;"></i></a></li>
</ul>
<div class="slide-out-block shadow slide-out-content" id="slide-out">
<nav class="sidebar-slideout">
<ul class="list-unstyled">
<li class="sidebar-item title">{{ __('Content') }}</li>
<li class="sidebar-item"><a href="{{ route('pages') }}" class="sidebar-link {{ Route::currentRouteNamed('pages') ? 'sidebar-active' : '' }}">{{ __('Pages') }}</a></li>
<li class="sidebar-item"><a href="{{ route('blocks') }}" class="sidebar-link {{ Route::currentRouteNamed('blocks') ? 'sidebar-active' : '' }}">{{ __('Blocks') }}</a></li>
<li class="sidebar-item"><a href="{{ route('layouts') }}" class="sidebar-link {{ Route::currentRouteNamed('layouts') ? 'sidebar-active' : '' }}">{{ __('Layouts') }}</a></li>
</ul>
</nav>
</div>