Update Compodoc

This commit is contained in:
Kevin Pauer
2022-05-10 13:03:10 +02:00
parent 5d266dfdaf
commit bed97bb3d6
62 changed files with 17159 additions and 11459 deletions

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,43 @@
(function(compodoc) {
var engine = null;
var initialized = false;
function setEngine(Engine) {
initialized = false;
engine = new Engine();
init();
}
function init() {
if (!engine) throw new Error('No engine set for research. Set an engine using compodoc.search.setEngine(Engine).');
return engine.init()
.then(function() {
initialized = true;
compodoc.dispatchEvent({
type: compodoc.EVENTS.SEARCH_READY
});
});
}
function query(q, offset, length) {
if (!initialized) throw new Error('Search has not been initialized');
return engine.search(q, offset, length);
}
function getEngine() {
return engine? engine.name : null;
}
function isInitialized() {
return initialized;
}
compodoc.search = {
setEngine: setEngine,
getEngine: getEngine,
query: query,
isInitialized: isInitialized
};
})(compodoc);

View File

@@ -1,7 +1,7 @@
(function(compodoc) {
function LunrSearchEngine() {
this.index = undefined;
this.index = null;
this.store = {};
this.name = 'LunrSearchEngine';
}
@@ -23,7 +23,7 @@
d = new promise.Promise();
if (this.index) {
results = $.map(this.index.search('*' + q + '*'), function(result) {
results = $.map(this.index.search(q), function(result) {
var doc = that.store[result.ref];
return {
@@ -36,7 +36,7 @@
d.done({
query: q,
results: length === 0 ? results : results.slice(0, length),
results: results.slice(0, length),
count: results.length
});
@@ -44,9 +44,19 @@
};
compodoc.addEventListener(compodoc.EVENTS.READY, function(event) {
console.log('compodoc ready');
var engine = new LunrSearchEngine(),
initialized = false;
engine.init()
.then(function() {
initialized = true;
compodoc.dispatchEvent({
type: compodoc.EVENTS.SEARCH_READY
});
});
function query(q, offset, length) {
if (!initialized) throw new Error('Search has not been initialized');
return engine.search(q, offset, length);
@@ -55,13 +65,5 @@
compodoc.search = {
query: query
};
engine.init()
.then(function() {
initialized = true;
compodoc.dispatchEvent({
type: compodoc.EVENTS.SEARCH_READY
});
});
});
})(compodoc);

View File

@@ -1,5 +1,8 @@
(function(compodoc) {
var usePushState = (typeof history.pushState !== 'undefined'),
var MAX_RESULTS = 15,
MAX_DESCRIPTION_SIZE = 500,
usePushState = (typeof history.pushState !== 'undefined'),
// DOM Elements
$body = $('body'),
@@ -20,7 +23,7 @@
var ctx = this, args = arguments;
if (!timeout) {
timeout = setTimeout(function() {
timeout = undefined;
timeout = null;
fn.apply(ctx, args);
}, wait);
}
@@ -29,7 +32,6 @@
function displayResults(res) {
var noResults = res.count == 0;
var groups = {};
$searchResults.toggleClass('no-results', noResults);
// Clear old results
@@ -39,74 +41,30 @@
$searchResultsCount.text(res.count);
$searchQuery.text(res.query);
// Group result by context
// Create an <li> element for each result
res.results.forEach(function(res) {
var context = res.title.split(' - ')[0];
if (typeof groups[context] === 'undefined') {
groups[context] = {
results: [res]
}
} else {
groups[context].results.push(res)
}
});
var sortedGroups = Object.keys(groups).sort();
for (var i = 0; i < sortedGroups.length; i++) {
var property = sortedGroups[i];
var $li = $('<li>', {
'class': 'search-results-group'
'class': 'search-results-item'
});
var finalPropertyLabel = '';
var propertyLabels = property.split('-');
if (propertyLabels.length === 2 && propertyLabels[0] !== 'miscellaneous' && propertyLabels[0] !== 'additional') {
finalPropertyLabel = propertyLabels[0].charAt(0).toUpperCase() + propertyLabels[0].substring(1) + ' - ' + propertyLabels[1].charAt(0).toUpperCase() + propertyLabels[1].substring(1) + ' (' + groups[property].results.length + ')';
} else if (propertyLabels[0] === 'additional') {
finalPropertyLabel = 'Additional pages' + ' (' + groups[property].results.length + ')'
} else {
finalPropertyLabel = propertyLabels[0].charAt(0).toUpperCase() + propertyLabels[0].substring(1) + ' (' + groups[property].results.length + ')'
var $title = $('<h3>');
var $link = $('<a>', {
'href': res.url,
'text': res.title
});
var content = res.body.trim();
if (content.length > MAX_DESCRIPTION_SIZE) {
content = content.slice(0, MAX_DESCRIPTION_SIZE).trim()+'...';
}
var $groupTitle = $('<h3>', {
'text': finalPropertyLabel
});
$groupTitle.appendTo($li);
var $ulResults = $('<ul>', {
'class': 'search-results-list'
})
groups[property].results.forEach(function(res) {
var link = '';
var $liResult = $('<li>', {
'class': 'search-results-item'
});
switch (COMPODOC_CURRENT_PAGE_DEPTH) {
case 0:
link = './';
break;
case 1:
case 2:
case 3:
case 4:
case 5:
link = '../'.repeat(COMPODOC_CURRENT_PAGE_DEPTH);
break;
};
var finalResLabel = res.title.split(' - ')[1].charAt(0).toUpperCase() + res.title.split(' - ')[1].substring(1);
var $link = $('<a>', {
'href': link + res.url,
'text': finalResLabel
});
$link.appendTo($liResult);
$liResult.appendTo($ulResults);
});
$ulResults.appendTo($li);
var $content = $('<p>').html(content);
$link.appendTo($title);
$title.appendTo($li);
$content.appendTo($li);
$li.appendTo($searchList);
}
});
}
function launchSearch(q) {
@@ -117,7 +75,7 @@
$mainContainer.css('margin-top', '100px');
}
throttle(compodoc.search.query(q, 0, MAX_SEARCH_RESULTS)
throttle(compodoc.search.query(q, 0, MAX_RESULTS)
.then(function(results) {
displayResults(results);
}), 1000);
@@ -163,7 +121,6 @@
if (q.length == 0) {
closeSearch();
window.location.href = window.location.href.replace(window.location.search, '');
} else {
launchSearch(q);
}
@@ -195,9 +152,7 @@
// Update history state
if (usePushState) {
var uri = updateQueryString('q', $(this).val());
if ($(this).val() !== '') {
history.pushState({ path: uri }, null, uri);
}
history.pushState({ path: uri }, null, uri);
}
});
});

File diff suppressed because one or more lines are too long