mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-11-17 06:35:14 +08:00
1f6fff812a
* Add projects navigation buttons and fix sidebar reload on sorting [SCI-5357][SCI-5331]
51 lines
1.4 KiB
JavaScript
51 lines
1.4 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');
|
|
$.get(url, params, function(result) {
|
|
$(SIDEBAR_CONTAINER).find('.sidebar-body').html(result.html);
|
|
showSelectedLeaf();
|
|
$(SIDEBAR_CONTAINER).data('scrollBar').update();
|
|
});
|
|
}
|
|
|
|
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();
|
|
});
|