mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Save sidebar state
This commit is contained in:
@@ -3,16 +3,14 @@ require([
|
||||
"core/state",
|
||||
"core/exercise",
|
||||
"core/progress",
|
||||
], function($, _state, exercise, progress){
|
||||
"core/sidebar"
|
||||
], function($, _state, exercise, progress, sidebar){
|
||||
$(document).ready(function() {
|
||||
var state = _state();
|
||||
var $book = state.$book;
|
||||
|
||||
// Toggle summary
|
||||
$book.find(".book-header .toggle-summary").click(function(e) {
|
||||
e.preventDefault();
|
||||
$book.toggleClass("with-summary");
|
||||
});
|
||||
// Init sidebar
|
||||
sidebar.init();
|
||||
|
||||
// Star and watch count
|
||||
$.getJSON("https://api.github.com/repos/"+state.githubId)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
define([
|
||||
"utils/storage",
|
||||
"utils/platform",
|
||||
"core/state"
|
||||
], function(storage, platform, state) {
|
||||
|
||||
// Toggle sidebar with or withour animation
|
||||
var toggleSidebar = function(_state, animation) {
|
||||
if (animation == null) animation = true;
|
||||
|
||||
var $book = state().$book;
|
||||
$book.toggleClass("without-animation", !animation);
|
||||
$book.toggleClass("with-summary", _state);
|
||||
|
||||
storage.set("sidebar", isOpen());
|
||||
};
|
||||
|
||||
// Return true if sidebar is open
|
||||
var isOpen = function() {
|
||||
return state().$book.hasClass("with-summary");
|
||||
};
|
||||
|
||||
// Prepare sidebar: state and toggle button
|
||||
var init = function() {
|
||||
var $book = state().$book;
|
||||
|
||||
// Toggle summary
|
||||
$book.find(".book-header .toggle-summary").click(function(e) {
|
||||
e.preventDefault();
|
||||
toggleSidebar();
|
||||
});
|
||||
|
||||
// Init last state if not mobile and not homepage
|
||||
if (!isOpen()) toggleSidebar(platform.isMobile ? false : storage.get("sidebar", false), false);
|
||||
};
|
||||
|
||||
return {
|
||||
init: init,
|
||||
toggle: toggleSidebar
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
define([], function() {
|
||||
return {
|
||||
isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
||||
};
|
||||
});
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -46,4 +46,10 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.without-animation {
|
||||
.book-body {
|
||||
.transition(none) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,4 +90,10 @@
|
||||
left: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
&.without-animation {
|
||||
.book-summary {
|
||||
.transition(none) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user