scinote-web/app/assets/javascripts/sidebar.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

/* global PerfectScrollbar */
2020-02-27 23:04:44 +08:00
var Sidebar = (function() {
const SIDEBAR_CONTAINER = '.sidebar-container';
2020-02-27 23:04:44 +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');
}
function reloadSidebar(params) {
let url = $(SIDEBAR_CONTAINER).data('sidebar-url');
2020-02-27 23:04:44 +08:00
}
function initSideBar() {
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
});
$(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-02-27 23:04:44 +08:00
return {
2020-02-28 21:03:08 +08:00
init: () => {
if ($(SIDEBAR_CONTAINER).length) {
initSideBar();
showSelectedLeaf();
$('#wrapper').show();
}
},
reload: (params = {}) => {
reloadSidebar(params);
2020-02-27 23:04:44 +08:00
}
};
}());
$(document).on('turbolinks:load', function() {
Sidebar.init();
});