This commit is contained in:
MarcRiera 2022-09-17 16:10:13 +00:00
parent 2e2e54e756
commit 8741cca729
242 changed files with 5054 additions and 1972 deletions

View file

@ -13,9 +13,32 @@ var touchsupport = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0)
var formelements = 'button, datalist, fieldset, input, label, legend, meter, optgroup, option, output, progress, select, textarea';
// rapidoc: #280 disable broad document syntax highlightning
window.Prism = window.Prism || {};
Prism.manual = true;
// PerfectScrollbar
var psc;
var psm;
var pst;
function scrollbarWidth(){
// https://davidwalsh.name/detect-scrollbar-width
// Create the measurement node
var scrollDiv = document.createElement("div");
scrollDiv.className = "scrollbar-measure";
document.body.appendChild(scrollDiv);
// Get the scrollbar width
var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth;
// Delete the DIV
document.body.removeChild(scrollDiv);
return scrollbarWidth;
}
function switchTab(tabGroup, tabId) {
allTabItems = jQuery("[data-tab-group='"+tabGroup+"']");
targetTabItems = jQuery("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']");
var tabs = jQuery(".tab-panel").has("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']");
var allTabItems = tabs.find("[data-tab-group='"+tabGroup+"']");
var targetTabItems = tabs.find("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']");
// if event is undefined then switchTab was called from restoreTabSelection
// so it's not a button event and we don't need to safe the selction or
@ -64,10 +87,10 @@ function restoreTabSelections() {
}
}
function initMermaid( update ) {
function initMermaid( update, attrs ) {
// we are either in update or initialization mode;
// during initialization, we want to edit the DOM;
// during update we only want to execute if something chanegd
// during update we only want to execute if something changed
var decodeHTML = function( html ){
var txt = document.createElement( 'textarea' );
txt.innerHTML = html;
@ -90,10 +113,9 @@ function initMermaid( update ) {
return '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n' + graph.content;
};
var init_func = function(){
state.is_initialized = true;
var init_func = function( attrs ){
var is_initialized = false;
var theme = variants.getColorValue( 'MERMAID-theme' );
var theme = attrs.theme;
document.querySelectorAll('.mermaid').forEach( function( element ){
var parse = parseGraph( decodeHTML( element.innerHTML ) );
@ -115,9 +137,9 @@ function initMermaid( update ) {
return is_initialized;
}
var update_func = function(){
var update_func = function( attrs ){
var is_initialized = false;
var theme = variants.getColorValue( 'MERMAID-theme' );
var theme = attrs.theme;
document.querySelectorAll( '.mermaid-container' ).forEach( function( e ){
var element = e.querySelector( '.mermaid' );
var code = e.querySelector( '.mermaid-code' );
@ -151,28 +173,66 @@ function initMermaid( update ) {
return;
}
var is_initialized = ( update ? update_func() : init_func() );
if( !state.is_initialized ){
state.is_initialized = true;
window.addEventListener( 'beforeprint', function(){
initMermaid( true, {
'theme': variants.getColorValue( 'PRINT-MERMAID-theme' ),
});
}.bind( this ) );
window.addEventListener( 'afterprint', function(){
initMermaid( true );
}.bind( this ) );
}
attrs = attrs || {
'theme': variants.getColorValue( 'MERMAID-theme' ),
};
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
if( is_initialized ){
mermaid.init();
$(".mermaid svg").svgPanZoom({});
}
}
function initSwagger( update ){
function initSwagger( update, attrs ){
var state = this;
if( update && !state.is_initialized ){
return;
}
if( typeof variants == 'undefined' ){
return;
}
var attrs = [
[ 'bg-color', variants.getColorValue( 'MAIN-BG-color' ) ],
[ 'mono-font', variants.getColorValue( 'CODE-font' ) ],
[ 'primary-color', variants.getColorValue( 'TAG-BG-color' ) ],
[ 'regular-font', variants.getColorValue( 'MAIN-font' ) ],
[ 'text-color', variants.getColorValue( 'MAIN-TEXT-color' ) ],
[ 'theme', variants.getColorValue( 'SWAGGER-theme' ) ],
];
if( !state.is_initialized ){
state.is_initialized = true;
window.addEventListener( 'beforeprint', function(){
initSwagger( true, {
'bg-color': variants.getColorValue( 'PRINT-MAIN-BG-color' ),
'mono-font': variants.getColorValue( 'PRINT-CODE-font' ),
'primary-color': variants.getColorValue( 'PRINT-TAG-BG-color' ),
'regular-font': variants.getColorValue( 'PRINT-MAIN-font' ),
'text-color': variants.getColorValue( 'PRINT-MAIN-TEXT-color' ),
'theme': variants.getColorValue( 'PRINT-SWAGGER-theme' ),
});
}.bind( this ) );
window.addEventListener( 'afterprint', function(){
initSwagger( true );
}.bind( this ) );
}
attrs = attrs || {
'bg-color': variants.getColorValue( 'MAIN-BG-color' ),
'mono-font': variants.getColorValue( 'CODE-font' ),
'primary-color': variants.getColorValue( 'TAG-BG-color' ),
'regular-font': variants.getColorValue( 'MAIN-font' ),
'text-color': variants.getColorValue( 'MAIN-TEXT-color' ),
'theme': variants.getColorValue( 'SWAGGER-theme' ),
};
document.querySelectorAll( 'rapi-doc' ).forEach( function( e ){
attrs.forEach( function( attr ){
e.setAttribute( attr[0], attr[1] );
Object.keys( attrs ).forEach( function( key ){
/* this doesn't work for FF 102, maybe related to custom elements? */
e.setAttribute( key, attrs[key] );
});
});
}
@ -219,10 +279,12 @@ function initCodeClipboard(){
}
$('code').each(function() {
var code = $(this),
text = code.text();
var code = $(this);
var text = code.text();
var parent = code.parent();
var inPre = parent.prop('tagName') == 'PRE';
if (text.length > 5) {
if (inPre || text.length > 5) {
var clip = new ClipboardJS('.copy-to-clipboard-button', {
text: function(trigger) {
var text = $(trigger).prev('code').text();
@ -249,8 +311,6 @@ function initCodeClipboard(){
});
});
var parent = code.parent();
var inPre = parent.prop('tagName') == 'PRE';
code.addClass('copy-to-clipboard-code');
if( inPre ){
parent.addClass( 'copy-to-clipboard' );
@ -268,6 +328,10 @@ function initCodeClipboard(){
}
function initArrowNav(){
if( isPrint ){
return;
}
// button navigation
jQuery(function() {
jQuery('a.nav-prev').click(function(){
@ -301,7 +365,10 @@ function initMenuScrollbar(){
return;
}
var content = '#body-inner';
var elc = document.querySelector('#body-inner');
var elm = document.querySelector('#content-wrapper');
var elt = document.querySelector('#TableOfContents');
var autofocus = false;
document.addEventListener('keydown', function(event){
// for initial keyboard scrolling support, no element
@ -311,42 +378,52 @@ function initMenuScrollbar(){
// it and give focus to the scrollbar - only
// to just remove the focus right after scrolling
// happend
var p = document.querySelector(content).matches(':hover');
var m = document.querySelector('#content-wrapper').matches(':hover');
var c = elc && elc.matches(':hover');
var m = elm && elm.matches(':hover');
var t = elt && elt.matches(':hover');
var f = event.target.matches( formelements );
if( !p && !m && !f ){
if( !c && !m && !t && !f ){
// only do this hack if none of our scrollbars
// is hovered
autofocus = true;
// if we are showing the sidebar as a flyout we
// want to scroll the content-wrapper, otherwise we want
// to scroll the body
var n = document.querySelector('body').matches('.sidebar-flyout');
if( n ){
psm.scrollbarY.focus();
var nt = document.querySelector('body').matches('.toc-flyout');
var nm = document.querySelector('body').matches('.sidebar-flyout');
if( nt ){
pst && pst.scrollbarY.focus();
}
else if( nm ){
psm && psm.scrollbarY.focus();
}
else{
psc.scrollbarY.focus();
document.querySelector('#body-inner').focus();
psc && psc.scrollbarY.focus();
}
}
});
// scrollbars will install their own keyboard handlers
// that need to be executed inbetween our own handlers
var psm = new PerfectScrollbar('#content-wrapper');
var psc = new PerfectScrollbar(content);
// PSC removed for #242 #243 #244
// psc = elc && new PerfectScrollbar('#body-inner');
psm = elm && new PerfectScrollbar('#content-wrapper');
pst = elt && new PerfectScrollbar('#TableOfContents');
document.addEventListener('keydown', function(){
// if we facked initial scrolling, we want to
// remove the focus to not leave visual markers on
// the scrollbar
if( autofocus ){
psc.scrollbarY.blur();
psm.scrollbarY.blur();
psc && psc.scrollbarY.blur();
psm && psm.scrollbarY.blur();
pst && pst.scrollbarY.blur();
autofocus = false;
}
});
// on resize, we have to redraw the scrollbars to let new height
// affect their size
window.addEventListener('resize', function(){
pst && pst.update();
psm && psm.update();
psc && psc.update();
});
@ -357,6 +434,20 @@ function initMenuScrollbar(){
psm && psm.update();
});
});
// finally, we want to adjust the contents right padding if there is a scrollbar visible
var scrollbarSize = scrollbarWidth();
function adjustContentWidth(){
var left = parseFloat( getComputedStyle( elc ).getPropertyValue( 'padding-left' ) );
var right = left;
if( elc.scrollHeight > elc.clientHeight ){
// if we have a scrollbar reduce the right margin by the scrollbar width
right = Math.max( 0, left - scrollbarSize );
}
elc.style[ 'padding-right' ] = '' + right + 'px';
}
window.addEventListener('resize', adjustContentWidth );
adjustContentWidth();
}
function initLightbox(){
@ -414,19 +505,119 @@ function initImageStyles(){
});
}
function sidebarEscapeHandler( event ){
if( event.key == "Escape" ){
var b = document.querySelector( 'body' );
b.classList.remove( 'sidebar-flyout' );
document.removeEventListener( 'keydown', sidebarEscapeHandler );
document.querySelector( '#body-inner' ).focus();
psc && psc.scrollbarY.focus();
}
}
function tocEscapeHandler( event ){
if( event.key == "Escape" ){
var b = document.querySelector( 'body' );
b.classList.remove( 'toc-flyout' );
document.removeEventListener( 'keydown', tocEscapeHandler );
document.querySelector( '#body-inner' ).focus();
psc && psc.scrollbarY.focus();
}
}
function sidebarShortcutHandler( event ){
if( event.altKey && event.ctrlKey && event.which == 77 /* m */ ){
showNav();
}
}
function tocShortcutHandler( event ){
if( event.altKey && event.ctrlKey && event.which == 84 /* t */ ){
showToc();
}
}
function editShortcutHandler( event ){
if( event.altKey && event.ctrlKey && event.which == 69 /* e */ ){
showEdit();
}
}
function printShortcutHandler( event ){
if( event.altKey && event.ctrlKey && event.which == 80 /* p */ ){
showPrint();
}
}
function showNav(){
if( !document.querySelector( '#sidebar-overlay' ) ){
// we may not have a flyout
return;
}
var b = document.querySelector( 'body' );
b.classList.toggle( 'sidebar-flyout' );
if( b.classList.contains( 'sidebar-flyout' ) ){
b.classList.remove( 'toc-flyout' );
document.removeEventListener( 'keydown', tocEscapeHandler );
document.addEventListener( 'keydown', sidebarEscapeHandler );
}
else{
document.removeEventListener( 'keydown', sidebarEscapeHandler );
document.querySelector( '#body-inner' ).focus();
psc && psc.scrollbarY.focus();
}
}
function showToc(){
var t = document.querySelector( '#toc-menu' );
if( !t ){
// we may not have a toc
return;
}
var b = document.querySelector( 'body' );
b.classList.toggle( 'toc-flyout' );
if( b.classList.contains( 'toc-flyout' ) ){
pst && pst.update();
document.addEventListener( 'keydown', tocEscapeHandler );
}
else{
document.removeEventListener( 'keydown', tocEscapeHandler );
document.querySelector( '#body-inner' ).focus();
psc && psc.scrollbarY.focus();
}
}
function showEdit(){
var l = document.querySelector( '#top-github-link a' );
if( l ){
l.click();
}
}
function showPrint(){
var l = document.querySelector( '#top-print-link a' );
if( l ){
l.click();
}
}
function initToc(){
function showNav(){
var b = document.querySelector( 'body' );
b.classList.toggle( 'sidebar-flyout' );
var n = b.matches('.sidebar-flyout');
if( n ){
b.classList.remove( 'toc-flyout' );
if( isPrint ){
return;
}
document.addEventListener( 'keydown', editShortcutHandler );
document.addEventListener( 'keydown', printShortcutHandler );
document.addEventListener( 'keydown', sidebarShortcutHandler );
document.addEventListener( 'keydown', tocShortcutHandler );
// avoid keyboard navigation for input fields
jQuery(formelements).keydown(function (e) {
if( e.altKey && event.ctrlKey ){
if( e.which == 77 /* m */ || e.which == 84 /* t */ || e.which == 69 /* e */ || e.which == 80 /* p */ ){
e.stopPropagation();
}
}
}
function showToc(){
var b = document.querySelector( 'body' );
b.classList.toggle( 'toc-flyout' );
}
});
document.querySelector( '#sidebar-overlay' ).addEventListener( 'click', showNav );
document.querySelector( '#sidebar-toggle' ).addEventListener( 'click', showNav );
@ -438,6 +629,10 @@ function initToc(){
t.addEventListener( 'click', showToc );
p.addEventListener( 'click', showToc );
}
// finally give initial focus to allow keyboard scrolling in FF
document.querySelector( '#body-inner' ).focus();
psc && psc.scrollbarY.focus();
}
function initSwipeHandler(){
@ -464,7 +659,11 @@ function initSwipeHandler(){
else if( diffx > 30 ){
startx = null;
starty = null;
document.querySelector( 'body' ).classList.toggle( 'sidebar-flyout' );
var b = document.querySelector( 'body' );
b.classList.remove( 'sidebar-flyout' );
document.removeEventListener( 'keydown', sidebarEscapeHandler );
document.querySelector( '#body-inner' ).focus();
psc && psc.scrollbarY.focus();
}
}
return false;
@ -486,6 +685,36 @@ function initSwipeHandler(){
document.querySelectorAll( '#sidebar *' ).forEach( function(e){ e.addEventListener("touchend", handleEndX); }, false);
}
function clearHistory() {
var visitedItem = baseUriFull + 'visited-url/'
for( var item in sessionStorage ){
if( item.substring( 0, visitedItem.length ) === visitedItem ){
sessionStorage.removeItem( item );
var url = item.substring( visitedItem.length );
// in case we have `relativeURLs=true` we have to strip the
// relative path to root
url = url.replace( /\.\.\//g, '/' ).replace( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').removeClass('visited');
}
}
}
function initHistory() {
var visitedItem = baseUriFull + 'visited-url/'
sessionStorage.setItem(visitedItem+jQuery('body').data('url'), 1);
// loop through the sessionStorage and see if something should be marked as visited
for( var item in sessionStorage ){
if( item.substring( 0, visitedItem.length ) === visitedItem && sessionStorage.getItem( item ) == 1 ){
var url = item.substring( visitedItem.length );
// in case we have `relativeURLs=true` we have to strip the
// relative path to root
url = url.replace( /\.\.\//g, '/' ).replace( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').addClass('visited');
}
}
}
function scrollToActiveMenu() {
window.setTimeout(function(){
var e = document.querySelector( '#sidebar ul.topics li.active a' );
@ -511,8 +740,81 @@ function scrollToFragment() {
}, 10);
}
function mark(){
var value = sessionStorage.getItem(baseUriFull+'search-value');
$(".highlightable").highlight(value, { element: 'mark' });
$("mark").parents(".expand").addClass("expand-marked");
$("mark").parents("li").each( function(){
var i = jQuery(this).children("input.toggle:not(.menu-marked)");
if( i.length ){
e = jQuery(i[0]);
e.attr("data-checked", (e.prop('checked')?"true":"false")).addClass("menu-marked");
i[0].checked = true;
}
});
psm && psm.update();
}
function unmark(){
sessionStorage.removeItem(baseUriFull+'search-value');
$("mark").parents("li").each( function(){
var i = jQuery(this).children("input.toggle.menu-marked");
if( i.length ){
e = jQuery(i[0]);
i[0].checked = (e.attr("data-checked")=="true");
e.attr("data-checked", null).removeClass("menu-marked");
}
});
$("mark").parents(".expand-marked").removeClass("expand-marked");
$(".highlightable").unhighlight({ element: 'mark' })
psm && psm.update();
}
function initSearch() {
jQuery('[data-search-input]').on('input', function() {
var input = jQuery(this);
var value = input.val();
unmark();
if (value.length) {
sessionStorage.setItem(baseUriFull+'search-value', value);
mark();
}
});
jQuery('[data-search-clear]').on('click', function() {
jQuery('[data-search-input]').val('').trigger('input');
unmark();
});
mark();
// custom sizzle case insensitive "contains" pseudo selector
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
// set initial search value on page load
if (sessionStorage.getItem(baseUriFull+'search-value')) {
var searchValue = sessionStorage.getItem(baseUriFull+'search-value')
$('[data-search-input]').val(searchValue);
$('[data-search-input]').trigger('input');
var searchedElem = $('#body-inner').find(':contains(' + searchValue + ')').get(0);
if (searchedElem) {
searchedElem.scrollIntoView(true);
var scrolledY = window.scrollY;
if(scrolledY){
window.scroll(0, scrolledY - 125);
}
}
}
// mark some additonal stuff as searchable
$('#topbar a:not(:has(img)):not(.btn)').addClass('highlight');
$('#body-inner a:not(:has(img)):not(.btn):not(a[rel="footnote"])').addClass('highlight');
}
// Get Parameters from some url
var getUrlParameter = function getUrlParameter(sPageURL) {
function getUrlParameter(sPageURL) {
var url = sPageURL.split('?');
var obj = {};
if (url.length == 2) {
@ -570,86 +872,8 @@ jQuery(function() {
initCodeClipboard();
restoreTabSelections();
initSwipeHandler();
jQuery('[data-clear-history-toggle]').on('click', function() {
for( var item in sessionStorage ){
if( item.substring( 0, baseUriFull.length ) === baseUriFull ){
sessionStorage.removeItem( item );
}
}
location.reload();
return false;
});
var ajax;
jQuery('[data-search-input]').on('input', function() {
var input = jQuery(this),
value = input.val(),
items = jQuery('[data-nav-id]');
items.removeClass('search-match');
if (!value.length) {
$('ul.topics').removeClass('searched');
items.css('display', 'block');
sessionStorage.removeItem(baseUriFull+'search-value');
$("mark").parents(".expand-marked").removeClass("expand-marked");
$(".highlightable").unhighlight({ element: 'mark' })
return;
}
sessionStorage.setItem(baseUriFull+'search-value', value);
$("mark").parents(".expand-marked").removeClass("expand-marked");
$(".highlightable").unhighlight({ element: 'mark' }).highlight(value, { element: 'mark' });
$("mark").parents(".expand").addClass("expand-marked");
if (ajax && ajax.abort) ajax.abort();
jQuery('[data-search-clear]').on('click', function() {
jQuery('[data-search-input]').val('').trigger('input');
sessionStorage.removeItem(baseUriFull+'search-input');
$("mark").parents(".expand-marked").removeClass("expand-marked");
$(".highlightable").unhighlight({ element: 'mark' })
});
});
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
return function( elem ) {
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
if (sessionStorage.getItem(baseUriFull+'search-value')) {
var searchValue = sessionStorage.getItem(baseUriFull+'search-value')
$('[data-search-input]').val(searchValue);
$('[data-search-input]').trigger('input');
var searchedElem = $('#body-inner').find(':contains(' + searchValue + ')').get(0);
if (searchedElem) {
searchedElem.scrollIntoView(true);
var scrolledY = window.scrollY;
if(scrolledY){
window.scroll(0, scrolledY - 125);
}
}
}
$(".highlightable").highlight(sessionStorage.getItem(baseUriFull+'search-value'), { element: 'mark' });
$("mark").parents(".expand").addClass("expand-marked");
$('#topbar a:not(:has(img)):not(.btn)').addClass('highlight');
$('#body-inner a:not(:has(img)):not(.btn):not(a[rel="footnote"])').addClass('highlight');
var visitedItem = baseUriFull + 'visited-url/'
sessionStorage.setItem(visitedItem+jQuery('body').data('url'), 1);
// loop through the sessionStorage and see if something should be marked as visited
for( var item in sessionStorage ){
if( item.substring( 0, visitedItem.length ) === visitedItem && sessionStorage.getItem( item ) == 1 ){
var url = item.substring( visitedItem.length );
// in case we have `relativeURLs=true` we have to strip the
// relative path to root
url = url.replace( /\.\.\//g, '/' ).replace( /^\/+\//, '/' );
jQuery('[data-nav-id="' + url + '"]').addClass('visited');
}
}
initHistory();
initSearch();
});
jQuery.extend({
@ -725,3 +949,30 @@ jQuery.fn.highlight = function(words, options) {
jQuery.highlight(this, re, settings.element, settings.className);
});
};
function useMermaid( config ){
if( !Object.assign ){
// We don't support Mermaid for IE11 anyways, so bail out early
return;
}
if (typeof mermaid != 'undefined' && typeof mermaid.mermaidAPI != 'undefined') {
mermaid.initialize( Object.assign( { "securityLevel": "antiscript", "startOnLoad": false }, config ) );
if( config.theme && variants ){
var write_style = variants.findLoadedStylesheet( 'variant-style' );
write_style.setProperty( '--CONFIG-MERMAID-theme', config.theme );
}
}
}
if( window.themeUseMermaid ){
useMermaid( window.themeUseMermaid );
}
function useSwagger( config ){
if( config.theme && variants ){
var write_style = variants.findLoadedStylesheet( 'variant-style' );
write_style.setProperty( '--CONFIG-SWAGGER-theme', config.theme );
}
}
if( window.themeUseSwagger ){
useSwagger( window.themeUseSwagger );
}