Merge pull request #11455 from MoonE/apidoc-improvements

Apidoc improvements
This commit is contained in:
Andreas Hocevar
2020-08-25 15:03:49 +02:00
committed by GitHub
5 changed files with 40 additions and 31 deletions
@@ -36,7 +36,7 @@ $(function () {
} }
// If everything else is equal, prefer shorter names, and prefer classes over modules // If everything else is equal, prefer shorter names, and prefer classes over modules
let weight = 10000 + matchedItem.dataset.longname.length - name.length * 100; let weight = 10000 + matchedItem.dataset.longname.length - name.length * 100;
if (name.match(re.begin)) { if (re.begin.test(name)) {
weight += 10000; weight += 10000;
if (re.baseName.test(name)) { if (re.baseName.test(name)) {
weight += 10000; weight += 10000;
@@ -79,6 +79,7 @@ $(function () {
$currentItem: currentItem ? $(currentItem) : undefined, $currentItem: currentItem ? $(currentItem) : undefined,
lastSearchTerm: undefined, lastSearchTerm: undefined,
lastState: {}, lastState: {},
lastClasses: undefined,
getClassList: function () { getClassList: function () {
return $classItems || ($classItems = $navList.find('li.item')); return $classItems || ($classItems = $navList.find('li.item'));
}, },
@@ -143,9 +144,9 @@ $(function () {
if (state === 'search-empty' && search.$currentItem) { if (state === 'search-empty' && search.$currentItem) {
search.manualToggle(search.$currentItem, true); search.manualToggle(search.$currentItem, true);
} }
search.lastClasses = undefined;
} else { } else {
search.changeStateClass('searching'); search.changeStateClass('searching');
searchTerm = searchTerm.toLowerCase();
const beginOnly = searchTerm.length < minInputForFullText; const beginOnly = searchTerm.length < minInputForFullText;
const getSearchWeight = getWeightFunction(searchTerm, allowRegex); const getSearchWeight = getWeightFunction(searchTerm, allowRegex);
const re = constructRegex(searchTerm, function (searchTerm) { const re = constructRegex(searchTerm, function (searchTerm) {
@@ -197,13 +198,14 @@ $(function () {
li.classList.add('match'); li.classList.add('match');
} }
}); });
classes.sort(function (a, b) {
return b.weight - a.weight;
});
clearOldMatches(search.lastState, searchState); clearOldMatches(search.lastState, searchState);
search.lastState = searchState; search.lastState = searchState;
search.lastClasses = classes;
classes.sort(function (a, b) { for (let i = 0, ii = classes.length; i < ii; ++i) {
return a.weight - b.weight;
});
for (let i = classes.length - 1; i >= 0; --i) {
navList.appendChild(classes[i].item); navList.appendChild(classes[i].item);
} }
} }
@@ -217,15 +219,24 @@ $(function () {
key = setTimeout(function () { key = setTimeout(function () {
key = undefined; key = undefined;
const searchTerm = searchInput.value; doSearch(searchInput.value);
doSearch(searchTerm);
}, 0); }, 0);
} }
} }
// Search Items // Search Items
searchInput.addEventListener('input', queueSearch); searchInput.addEventListener('input', queueSearch);
searchInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
doSearch(searchInput.value);
const first = search.lastClasses ? search.lastClasses[0].item : null;
if (first) {
window.location.href = first.querySelector('.title a').href;
}
}
});
doSearch(searchInput.value); doSearch(searchInput.value);
searchInput.focus();
// Toggle when click an item element // Toggle when click an item element
search.$navList.on('click', '.toggle', function (e) { search.$navList.on('click', '.toggle', function (e) {
@@ -237,10 +248,8 @@ $(function () {
search.manualToggle(clsItem, show); search.manualToggle(clsItem, show);
}); });
var currentVersion = document.getElementById('package-version').innerHTML;
// warn about outdated version // warn about outdated version
var currentVersion = document.getElementById('package-version').innerHTML;
var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json'; var packageUrl = 'https://raw.githubusercontent.com/openlayers/openlayers.github.io/build/package.json';
fetch(packageUrl).then(function(response) { fetch(packageUrl).then(function(response) {
return response.json(); return response.json();
@@ -265,15 +274,4 @@ $(function () {
} }
} }
}); });
// create source code links to github
var srcLinks = $('div.tag-source');
srcLinks.each(function(i, el) {
var textParts = el.innerHTML.trim().split(', ');
var link = 'https://github.com/openlayers/openlayers/blob/v' + currentVersion + '/src/ol/' +
textParts[0];
el.innerHTML = '<a href="' + link + '">' + textParts[0] + '</a>, ' +
'<a href="' + link + textParts[1].replace('line ', '#L') + '">' +
textParts[1] + '</a>';
});
}); });
@@ -335,8 +335,8 @@ span.type-signature.static {
} }
.main .nameContainer { .main .nameContainer {
position: relative; position: relative;
margin-top: 20px; margin-top: 1.2rem;
padding-top: 5px; padding-top: 1.2rem;
border-top: 2px solid #1F6B75; border-top: 2px solid #1F6B75;
} }
.main .nameContainer .inherited { .main .nameContainer .inherited {
@@ -354,7 +354,7 @@ span.type-signature.static {
@media (min-width: 768px) { @media (min-width: 768px) {
.main .nameContainer .tag-source { .main .nameContainer .tag-source {
position: absolute; position: absolute;
top: 0.2rem; top: 1.2rem;
right: 0; right: 0;
font-size: 0.8rem; font-size: 0.8rem;
} }
@@ -54,11 +54,15 @@
<article> <article>
<div class="container-overview"> <div class="container-overview">
<?js if (doc.kind === 'module' && doc.module) { ?> <?js if (doc.kind === 'module' && doc.module) { ?>
<?js= self.partial('method.tmpl', doc.module) ?> <dl>
<?js= self.partial('method.tmpl', doc.module) ?>
</dl>
<?js } ?> <?js } ?>
<?js if (doc.kind === 'class') { ?> <?js if (doc.kind === 'class') { ?>
<?js= self.partial('method.tmpl', doc) ?> <dl>
<?js= self.partial('method.tmpl', doc) ?>
</dl>
<?js } else { ?> <?js } else { ?>
<?js if (doc.description) { ?> <?js if (doc.description) { ?>
<div class="description"><?js= doc.description ?></div> <div class="description"><?js= doc.description ?></div>
+1 -1
View File
@@ -4,6 +4,7 @@ var version = obj.packageInfo.version;
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8">
<script> <script>
var gaProperty = 'UA-2577926-1'; var gaProperty = 'UA-2577926-1';
// Disable tracking if the opt-out cookie exists. // Disable tracking if the opt-out cookie exists.
@@ -61,7 +62,6 @@ var version = obj.packageInfo.version;
}) })
}); });
</script> </script>
<meta charset="utf-8">
<title>OpenLayers v<?js= version ?> API - <?js= title ?></title> <title>OpenLayers v<?js= version ?> API - <?js= title ?></title>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch"></script> <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch"></script>
<script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/prettify.js"> </script>
+10 -3
View File
@@ -1,10 +1,16 @@
<?js <?js
var data = obj; var data = obj;
var self = this; var self = this;
var version = self.find({kind: 'package' })[0].version;
if (/-dev$/.test(version)) {
version = 'main';
} else {
version = 'v' + version;
}
?> ?>
<dt class="<?js= (data.stability && data.stability !== 'stable') ? 'unstable' : '' ?>"> <dt class="<?js= (data.stability && data.stability !== 'stable') ? 'unstable' : '' ?>">
<?js if (data.stability || kind !== 'class') { ?>
<div class="nameContainer<?js if (data.inherited) { ?> inherited<?js } ?>"> <div class="nameContainer<?js if (data.inherited) { ?> inherited<?js } ?>">
<?js if (data.stability || kind !== 'class') { ?>
<div class="anchor" id="<?js= id ?>"> <div class="anchor" id="<?js= id ?>">
</div> </div>
<h4 class="name"> <h4 class="name">
@@ -16,11 +22,12 @@ var self = this;
</h4> </h4>
<?js if (data.meta) {?> <?js if (data.meta) {?>
<div class="tag-source"> <div class="tag-source">
<?js= self.linkto(meta.filename) ?>, <?js= self.linkto(meta.filename, 'line ' + meta.lineno, null, 'line' + meta.lineno) ?> <a href="https://github.com/openlayers/openlayers/blob/<?js= version ?>/src/ol/<?js= meta.filename ?>"><?js= meta.filename ?></a>,
<a href="https://github.com/openlayers/openlayers/blob/<?js= version ?>/src/ol/<?js= meta.filename ?>#L<?js= meta.lineno ?>">line <?js= meta.lineno ?></a>
</div> </div>
<?js } ?> <?js } ?>
<?js } ?>
</div> </div>
<?js } ?>
<?js if (data.summary) { ?> <?js if (data.summary) { ?>
<p class="summary"><?js= summary ?></p> <p class="summary"><?js= summary ?></p>
<?js } ?> <?js } ?>