2020-12-08 23:07:26 +08:00
|
|
|
/* global PerfectScrollbar */
|
2020-02-27 23:04:44 +08:00
|
|
|
|
|
|
|
var Sidebar = (function() {
|
2020-12-08 23:07:26 +08:00
|
|
|
const SIDEBAR_CONTAINER = '.sidebar-container';
|
2020-02-27 23:04:44 +08:00
|
|
|
|
2020-12-10 22:15:36 +08:00
|
|
|
function showSelectedLeaf() {
|
|
|
|
var branchSelectors = $(SIDEBAR_CONTAINER).find('.sidebar-link.selected')
|
|
|
|
.parents('.sidebar-leaf')
|
|
|
|
.find('> .toggle-branch');
|
|
|
|
branchSelectors.removeClass('collapsed fa-caret-right').addClass('fa-caret-down');
|
|
|
|
}
|
|
|
|
|
2021-01-07 20:16:05 +08:00
|
|
|
function reloadSidebar(params) {
|
2020-12-08 23:07:26 +08:00
|
|
|
let url = $(SIDEBAR_CONTAINER).data('sidebar-url');
|
2020-02-27 23:04:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
function initSideBar() {
|
2020-12-08 23:07:26 +08:00
|
|
|
var sidebarBody = $(SIDEBAR_CONTAINER).find('.sidebar-body');
|
|
|
|
var scrollBar = new PerfectScrollbar(sidebarBody[0], {
|
|
|
|
wheelSpeed: 0.5, minScrollbarLength: 20
|
2020-02-28 21:03:08 +08:00
|
|
|
});
|
2020-12-08 23:07:26 +08:00
|
|
|
$(SIDEBAR_CONTAINER).data('scrollBar', scrollBar);
|
|
|
|
$(SIDEBAR_CONTAINER).on('click', '.toggle-branch', function() {
|
|
|
|
$(this).toggleClass('collapsed fa-caret-down fa-caret-right');
|
|
|
|
$(SIDEBAR_CONTAINER).data('scrollBar').update();
|
2020-02-28 21:03:08 +08:00
|
|
|
});
|
2020-12-08 23:07:26 +08:00
|
|
|
}
|
2020-02-27 23:04:44 +08:00
|
|
|
|
|
|
|
return {
|
2020-02-28 21:03:08 +08:00
|
|
|
init: () => {
|
2020-12-10 22:15:36 +08:00
|
|
|
if ($(SIDEBAR_CONTAINER).length) {
|
|
|
|
initSideBar();
|
|
|
|
showSelectedLeaf();
|
|
|
|
$('#wrapper').show();
|
|
|
|
}
|
2020-11-20 21:53:50 +08:00
|
|
|
},
|
2020-12-08 23:07:26 +08:00
|
|
|
|
2021-01-07 20:16:05 +08:00
|
|
|
reload: (params = {}) => {
|
|
|
|
reloadSidebar(params);
|
2020-02-27 23:04:44 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}());
|
|
|
|
|
|
|
|
$(document).on('turbolinks:load', function() {
|
|
|
|
Sidebar.init();
|
|
|
|
});
|