Hide sidebar on link selection when it occupies large space

in relation to the whole screen width (solves problems on phones)
This commit is contained in:
Michal Budzynski 2017-06-09 15:51:30 +02:00
parent 6c279453d9
commit f607978780
1 changed files with 26 additions and 17 deletions

View File

@ -51,31 +51,21 @@ $( 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");
var content = $("#content"); var content = $("#content");
// Toggle sidebar // Toggle sidebar
$("#sidebar-toggle").click(function(event){ $("#sidebar-toggle").click(sidebarToggle);
if ( html.hasClass("sidebar-hidden") ) {
html.removeClass("sidebar-hidden").addClass("sidebar-visible"); // Hide sidebar on section link click if it occupies large space
localStorage.setItem('sidebar', 'visible'); // in relation to the whole screen (phone in portrait)
} else if ( html.hasClass("sidebar-visible") ) { $("#sidebar a").click(function(event){
html.removeClass("sidebar-visible").addClass("sidebar-hidden"); if (sidebar.width() > window.screen.width * 0.4) {
localStorage.setItem('sidebar', 'hidden'); sidebarToggle();
} else {
if(sidebar.position().left === 0){
html.addClass("sidebar-hidden");
localStorage.setItem('sidebar', 'hidden');
} else {
html.addClass("sidebar-visible");
localStorage.setItem('sidebar', 'visible');
}
} }
}); });
// Scroll sidebar to current active section // Scroll sidebar to current active section
var activeSection = sidebar.find(".active"); var activeSection = sidebar.find(".active");
if(activeSection.length) { if(activeSection.length) {
@ -227,6 +217,25 @@ function showTooltip(elem, msg) {
elem.setAttribute('class', 'fa fa-copy tooltipped'); elem.setAttribute('class', 'fa fa-copy tooltipped');
} }
function sidebarToggle() {
var html = $("html");
if ( html.hasClass("sidebar-hidden") ) {
html.removeClass("sidebar-hidden").addClass("sidebar-visible");
localStorage.setItem('sidebar', 'visible');
} else if ( html.hasClass("sidebar-visible") ) {
html.removeClass("sidebar-visible").addClass("sidebar-hidden");
localStorage.setItem('sidebar', 'hidden');
} else {
if($("#sidebar").position().left === 0){
html.addClass("sidebar-hidden");
localStorage.setItem('sidebar', 'hidden');
} else {
html.addClass("sidebar-visible");
localStorage.setItem('sidebar', 'visible');
}
}
}
function run_rust_code(code_block) { function run_rust_code(code_block) {
var result_block = code_block.find(".result"); var result_block = code_block.find(".result");
if(result_block.length === 0) { if(result_block.length === 0) {