summaryrefslogtreecommitdiffstats
path: root/theme/javascript
diff options
context:
space:
mode:
Diffstat (limited to 'theme/javascript')
-rw-r--r--theme/javascript/platform.js4
-rw-r--r--theme/javascript/sidebar.js7
-rw-r--r--theme/javascript/state.js8
3 files changed, 16 insertions, 3 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
diff --git a/theme/javascript/state.js b/theme/javascript/state.js
index fb91f7a..a6a7877 100644
--- a/theme/javascript/state.js
+++ b/theme/javascript/state.js
@@ -11,6 +11,9 @@ state.update = function(dom) {
state.level = $book.data('level');
state.basePath = $book.data('basepath');
+ // If book is multilingual, language of this book
+ state.innerlanguage = $book.data('innerlanguage');
+
// Date of build
state.revision = $book.data('revision');
@@ -20,11 +23,14 @@ state.update = function(dom) {
// Title of the chapter
state.chapterTitle = $book.data('chapter-title');
- // Absolute url to the root of the book
+ // Absolute url to the root of the book (inner book)
state.root = url.resolve(
location.protocol+'//'+location.host,
path.dirname(path.resolve(location.pathname.replace(/\/$/, '/index.html'), state.basePath))
);
+
+ // Absolute root to the language (for multilingual book)
+ state.bookRoot = state.innerlanguage? url.resolve(state.root, '..') : state.root;
};
state.update($);