diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-04 14:10:56 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-04 14:10:56 -0700 |
commit | 446d486a0fb725f3df76d9b6e8d2bca02042805b (patch) | |
tree | cfd5405f607fcca196ef5bad6b0b88662c30ccb9 /theme/javascript/core/sidebar.js | |
parent | 07101deaefb8848d40231eea12a3bf0710e6a78e (diff) | |
download | gitbook-446d486a0fb725f3df76d9b6e8d2bca02042805b.zip gitbook-446d486a0fb725f3df76d9b6e8d2bca02042805b.tar.gz gitbook-446d486a0fb725f3df76d9b6e8d2bca02042805b.tar.bz2 |
Add base for theming
Diffstat (limited to 'theme/javascript/core/sidebar.js')
-rw-r--r-- | theme/javascript/core/sidebar.js | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/theme/javascript/core/sidebar.js b/theme/javascript/core/sidebar.js new file mode 100644 index 0000000..717c2b7 --- /dev/null +++ b/theme/javascript/core/sidebar.js @@ -0,0 +1,42 @@ +define([ + "utils/storage", + "utils/platform", + "core/state" +], function(storage, platform, state) { + + // Toggle sidebar with or withour animation + var toggleSidebar = function(_state, animation) { + if (-state != null && isOpen() == _state) return; + 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 + toggleSidebar(platform.isMobile ? false : storage.get("sidebar", true), false); + }; + + return { + init: init, + toggle: toggleSidebar + } +});
\ No newline at end of file |