scinote-web/app/assets/javascripts/sidebar_toggle.js.erb
2020-05-25 16:21:28 +02:00

68 lines
1.7 KiB
Text

(function(global) {
'use strict';
global.SideBarToggle = (function() {
var STORAGE_TOGGLE_KEY = "scinote-sidebar-toggled";
function show() {
$('#wrapper').removeClass('hidden2');
$('#wrapper').css('paddingLeft', '280px');
$('.navbar-secondary').css(
{ 'margin-left': '-280px', 'padding-left': '280px' }
);
$('#sidebar-arrow').attr('data-shown', '');
sessionStorage.setItem(STORAGE_TOGGLE_KEY, "un-toggled");
}
function hide() {
$('#wrapper').addClass('hidden2');
$('#wrapper').css('paddingLeft', '0');
$('.navbar-secondary').css({
'margin-left': '0',
'padding-left': '0'
});
$('#sidebar-arrow').removeAttr('data-shown');
sessionStorage.setItem(STORAGE_TOGGLE_KEY, "toggled");
}
function toggle() {
var btn = $('#sidebar-arrow');
var sideBarEvent;
if (btn.is('[data-shown]')) {
hide();
sideBarEvent = 'sideBar::hidden'
} else {
show();
sideBarEvent = 'sideBar::shown'
}
$('.navbar-secondary').one("transitionend",function(event) {
$('.navbar-secondary').trigger(sideBarEvent);
})
}
function isShown() {
var btn = $('#sidebar-arrow');
return btn.is('[data-shown]');
}
function isToggledStorage() {
var val = sessionStorage.getItem(STORAGE_TOGGLE_KEY);
if (val === null) {
return null;
}
return val === "toggled";
}
return Object.freeze({
show: show,
hide: hide,
toggle: toggle,
isShown: isShown,
isToggledStorage: isToggledStorage
})
})();
if (SideBarToggle.isToggledStorage()) {
SideBarToggle.hide();;
}
})(window);