diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-01 13:26:04 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-01 13:26:06 -0700 |
commit | b93f67c84ac13abbee63c91ef24d8089dd78146c (patch) | |
tree | c2cd86490bf8cbf679c3fe6a790637d63fd590a1 /assets/javascript/core/sidebar.js | |
parent | 86cf2d9d9d123177d7a840a4ad0dbb7410e83176 (diff) | |
download | gitbook-b93f67c84ac13abbee63c91ef24d8089dd78146c.zip gitbook-b93f67c84ac13abbee63c91ef24d8089dd78146c.tar.gz gitbook-b93f67c84ac13abbee63c91ef24d8089dd78146c.tar.bz2 |
Save sidebar state
Diffstat (limited to 'assets/javascript/core/sidebar.js')
-rw-r--r-- | assets/javascript/core/sidebar.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/assets/javascript/core/sidebar.js b/assets/javascript/core/sidebar.js new file mode 100644 index 0000000..648aadb --- /dev/null +++ b/assets/javascript/core/sidebar.js @@ -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 + } +});
\ No newline at end of file |