mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-18 23:21:30 +08:00
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
/* global PerfectScrollbar */
|
|
|
|
var Sidebar = (function() {
|
|
const SIDEBAR_CONTAINER = '.sidebar-container';
|
|
|
|
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');
|
|
}
|
|
|
|
function reloadSidebar(params) {
|
|
let url = $(SIDEBAR_CONTAINER).data('sidebar-url');
|
|
}
|
|
|
|
function initSideBar() {
|
|
var sidebarBody = $(SIDEBAR_CONTAINER).find('.sidebar-body');
|
|
var scrollBar = new PerfectScrollbar(sidebarBody[0], {
|
|
wheelSpeed: 0.5, minScrollbarLength: 20
|
|
});
|
|
$(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();
|
|
});
|
|
}
|
|
|
|
return {
|
|
init: () => {
|
|
if ($(SIDEBAR_CONTAINER).length) {
|
|
initSideBar();
|
|
showSelectedLeaf();
|
|
$('#wrapper').show();
|
|
}
|
|
},
|
|
|
|
reload: (params = {}) => {
|
|
reloadSidebar(params);
|
|
}
|
|
};
|
|
}());
|
|
|
|
$(document).on('turbolinks:load', function() {
|
|
Sidebar.init();
|
|
});
|