-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e1c4647
Showing
49 changed files
with
48,718 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
"use strict"; | ||
|
||
// Fix back button cache problem | ||
window.onunload = function () { }; | ||
|
||
(function sidebar() { | ||
var html = document.querySelector("html"); | ||
var sidebar = document.getElementById("sidebar"); | ||
var sidebarLinks = document.querySelectorAll('#sidebar a'); | ||
var sidebarToggleButton = document.getElementById("sidebar-toggle"); | ||
var firstContact = null; | ||
|
||
function showSidebar() { | ||
html.classList.remove('sidebar-hidden') | ||
html.classList.add('sidebar-visible'); | ||
Array.from(sidebarLinks).forEach(function (link) { | ||
link.setAttribute('tabIndex', 0); | ||
}); | ||
sidebarToggleButton.setAttribute('aria-expanded', true); | ||
sidebar.setAttribute('aria-hidden', false); | ||
try { localStorage.setItem('mdbook-sidebar', 'visible'); } catch (e) { } | ||
} | ||
|
||
function hideSidebar() { | ||
html.classList.remove('sidebar-visible') | ||
html.classList.add('sidebar-hidden'); | ||
Array.from(sidebarLinks).forEach(function (link) { | ||
link.setAttribute('tabIndex', -1); | ||
}); | ||
sidebarToggleButton.setAttribute('aria-expanded', false); | ||
sidebar.setAttribute('aria-hidden', true); | ||
try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { } | ||
} | ||
|
||
// Toggle sidebar | ||
sidebarToggleButton.addEventListener('click', function sidebarToggle() { | ||
if (html.classList.contains("sidebar-hidden")) { | ||
showSidebar(); | ||
} else if (html.classList.contains("sidebar-visible")) { | ||
hideSidebar(); | ||
} else { | ||
if (getComputedStyle(sidebar)['transform'] === 'none') { | ||
hideSidebar(); | ||
} else { | ||
showSidebar(); | ||
} | ||
} | ||
}); | ||
|
||
document.addEventListener('touchstart', function (e) { | ||
firstContact = { | ||
x: e.touches[0].clientX, | ||
time: Date.now() | ||
}; | ||
}, { passive: true }); | ||
|
||
document.addEventListener('touchmove', function (e) { | ||
if (!firstContact) | ||
return; | ||
|
||
var curX = e.touches[0].clientX; | ||
var xDiff = curX - firstContact.x, | ||
tDiff = Date.now() - firstContact.time; | ||
|
||
if (tDiff < 250 && Math.abs(xDiff) >= 150) { | ||
if (xDiff >= 0 && firstContact.x < Math.min(document.body.clientWidth * 0.25, 300)) | ||
showSidebar(); | ||
else if (xDiff < 0 && curX < 300) | ||
hideSidebar(); | ||
|
||
firstContact = null; | ||
} | ||
}, { passive: true }); | ||
|
||
// Scroll sidebar to current active section | ||
var activeSection = sidebar.querySelector(".active"); | ||
if (activeSection) { | ||
sidebar.scrollTop = activeSection.offsetTop; | ||
} | ||
})(); | ||
|
||
(function chapterNavigation() { | ||
document.addEventListener('keydown', function (e) { | ||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } | ||
if (window.search && window.search.hasFocus()) { return; } | ||
|
||
switch (e.key) { | ||
case 'ArrowRight': | ||
e.preventDefault(); | ||
var nextButton = document.querySelector('.nav-chapters.next'); | ||
if (nextButton) { | ||
window.location.href = nextButton.href; | ||
} | ||
break; | ||
case 'ArrowLeft': | ||
e.preventDefault(); | ||
var previousButton = document.querySelector('.nav-chapters.previous'); | ||
if (previousButton) { | ||
window.location.href = previousButton.href; | ||
} | ||
break; | ||
} | ||
}); | ||
})(); | ||
|
||
(function scrollToTop () { | ||
var menuTitle = document.querySelector('.menu-title'); | ||
|
||
menuTitle.addEventListener('click', function () { | ||
document.scrollingElement.scrollTo({ top: 0, behavior: 'smooth' }); | ||
}); | ||
})(); | ||
|
||
(function autoHideMenu() { | ||
var menu = document.getElementById('menu-bar'); | ||
|
||
var previousScrollTop = document.scrollingElement.scrollTop; | ||
|
||
document.addEventListener('scroll', function () { | ||
if (menu.classList.contains('folded') && document.scrollingElement.scrollTop < previousScrollTop) { | ||
menu.classList.remove('folded'); | ||
} else if (!menu.classList.contains('folded') && document.scrollingElement.scrollTop > previousScrollTop) { | ||
menu.classList.add('folded'); | ||
} | ||
|
||
if (!menu.classList.contains('bordered') && document.scrollingElement.scrollTop > 0) { | ||
menu.classList.add('bordered'); | ||
} | ||
|
||
if (menu.classList.contains('bordered') && document.scrollingElement.scrollTop === 0) { | ||
menu.classList.remove('bordered'); | ||
} | ||
|
||
previousScrollTop = document.scrollingElement.scrollTop; | ||
}, { passive: true }); | ||
})(); |
Oops, something went wrong.