Load api navigation dynamically to reduce needed disk space
This commit is contained in:
@@ -62,21 +62,47 @@ $(function () {
|
||||
$navList.addClass('search-empty');
|
||||
return 'search-empty';
|
||||
})();
|
||||
let initialCurrent = navListNode.querySelector('li.item');
|
||||
const longname = initialCurrent && initialCurrent.dataset.longname;
|
||||
let manualToggles = {};
|
||||
|
||||
// Show an item related a current documentation automatically
|
||||
const longname = $('.page-title').data('filename')
|
||||
.replace(/\.[a-z]+$/, '')
|
||||
.replace('module-', 'module:')
|
||||
.replace(/_/g, '/')
|
||||
.replace(/-/g, '~');
|
||||
const currentItem = navListNode.querySelector('.item[data-longname="' + longname + '"]');
|
||||
if (currentItem) {
|
||||
$navList.prepend(currentItem);
|
||||
if (initialCurrent) {
|
||||
manualToggles[longname] = $(initialCurrent);
|
||||
}
|
||||
|
||||
fetch('./navigation.tmpl.html').then(function (response) {
|
||||
return response.text();
|
||||
}).then(function (text) {
|
||||
navListNode.innerHTML = text;
|
||||
|
||||
// Show an item related a current documentation automatically
|
||||
const currentItem = navListNode.querySelector('.item[data-longname="' + longname + '"]');
|
||||
if (currentItem) {
|
||||
$navList.prepend(currentItem);
|
||||
search.$currentItem = $(currentItem);
|
||||
}
|
||||
$classItems = undefined;
|
||||
$members = undefined;
|
||||
|
||||
// Search again with full navigation, if user already searched
|
||||
manualToggles = {};
|
||||
const lastTerm = search.lastSearchTerm;
|
||||
search.lastSearchTerm = undefined;
|
||||
const fa = currentItem.querySelector('.title > .fa');
|
||||
fa.classList.add('no-transition');
|
||||
doSearch(lastTerm || '');
|
||||
|
||||
// Transfer manual toggle state to newly loaded current node
|
||||
if (initialCurrent && initialCurrent.classList.contains('toggle-manual')) {
|
||||
search.manualToggle(search.$currentItem, initialCurrent.classList.contains('toggle-manual-show'));
|
||||
}
|
||||
setTimeout(function () {
|
||||
fa.classList.remove('no-transition');
|
||||
}, 0);
|
||||
});
|
||||
|
||||
return {
|
||||
$navList: $navList,
|
||||
$currentItem: currentItem ? $(currentItem) : undefined,
|
||||
$currentItem: initialCurrent ? $(initialCurrent) : undefined,
|
||||
lastSearchTerm: undefined,
|
||||
lastState: {},
|
||||
lastClasses: undefined,
|
||||
@@ -240,7 +266,7 @@ $(function () {
|
||||
|
||||
// Toggle when click an item element
|
||||
search.$navList.on('click', '.toggle', function (e) {
|
||||
if (event.target.tagName.toLowerCase() === 'a') {
|
||||
if (e.target.tagName === 'A') {
|
||||
return;
|
||||
}
|
||||
const clsItem = $(this).closest('.item');
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
.navbar-brand img {
|
||||
height: 35px;
|
||||
width: 35px;
|
||||
vertical-align: middle;
|
||||
margin-right: 5px;
|
||||
display: inline-block;
|
||||
@@ -71,6 +72,11 @@ li {
|
||||
.navigation-list {
|
||||
padding: 0 15px 0 15px;
|
||||
}
|
||||
.no-transition,
|
||||
.no-transition:after,
|
||||
.no-transition:before {
|
||||
transition: none!important;
|
||||
}
|
||||
@supports (position: sticky) {
|
||||
.navigation {
|
||||
position: sticky;
|
||||
@@ -78,7 +84,7 @@ li {
|
||||
height: calc(100vh - 54px);
|
||||
}
|
||||
.navigation-list {
|
||||
overflow: auto;
|
||||
overflow-y: auto;
|
||||
/* 54px navbar height */
|
||||
/* 4.25rem + 2px searchbox height */
|
||||
/* 25px navigation padding */
|
||||
@@ -94,7 +100,7 @@ li {
|
||||
position: inherit;
|
||||
}
|
||||
.navigation-list {
|
||||
overflow: auto;
|
||||
overflow-y: auto;
|
||||
max-height: 33vh;
|
||||
height: inherit;
|
||||
}
|
||||
@@ -206,6 +212,10 @@ li {
|
||||
padding-left: 8px;
|
||||
}
|
||||
|
||||
.navigation-list li.loading {
|
||||
display: block;
|
||||
height: 101vh;
|
||||
}
|
||||
/* search state */
|
||||
/* show all classes when search is empty */
|
||||
.navigation-list.search-empty .item {
|
||||
|
||||
Reference in New Issue
Block a user