diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-11-25 10:25:58 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-11-25 10:25:58 +0100 |
commit | 9bc89c24f5e0048b3138fec5293a968e19feca27 (patch) | |
tree | 78afc22f276291b395f0c65a906af4ea6579aa31 /theme/javascript | |
parent | 5a8c4d5a4ed52e49c33cb6561502843b59950d36 (diff) | |
download | gitbook-9bc89c24f5e0048b3138fec5293a968e19feca27.zip gitbook-9bc89c24f5e0048b3138fec5293a968e19feca27.tar.gz gitbook-9bc89c24f5e0048b3138fec5293a968e19feca27.tar.bz2 |
Fix #1023: close sidebar after clicking a link on mobile
Diffstat (limited to 'theme/javascript')
-rw-r--r-- | theme/javascript/platform.js | 4 | ||||
-rw-r--r-- | theme/javascript/sidebar.js | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/theme/javascript/platform.js b/theme/javascript/platform.js index 9721fb7..b6fb453 100644 --- a/theme/javascript/platform.js +++ b/theme/javascript/platform.js @@ -1,3 +1,5 @@ module.exports = { - isMobile: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) + isMobile: function() { + return (document.width <= 600); + } }; diff --git a/theme/javascript/sidebar.js b/theme/javascript/sidebar.js index d381822..9fc1e8e 100644 --- a/theme/javascript/sidebar.js +++ b/theme/javascript/sidebar.js @@ -25,9 +25,14 @@ function isOpen() { // Prepare sidebar: state and toggle button function init() { // Init last state if not mobile - if (!platform.isMobile) { + if (!platform.isMobile()) { toggleSidebar(storage.get('sidebar', true), false); } + + // Close sidebar after clicking a link on mobile + $(document).on('click', '.book-summary li.chapter a', function(e) { + if (platform.isMobile()) toggleSidebar(false, false); + }); } // Filter summary with a list of path |