mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-25 11:52:10 +00:00
Define specific action for toggling summary
This commit is contained in:
@@ -65,7 +65,6 @@ define([
|
||||
|
||||
// Update state
|
||||
state.update($("html"));
|
||||
// recover search keyword
|
||||
preparePage();
|
||||
})
|
||||
.fail(function (e) {
|
||||
|
||||
@@ -1,56 +1,51 @@
|
||||
define([
|
||||
"jQuery",
|
||||
"lodash",
|
||||
"utils/storage",
|
||||
"utils/platform",
|
||||
"core/state"
|
||||
'jQuery',
|
||||
'lodash',
|
||||
'utils/storage',
|
||||
'utils/platform',
|
||||
'core/state'
|
||||
], function($, _, storage, platform, state) {
|
||||
// Toggle sidebar with or withour animation
|
||||
var toggleSidebar = function(_state, animation) {
|
||||
function toggleSidebar(_state, animation) {
|
||||
if (state != null && isOpen() == _state) return;
|
||||
if (animation == null) animation = true;
|
||||
|
||||
state.$book.toggleClass("without-animation", !animation);
|
||||
state.$book.toggleClass("with-summary", _state);
|
||||
state.$book.toggleClass('without-animation', !animation);
|
||||
state.$book.toggleClass('with-summary', _state);
|
||||
|
||||
storage.set("sidebar", isOpen());
|
||||
};
|
||||
storage.set('sidebar', isOpen());
|
||||
}
|
||||
|
||||
// Return true if sidebar is open
|
||||
var isOpen = function() {
|
||||
return state.$book.hasClass("with-summary");
|
||||
};
|
||||
function isOpen() {
|
||||
return state.$book.hasClass('with-summary');
|
||||
}
|
||||
|
||||
// Prepare sidebar: state and toggle button
|
||||
var init = function() {
|
||||
// Toggle summary
|
||||
$(document).on("click", ".book-header .toggle-summary", function(e) {
|
||||
e.preventDefault();
|
||||
toggleSidebar();
|
||||
});
|
||||
|
||||
function init() {
|
||||
// Init last state if not mobile
|
||||
if (!platform.isMobile) {
|
||||
toggleSidebar(storage.get("sidebar", true), false);
|
||||
toggleSidebar(storage.get('sidebar', true), false);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Filter summary with a list of path
|
||||
var filterSummary = function(paths) {
|
||||
var $summary = $(".book-summary");
|
||||
function filterSummary(paths) {
|
||||
var $summary = $('.book-summary');
|
||||
|
||||
$summary.find("li").each(function() {
|
||||
var path = $(this).data("path");
|
||||
$summary.find('li').each(function() {
|
||||
var path = $(this).data('path');
|
||||
var st = paths == null || _.contains(paths, path);
|
||||
|
||||
$(this).toggle(st);
|
||||
if (st) $(this).parents("li").show();
|
||||
if (st) $(this).parents('li').show();
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
init: init,
|
||||
isOpen: isOpen,
|
||||
toggle: toggleSidebar,
|
||||
filter: filterSummary
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -26,6 +26,16 @@ keyboard, navigation, progress, sidebar, toolbar){
|
||||
// Init navigation
|
||||
navigation.init();
|
||||
|
||||
|
||||
// Add action to toggle sidebar
|
||||
toolbar.createButton({
|
||||
icon: 'fa fa-align-justify',
|
||||
onClick: function(e) {
|
||||
e.preventDefault();
|
||||
sidebar.toggle();
|
||||
}
|
||||
});
|
||||
|
||||
events.trigger('start', config);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user