Fix #47 sidebar stays hidden even after page change

This commit is contained in:
Mathieu David 2015-09-24 16:47:33 +02:00
parent 7446743cd6
commit 6c240090ae
6 changed files with 64 additions and 9 deletions

View File

@ -30,8 +30,14 @@ body {
} }
@media only screen and (max-width: 1060px) { @media only screen and (max-width: 1060px) {
.sidebar { .sidebar {
left: -$sidebar-width;
}
}
.sidebar-hidden .sidebar {
left: -300px; left: -300px;
} }
.sidebar-visible . sidebar {
left: 0;
} }
.chapter { .chapter {
list-style: none outside none; list-style: none outside none;
@ -85,6 +91,12 @@ body {
padding-right: 15px; padding-right: 15px;
} }
} }
.sidebar-hidden .page-wrapper {
left: 15px;
}
.sidebar-visible .page-wrapper {
left: 315px;
}
.page { .page {
position: absolute; position: absolute;
top: 0; top: 0;

View File

@ -3,12 +3,14 @@ $( document ).ready(function() {
// url // url
var url = window.location.pathname; var url = window.location.pathname;
// Set theme // Set theme
var theme = localStorage.getItem('theme'); var theme = localStorage.getItem('theme');
if (theme == null) { theme = 'light'; } if (theme == null) { theme = 'light'; }
set_theme(theme); set_theme(theme);
// Syntax highlighting Configuration // Syntax highlighting Configuration
hljs.configure({ hljs.configure({
tabReplace: ' ', // 4 spaces tabReplace: ' ', // 4 spaces
@ -21,19 +23,31 @@ $( document ).ready(function() {
// Interesting DOM Elements // Interesting DOM Elements
var html = $("html");
var sidebar = $("#sidebar"); var sidebar = $("#sidebar");
var page_wrapper = $("#page-wrapper"); var page_wrapper = $("#page-wrapper");
// Toggle sidebar
$("#sidebar-toggle").click(function(event){ $("#sidebar-toggle").click(function(event){
if(sidebar.position().left === 0){ if ( html.hasClass("sidebar-hidden") ) {
sidebar.css({left: "-300px"}); html.removeClass("sidebar-hidden").addClass("sidebar-visible");
page_wrapper.css({left: "15px"}); localStorage.setItem('sidebar', 'visible');
} else if ( html.hasClass("sidebar-visible") ) {
html.removeClass("sidebar-visible").addClass("sidebar-hidden");
localStorage.setItem('sidebar', 'hidden');
} else { } else {
sidebar.css({left: "0"}); if(sidebar.position().left === 0){
page_wrapper.css({left: "315px"}); html.addClass("sidebar-hidden");
localStorage.setItem('sidebar', 'hidden');
} else {
html.addClass("sidebar-visible");
localStorage.setItem('sidebar', 'visible');
}
} }
}); });
// Print button // Print button
$("#print-button").click(function(){ $("#print-button").click(function(){
var printWindow = window.open("print.html"); var printWindow = window.open("print.html");
@ -43,6 +57,7 @@ $( document ).ready(function() {
window.print(); window.print();
} }
// Theme button // Theme button
$("#theme-toggle").click(function(){ $("#theme-toggle").click(function(){
if($('.theme-popup').length) { if($('.theme-popup').length) {

View File

@ -37,6 +37,13 @@
$('body').removeClass().addClass(theme); $('body').removeClass().addClass(theme);
</script> </script>
<!-- Hide / unhide sidebar before it is displayed -->
<script type="text/javascript">
var sidebar = localStorage.getItem('sidebar');
if (sidebar === "hidden") { $("html").addClass("sidebar-hidden") }
else if (sidebar === "visible") { $("html").addClass("sidebar-visible") }
</script>
<div id="sidebar" class="sidebar"> <div id="sidebar" class="sidebar">
{{#toc}}{{/toc}} {{#toc}}{{/toc}}
</div> </div>

View File

@ -1,7 +1,9 @@
@require 'variables'
.page-wrapper { .page-wrapper {
position: absolute position: absolute
overflow-y: auto overflow-y: auto
left: 315px left: $sidebar-width + 15px
right: 0 right: 0
top: 0 top: 0
bottom: 0 bottom: 0
@ -19,6 +21,14 @@
} }
} }
.sidebar-hidden .page-wrapper {
left: 15px
}
.sidebar-visible .page-wrapper {
left: $sidebar-width + 15px
}
.page { .page {
position: absolute position: absolute
top: 0 top: 0

View File

@ -1,9 +1,11 @@
@require 'variables'
.sidebar { .sidebar {
position: absolute position: absolute
left: 0 left: 0
top: 0 top: 0
bottom: 0 bottom: 0
width: 300px width: $sidebar-width
overflow-y: auto overflow-y: auto
padding: 10px 10px padding: 10px 10px
font-size: 0.875em font-size: 0.875em
@ -14,10 +16,18 @@
transition: left 0.5s transition: left 0.5s
@media only screen and (max-width: 1060px) { @media only screen and (max-width: 1060px) {
left: -300px left: -$sidebar-width
} }
} }
.sidebar-hidden .sidebar {
left: - $sidebar-width
}
.sidebar-visible . sidebar {
left: 0
}
.chapter { .chapter {
list-style: none outside none list-style: none outside none
padding-left: 0 padding-left: 0

View File

@ -0,0 +1 @@
$sidebar-width = 300px