mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-23 12:24:45 +02:00
Implement sidebar collapse with stimulus.
This commit is contained in:
parent
ab179a8b71
commit
565cb3a790
5 changed files with 79 additions and 109 deletions
|
@ -40,7 +40,6 @@ import '@fortawesome/fontawesome-free/css/all.css'
|
|||
|
||||
require('bootstrap');
|
||||
|
||||
import "./sidebar"
|
||||
import "./datatables";
|
||||
import "./error_handler";
|
||||
import "./tab_remember";
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
import "patternfly-bootstrap-treeview/src/css/bootstrap-treeview.css"
|
||||
import "patternfly-bootstrap-treeview";
|
||||
|
||||
class SidebarHelper {
|
||||
constructor() {
|
||||
this.BASE = $("body").data("base-url");
|
||||
//If path doesn't end with slash, add it.
|
||||
if(this.BASE[this.BASE.length - 1] !== '/') {
|
||||
this.BASE = this.BASE + '/';
|
||||
}
|
||||
console.info("Base path is " + this.BASE);
|
||||
|
||||
this.registerSidebarHideButton();
|
||||
//this.fillTrees();
|
||||
}
|
||||
|
||||
registerSidebarHideButton()
|
||||
{
|
||||
let $sidebar = $("#fixed-sidebar");
|
||||
let $container = $("#main");
|
||||
let $toggler = $('#sidebar-toggle-button');
|
||||
|
||||
function sidebarHide() {
|
||||
$sidebar.hide();
|
||||
$container.removeClass('col-md-9 col-lg-10 offset-md-3 offset-lg-2');
|
||||
$container.addClass('col-12');
|
||||
$toggler.html('<i class="fas fa-angle-right"></i>');
|
||||
$toggler.data('hidden', true);
|
||||
localStorage.setItem('sidebarHidden', 'true');
|
||||
}
|
||||
function sidebarShow() {
|
||||
let $sidebar = $("#fixed-sidebar");
|
||||
$sidebar.show();
|
||||
let $container = $("#main");
|
||||
$container.removeClass('col-12');
|
||||
$container.addClass('col-md-9 col-lg-10 offset-md-3 offset-lg-2');
|
||||
$toggler.html('<i class="fas fa-angle-left"></i>');
|
||||
$toggler.data('hidden', false);
|
||||
localStorage.setItem('sidebarHidden', 'false');
|
||||
}
|
||||
|
||||
//Make the state persistent over reloads
|
||||
if(localStorage.getItem('sidebarHidden') === 'true') {
|
||||
sidebarHide();
|
||||
}
|
||||
|
||||
//Register handler
|
||||
$toggler.click(function() {
|
||||
if($(this).data('hidden')) {
|
||||
sidebarShow();
|
||||
} else {
|
||||
sidebarHide();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new SidebarHelper();
|
Loading…
Add table
Add a link
Reference in a new issue