scinote-web/app/assets/javascripts/sidebar_toggle.js.erb

62 lines
1.5 KiB
Text
Raw Normal View History

(function(global) {
'use strict';
global.SideBarToggle = (function() {
2018-05-30 23:58:18 +08:00
var STORAGE_TOGGLE_KEY = "scinote-sidebar-toggled";
function show() {
$('#wrapper').removeClass('hidden2');
$('#wrapper').css('paddingLeft', '280px');
$('.navbar-secondary').css(
2019-12-04 21:19:19 +08:00
{ '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',
2019-12-04 21:19:19 +08:00
'padding-left': '0'
});
$('#sidebar-arrow').removeAttr('data-shown');
sessionStorage.setItem(STORAGE_TOGGLE_KEY, "toggled");
}
2018-05-24 19:39:04 +08:00
function toggle() {
var btn = $('#sidebar-arrow');
2018-05-25 14:50:27 +08:00
if (btn.is('[data-shown]')) {
2018-05-24 19:39:04 +08:00
hide();
} else {
show();
}
}
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,
2018-05-24 19:39:04 +08:00
hide: hide,
toggle: toggle,
isShown: isShown,
isToggledStorage: isToggledStorage
})
})();
2018-07-19 23:56:42 +08:00
if (SideBarToggle.isToggledStorage()) {
SideBarToggle.hide();;
}
})(window);