2022-11-17 21:13:11 +00:00
|
|
|
window.relearn = window.relearn || {};
|
|
|
|
|
2022-03-27 20:25:36 +00:00
|
|
|
var theme = true;
|
2022-02-28 00:20:19 +00:00
|
|
|
var isIE = /*@cc_on!@*/false || !!document.documentMode;
|
2022-03-13 13:16:08 +00:00
|
|
|
if( isIE ){
|
2022-02-28 00:20:19 +00:00
|
|
|
// we don't support sidebar flyout in IE
|
2022-03-13 13:16:08 +00:00
|
|
|
document.querySelector( 'body' ).classList.remove( 'mobile-support' );
|
|
|
|
}
|
|
|
|
else{
|
2022-02-28 00:20:19 +00:00
|
|
|
document.querySelector( 'body' ).classList.add( 'mobile-support' );
|
|
|
|
}
|
2023-05-14 21:06:26 +00:00
|
|
|
|
2022-04-02 13:30:16 +00:00
|
|
|
var isPrint = document.querySelector( 'body' ).classList.contains( 'print' );
|
|
|
|
|
2023-02-08 23:54:12 +00:00
|
|
|
var isRtl = document.querySelector( 'html' ).getAttribute( 'dir' ) == 'rtl';
|
|
|
|
var dir_padding_start = 'padding-left';
|
|
|
|
var dir_padding_end = 'padding-right';
|
|
|
|
var dir_key_start = 37;
|
|
|
|
var dir_key_end = 39;
|
|
|
|
var dir_scroll = 1;
|
|
|
|
if( isRtl && !isIE ){
|
|
|
|
dir_padding_start = 'padding-right';
|
|
|
|
dir_padding_end = 'padding-left';
|
|
|
|
dir_key_start = 39;
|
|
|
|
dir_key_end = 37;
|
|
|
|
dir_scroll = -1;
|
|
|
|
}
|
|
|
|
|
2022-02-28 00:20:19 +00:00
|
|
|
var touchsupport = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
|
|
|
|
|
2022-03-06 10:46:10 +00:00
|
|
|
var formelements = 'button, datalist, fieldset, input, label, legend, meter, optgroup, option, output, progress, select, textarea';
|
|
|
|
|
2022-06-06 21:58:37 +00:00
|
|
|
// PerfectScrollbar
|
|
|
|
var psc;
|
|
|
|
var psm;
|
|
|
|
var pst;
|
2022-11-17 16:48:48 +00:00
|
|
|
var elc = document.querySelector('#body-inner');
|
|
|
|
|
|
|
|
function documentFocus(){
|
2023-02-08 23:54:12 +00:00
|
|
|
elc.focus();
|
2022-11-17 16:48:48 +00:00
|
|
|
psc && psc.scrollbarY.focus();
|
|
|
|
}
|
2022-06-06 21:58:37 +00:00
|
|
|
|
2022-07-02 18:46:11 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:48:48 +00:00
|
|
|
var scrollbarSize = scrollbarWidth();
|
|
|
|
function adjustContentWidth(){
|
2023-02-08 23:54:12 +00:00
|
|
|
var start = parseFloat( getComputedStyle( elc ).getPropertyValue( dir_padding_start ) );
|
|
|
|
var end = start;
|
2022-11-17 16:48:48 +00:00
|
|
|
if( elc.scrollHeight > elc.clientHeight ){
|
2023-02-08 23:54:12 +00:00
|
|
|
// if we have a scrollbar reduce the end margin by the scrollbar width
|
|
|
|
end = Math.max( 0, start - scrollbarSize );
|
2022-11-17 16:48:48 +00:00
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
elc.style[ dir_padding_end ] = '' + end + 'px';
|
2022-11-17 16:48:48 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 16:16:06 +00:00
|
|
|
function fixCodeTabs(){
|
|
|
|
/* if only a single code block is contained in the tab and no style was selected, treat it like style=code */
|
2023-06-08 14:46:50 +00:00
|
|
|
var codeTabContents = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style' ) ).filter( function( tabContent ){
|
|
|
|
return tabContent.querySelector( '*:scope > .tab-content-text > div.highlight:only-child, *:scope > .tab-content-text > pre.pre-code:only-child');
|
2023-06-06 16:16:06 +00:00
|
|
|
});
|
|
|
|
|
2023-06-08 14:46:50 +00:00
|
|
|
codeTabContents.forEach( function( tabContent ){
|
|
|
|
var tabId = tabContent.dataset.tabItem;
|
|
|
|
var tabPanel = tabContent.parentNode.parentNode;
|
|
|
|
var tabButton = tabPanel.querySelector( '.tab-nav-button.tab-panel-style[data-tab-item="'+tabId+'"]' );
|
|
|
|
if( tabContent.classList.contains( 'initial' ) ){
|
2023-06-08 13:12:59 +00:00
|
|
|
tabButton.classList.remove( 'initial' );
|
|
|
|
tabButton.classList.add( 'code' );
|
2023-06-08 14:46:50 +00:00
|
|
|
tabContent.classList.remove( 'initial' );
|
|
|
|
tabContent.classList.add( 'code' );
|
2023-06-08 13:12:59 +00:00
|
|
|
}
|
|
|
|
// mark code blocks for FF without :has()
|
2023-06-08 14:46:50 +00:00
|
|
|
tabContent.classList.add( 'codify' );
|
2023-06-06 16:16:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-16 23:18:04 +00:00
|
|
|
function switchTab(tabGroup, tabId) {
|
2023-01-29 16:05:10 +00:00
|
|
|
var tabs = Array.from( document.querySelectorAll( '.tab-panel[data-tab-group="'+tabGroup+'"]' ) ).filter( function( e ){
|
|
|
|
return !!e.querySelector( '[data-tab-item="'+tabId+'"]' );
|
|
|
|
});
|
|
|
|
var allTabItems = tabs && tabs.reduce( function( a, e ){
|
2023-02-07 17:07:26 +00:00
|
|
|
return a.concat( Array.from( e.querySelectorAll( '[data-tab-item]' ) ).filter( function( es ){
|
|
|
|
return es.parentNode.parentNode == e;
|
|
|
|
}) );
|
2023-01-29 16:05:10 +00:00
|
|
|
}, [] );
|
|
|
|
var targetTabItems = tabs && tabs.reduce( function( a, e ){
|
2023-02-07 17:07:26 +00:00
|
|
|
return a.concat( Array.from( e.querySelectorAll( '[data-tab-item="'+tabId+'"]' ) ).filter( function( es ){
|
|
|
|
return es.parentNode.parentNode == e;
|
|
|
|
}) );
|
2023-01-29 16:05:10 +00:00
|
|
|
}, [] );
|
2021-10-16 23:18:04 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
// prevent page jump
|
2023-02-03 23:05:34 +00:00
|
|
|
var isButtonEvent = event && event.target && event.target.getBoundingClientRect;
|
2021-10-16 23:18:04 +00:00
|
|
|
if(isButtonEvent){
|
|
|
|
// save button position relative to viewport
|
|
|
|
var yposButton = event.target.getBoundingClientRect().top;
|
|
|
|
}
|
|
|
|
|
2023-01-29 16:05:10 +00:00
|
|
|
allTabItems && allTabItems.forEach( function( e ){ e.classList.remove( 'active' ); });
|
|
|
|
targetTabItems && targetTabItems.forEach( function( e ){ e.classList.add( 'active' ); });
|
2021-10-16 23:18:04 +00:00
|
|
|
|
|
|
|
if(isButtonEvent){
|
|
|
|
// reset screen to the same position relative to clicked button to prevent page jump
|
|
|
|
var yposButtonDiff = event.target.getBoundingClientRect().top - yposButton;
|
|
|
|
window.scrollTo(window.scrollX, window.scrollY+yposButtonDiff);
|
|
|
|
|
|
|
|
// Store the selection to make it persistent
|
|
|
|
if(window.localStorage){
|
2022-03-07 21:55:59 +00:00
|
|
|
var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections");
|
2021-10-16 23:18:04 +00:00
|
|
|
if(selectionsJSON){
|
|
|
|
var tabSelections = JSON.parse(selectionsJSON);
|
|
|
|
}else{
|
|
|
|
var tabSelections = {};
|
|
|
|
}
|
|
|
|
tabSelections[tabGroup] = tabId;
|
2022-03-07 21:55:59 +00:00
|
|
|
window.localStorage.setItem(baseUriFull+"tab-selections", JSON.stringify(tabSelections));
|
2021-10-16 23:18:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreTabSelections() {
|
|
|
|
if(window.localStorage){
|
2022-03-07 21:55:59 +00:00
|
|
|
var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections");
|
2021-10-16 23:18:04 +00:00
|
|
|
if(selectionsJSON){
|
|
|
|
var tabSelections = JSON.parse(selectionsJSON);
|
|
|
|
}else{
|
|
|
|
var tabSelections = {};
|
|
|
|
}
|
|
|
|
Object.keys(tabSelections).forEach(function(tabGroup) {
|
|
|
|
var tabItem = tabSelections[tabGroup];
|
|
|
|
switchTab(tabGroup, tabItem);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:58 +00:00
|
|
|
function initMermaid( update, attrs ) {
|
2022-03-27 20:25:36 +00:00
|
|
|
// we are either in update or initialization mode;
|
|
|
|
// during initialization, we want to edit the DOM;
|
2022-07-02 12:20:53 +00:00
|
|
|
// during update we only want to execute if something changed
|
2022-03-27 20:25:36 +00:00
|
|
|
var decodeHTML = function( html ){
|
|
|
|
var txt = document.createElement( 'textarea' );
|
|
|
|
txt.innerHTML = html;
|
|
|
|
return txt.value;
|
|
|
|
};
|
|
|
|
|
|
|
|
var parseGraph = function( graph ){
|
2023-06-09 19:48:05 +00:00
|
|
|
// See https://github.com/mermaid-js/mermaid/blob/9a080bb975b03b2b1d4ef6b7927d09e6b6b62760/packages/mermaid/src/diagram-api/frontmatter.ts#L10
|
|
|
|
// for reference on the regex originally taken from jekyll
|
|
|
|
var YAML=1;
|
|
|
|
var INIT=2;
|
|
|
|
var GRAPH=3;
|
|
|
|
var d = /^(?:\s*[\n\r])*(-{3}\s*[\n\r](?:.*?)[\n\r]-{3}(?:\s*[\n\r]+)+)?(?:\s*(?:%%\s*\{\s*\w+\s*:([^%]*?)%%\s*[\n\r]?))?(.*)$/s
|
2022-03-27 20:25:36 +00:00
|
|
|
var m = d.exec( graph );
|
2023-06-09 19:48:05 +00:00
|
|
|
var yaml = '';
|
2022-03-27 20:25:36 +00:00
|
|
|
var dir = {};
|
|
|
|
var content = graph;
|
2023-06-09 19:48:05 +00:00
|
|
|
if( m && m.length == 4 ){
|
|
|
|
yaml = m[YAML] ? m[YAML] : yaml;
|
|
|
|
dir = m[INIT] ? JSON.parse( '{ "init": ' + m[INIT] ).init : dir;
|
|
|
|
content = m[GRAPH] ? m[GRAPH] : content;
|
2022-03-27 20:25:36 +00:00
|
|
|
}
|
2023-06-09 19:48:05 +00:00
|
|
|
var ret = { yaml: yaml, dir: dir, content: content.trim() }
|
|
|
|
return ret;
|
2022-03-27 20:25:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var serializeGraph = function( graph ){
|
2023-06-09 19:48:05 +00:00
|
|
|
var s = graph.yaml + '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n' + graph.content;
|
2022-11-18 23:02:20 +00:00
|
|
|
return s;
|
2022-03-27 20:25:36 +00:00
|
|
|
};
|
|
|
|
|
2022-07-29 19:55:58 +00:00
|
|
|
var init_func = function( attrs ){
|
2022-03-27 20:25:36 +00:00
|
|
|
var is_initialized = false;
|
2022-07-29 19:55:58 +00:00
|
|
|
var theme = attrs.theme;
|
2022-03-19 19:19:27 +00:00
|
|
|
document.querySelectorAll('.mermaid').forEach( function( element ){
|
2022-03-27 20:25:36 +00:00
|
|
|
var parse = parseGraph( decodeHTML( element.innerHTML ) );
|
2022-03-19 19:19:27 +00:00
|
|
|
|
2022-03-27 20:25:36 +00:00
|
|
|
if( parse.dir.theme ){
|
|
|
|
parse.dir.relearn_user_theme = true;
|
2022-03-19 19:19:27 +00:00
|
|
|
}
|
2022-03-27 20:25:36 +00:00
|
|
|
if( !parse.dir.relearn_user_theme ){
|
|
|
|
parse.dir.theme = theme;
|
2022-03-19 19:19:27 +00:00
|
|
|
}
|
2022-03-27 20:25:36 +00:00
|
|
|
is_initialized = true;
|
2022-03-19 19:19:27 +00:00
|
|
|
|
2022-03-27 20:25:36 +00:00
|
|
|
var graph = serializeGraph( parse );
|
|
|
|
element.innerHTML = graph;
|
2022-03-19 19:19:27 +00:00
|
|
|
var new_element = document.createElement( 'div' );
|
|
|
|
new_element.classList.add( 'mermaid-container' );
|
2022-03-27 20:25:36 +00:00
|
|
|
new_element.innerHTML = '<div class="mermaid-code">' + graph + '</div>' + element.outerHTML;
|
2022-03-19 19:19:27 +00:00
|
|
|
element.parentNode.replaceChild( new_element, element );
|
|
|
|
});
|
2022-03-27 20:25:36 +00:00
|
|
|
return is_initialized;
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:58 +00:00
|
|
|
var update_func = function( attrs ){
|
2022-03-27 20:25:36 +00:00
|
|
|
var is_initialized = false;
|
2022-07-29 19:55:58 +00:00
|
|
|
var theme = attrs.theme;
|
2022-03-27 20:25:36 +00:00
|
|
|
document.querySelectorAll( '.mermaid-container' ).forEach( function( e ){
|
|
|
|
var element = e.querySelector( '.mermaid' );
|
|
|
|
var code = e.querySelector( '.mermaid-code' );
|
|
|
|
var parse = parseGraph( decodeHTML( code.innerHTML ) );
|
|
|
|
|
|
|
|
if( parse.dir.relearn_user_theme ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( parse.dir.theme == theme ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
is_initialized = true;
|
|
|
|
|
|
|
|
parse.dir.theme = theme;
|
|
|
|
var graph = serializeGraph( parse );
|
|
|
|
element.removeAttribute('data-processed');
|
|
|
|
element.innerHTML = graph;
|
|
|
|
code.innerHTML = graph;
|
|
|
|
});
|
|
|
|
return is_initialized;
|
|
|
|
};
|
|
|
|
|
|
|
|
var state = this;
|
|
|
|
if( update && !state.is_initialized ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( typeof variants == 'undefined' ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( typeof mermaid == 'undefined' || typeof mermaid.mermaidAPI == 'undefined' ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:58 +00:00
|
|
|
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' ),
|
|
|
|
};
|
2023-02-03 23:08:40 +00:00
|
|
|
|
|
|
|
var search;
|
|
|
|
if( update ){
|
|
|
|
search = sessionStorage.getItem( baseUriFull+'search-value' );
|
|
|
|
unmark();
|
|
|
|
}
|
2022-07-29 19:55:58 +00:00
|
|
|
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
|
2022-03-27 20:25:36 +00:00
|
|
|
if( is_initialized ){
|
2022-03-19 19:19:27 +00:00
|
|
|
mermaid.init();
|
2023-02-04 00:55:05 +00:00
|
|
|
// zoom for Mermaid
|
|
|
|
// https://github.com/mermaid-js/mermaid/issues/1860#issuecomment-1345440607
|
2023-02-05 10:13:50 +00:00
|
|
|
var svgs = d3.selectAll( '.mermaid.zoom svg' );
|
2023-02-04 00:55:05 +00:00
|
|
|
svgs.each( function(){
|
|
|
|
var svg = d3.select( this );
|
|
|
|
svg.html( '<g>' + svg.html() + '</g>' );
|
|
|
|
var inner = svg.select( 'g' );
|
|
|
|
var zoom = d3.zoom().on( 'zoom', function( e ){
|
|
|
|
inner.attr( 'transform', e.transform);
|
|
|
|
});
|
|
|
|
svg.call( zoom );
|
|
|
|
});
|
2021-10-16 23:18:04 +00:00
|
|
|
}
|
2023-02-03 23:08:40 +00:00
|
|
|
if( update && search && search.length ){
|
|
|
|
sessionStorage.setItem( baseUriFull+'search-value', search );
|
|
|
|
mark();
|
|
|
|
}
|
2021-10-16 23:18:04 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 21:06:26 +00:00
|
|
|
function initOpenapi( update, attrs ){
|
|
|
|
if( isIE ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:58 +00:00
|
|
|
var state = this;
|
|
|
|
if( update && !state.is_initialized ){
|
|
|
|
return;
|
|
|
|
}
|
2022-03-27 20:25:36 +00:00
|
|
|
if( typeof variants == 'undefined' ){
|
|
|
|
return;
|
|
|
|
}
|
2022-07-29 19:55:58 +00:00
|
|
|
|
|
|
|
if( !state.is_initialized ){
|
|
|
|
state.is_initialized = true;
|
|
|
|
window.addEventListener( 'beforeprint', function(){
|
2023-05-14 21:06:26 +00:00
|
|
|
initOpenapi( true, { isPrintPreview: true } );
|
2022-07-29 19:55:58 +00:00
|
|
|
}.bind( this ) );
|
|
|
|
window.addEventListener( 'afterprint', function(){
|
2023-05-14 21:06:26 +00:00
|
|
|
initOpenapi( true, { isPrintPreview: false } );
|
2022-07-29 19:55:58 +00:00
|
|
|
}.bind( this ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs = attrs || {
|
2023-05-14 21:06:26 +00:00
|
|
|
isPrintPreview: false
|
2022-07-29 19:55:58 +00:00
|
|
|
};
|
2023-05-14 21:06:26 +00:00
|
|
|
|
|
|
|
function addFunctionToResizeEvent(){
|
|
|
|
|
|
|
|
}
|
|
|
|
function getFirstAncestorByClass(){
|
|
|
|
|
|
|
|
}
|
|
|
|
function renderOpenAPI(oc) {
|
|
|
|
var buster = window.themeUseOpenapi.assetsBuster ? '?' + window.themeUseOpenapi.assetsBuster : '';
|
|
|
|
var print = isPrint || attrs.isPrintPreview ? "PRINT-" : "";
|
|
|
|
var theme = print ? `${baseUri}/css/theme-relearn-light.css` : document.querySelector( '#variant-style' ).attributes.href.value
|
|
|
|
var swagger_theme = variants.getColorValue( print + 'OPENAPI-theme' );
|
|
|
|
var swagger_code_theme = variants.getColorValue( print + 'OPENAPI-CODE-theme' );
|
|
|
|
|
|
|
|
const openapiId = 'relearn-swagger-ui';
|
|
|
|
const openapiIframeId = openapiId + "-iframe";
|
|
|
|
const openapiIframe = document.getElementById(openapiIframeId);
|
|
|
|
if (openapiIframe) {
|
|
|
|
openapiIframe.remove();
|
|
|
|
}
|
|
|
|
const openapiErrorId = openapiId + '-error';
|
|
|
|
const openapiError = document.getElementById(openapiErrorId);
|
|
|
|
if (openapiError) {
|
|
|
|
openapiError.remove();
|
|
|
|
}
|
|
|
|
const oi = document.createElement('iframe');
|
|
|
|
oi.id = openapiIframeId;
|
|
|
|
oi.classList.toggle('sc-openapi-iframe', true);
|
|
|
|
oi.srcdoc =
|
|
|
|
'<!doctype html>' +
|
|
|
|
'<html lang="en">' +
|
|
|
|
'<head>' +
|
|
|
|
'<link rel="stylesheet" href="' + window.themeUseOpenapi.css + '">' +
|
|
|
|
'<link rel="stylesheet" href="' + theme + '">' +
|
|
|
|
'<link rel="stylesheet" href="' + baseUri + '/css/swagger.css' + buster + '">' +
|
|
|
|
'<link rel="stylesheet" href="' + baseUri + '/css/swagger-' + swagger_theme + '.css' + buster + '">' +
|
|
|
|
'</head>' +
|
|
|
|
'<body>' +
|
|
|
|
'<a class="relearn-expander" href="" onclick="return relearn_collapse_all()">Collapse all</a>' +
|
|
|
|
'<a class="relearn-expander" href="" onclick="return relearn_expand_all()">Exapnd all</a>' +
|
|
|
|
'<div id="relearn-swagger-ui"></div>' +
|
|
|
|
'<script>' +
|
|
|
|
'function relearn_expand_all(){' +
|
|
|
|
'document.querySelectorAll( ".opblock-summary-control[aria-expanded=false]" ).forEach( btn => btn.click() );' +
|
|
|
|
'document.querySelectorAll( ".model-container > .model-box > button[aria-expanded=false]" ).forEach( btn => btn.click() );' +
|
|
|
|
'return false;' +
|
|
|
|
'}' +
|
|
|
|
'function relearn_collapse_all(){' +
|
|
|
|
'document.querySelectorAll( ".opblock-summary-control[aria-expanded=true]" ).forEach( btn => btn.click() );' +
|
|
|
|
'document.querySelectorAll( ".model-container > .model-box > .model-box > .model > span > button[aria-expanded=true]" ).forEach( btn => btn.click() );' +
|
|
|
|
'return false;' +
|
|
|
|
'}' +
|
|
|
|
'</script>' +
|
|
|
|
'</body>' +
|
|
|
|
'</html>';
|
|
|
|
oi.height = '100%';
|
|
|
|
oi.width = '100%';
|
|
|
|
oi.onload = function(){
|
|
|
|
const openapiWrapper = getFirstAncestorByClass(oc, 'sc-openapi-wrapper');
|
|
|
|
const openapiPromise = new Promise( function(resolve){ resolve() });
|
|
|
|
openapiPromise
|
|
|
|
.then( function(){
|
|
|
|
SwaggerUIBundle({
|
|
|
|
defaultModelsExpandDepth: 2,
|
|
|
|
defaultModelExpandDepth: 2,
|
|
|
|
docExpansion: isPrint || attrs.isPrintPreview ? 'full' : 'list',
|
|
|
|
domNode: oi.contentWindow.document.getElementById(openapiId),
|
|
|
|
filter: !( isPrint || attrs.isPrintPreview ),
|
|
|
|
layout: 'BaseLayout',
|
|
|
|
onComplete: function(){
|
|
|
|
if( isPrint || attrs.isPrintPreview ){
|
|
|
|
oi.contentWindow.document.querySelectorAll( '.model-container > .model-box > button[aria-expanded=false]' ).forEach( function(btn){ btn.click() });
|
|
|
|
setOpenAPIHeight(oi);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
SwaggerUIBundle.plugins.DownloadUrl
|
|
|
|
],
|
|
|
|
presets: [
|
|
|
|
SwaggerUIBundle.presets.apis,
|
|
|
|
SwaggerUIStandalonePreset,
|
|
|
|
],
|
|
|
|
syntaxHighlight: {
|
|
|
|
activated: true,
|
|
|
|
theme: swagger_code_theme,
|
|
|
|
},
|
|
|
|
url: oc.getAttribute('openapi-url'),
|
|
|
|
validatorUrl: 'none',
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then( function(){
|
|
|
|
let observerCallback = function () {
|
|
|
|
setOpenAPIHeight(oi);
|
|
|
|
};
|
|
|
|
let observer = new MutationObserver(observerCallback);
|
|
|
|
observer.observe(oi.contentWindow.document.documentElement, {
|
|
|
|
childList: true,
|
|
|
|
subtree: true,
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then( function(){
|
|
|
|
if (openapiWrapper) {
|
|
|
|
openapiWrapper.classList.toggle('is-loading', false);
|
|
|
|
}
|
|
|
|
setOpenAPIHeight(oi);
|
|
|
|
})
|
|
|
|
.catch( function(error){
|
|
|
|
const ed = document.createElement('div');
|
|
|
|
ed.classList.add('sc-alert', 'sc-alert-error');
|
|
|
|
ed.innerHTML = error;
|
|
|
|
ed.id = openapiErrorId;
|
|
|
|
while (oc.lastChild) {
|
|
|
|
oc.removeChild(oc.lastChild);
|
|
|
|
}
|
|
|
|
if (openapiWrapper) {
|
|
|
|
openapiWrapper.classList.toggle('is-loading', false);
|
|
|
|
openapiWrapper.insertAdjacentElement('afterbegin', ed);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
oc.appendChild(oi);
|
|
|
|
}
|
|
|
|
function setOpenAPIHeight(oi) {
|
|
|
|
// add empirical offset if in print preview (GC 103)
|
|
|
|
oi.style.height =
|
|
|
|
(oi.contentWindow.document.documentElement.getBoundingClientRect().height + (attrs.isPrintPreview ? 200 : 0) )+
|
|
|
|
'px';
|
|
|
|
}
|
|
|
|
function resizeOpenAPI() {
|
|
|
|
let divi = document.getElementsByClassName('sc-openapi-iframe');
|
|
|
|
for (let i = 0; i < divi.length; i++) {
|
|
|
|
setOpenAPIHeight(divi[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let divo = document.getElementsByClassName('sc-openapi-container');
|
|
|
|
for (let i = 0; i < divo.length; i++) {
|
|
|
|
renderOpenAPI(divo[i]);
|
|
|
|
}
|
|
|
|
if (divo.length) {
|
|
|
|
addFunctionToResizeEvent(resizeOpenAPI);
|
|
|
|
}
|
2022-03-27 20:25:36 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 22:25:58 +00:00
|
|
|
function initAnchorClipboard(){
|
2023-05-19 11:00:10 +00:00
|
|
|
document.querySelectorAll( 'h1~h2,h1~h3,h1~h4,h1~h5,h1~h6').forEach( function( element ){
|
2023-02-20 12:55:42 +00:00
|
|
|
var url = encodeURI( (document.location.origin == "null" ? (document.location.protocol + "//" + document.location.host) : document.location.origin )+ document.location.pathname);
|
2023-02-03 22:26:54 +00:00
|
|
|
var link = url + "#" + element.id;
|
2022-03-25 14:35:54 +00:00
|
|
|
var new_element = document.createElement( 'span' );
|
|
|
|
new_element.classList.add( 'anchor' );
|
|
|
|
new_element.setAttribute( 'title', window.T_Copy_link_to_clipboard );
|
|
|
|
new_element.setAttribute( 'data-clipboard-text', link );
|
|
|
|
new_element.innerHTML = '<i class="fas fa-link fa-lg"></i>';
|
2022-04-03 13:22:14 +00:00
|
|
|
element.appendChild( new_element );
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
|
|
|
|
2023-02-03 22:26:54 +00:00
|
|
|
var anchors = document.querySelectorAll( '.anchor' );
|
|
|
|
for( var i = 0; i < anchors.length; i++ ) {
|
|
|
|
anchors[i].addEventListener( 'mouseleave', function( e ){
|
|
|
|
this.removeAttribute( 'aria-label' );
|
|
|
|
this.classList.remove( 'tooltipped', 'tooltipped-se', 'tooltipped-sw' );
|
|
|
|
});
|
|
|
|
}
|
2022-02-25 22:25:58 +00:00
|
|
|
|
2023-02-03 22:26:54 +00:00
|
|
|
var clip = new ClipboardJS( '.anchor' );
|
|
|
|
clip.on( 'success', function( e ){
|
2022-02-25 22:25:58 +00:00
|
|
|
e.clearSelection();
|
2023-02-03 22:26:54 +00:00
|
|
|
e.trigger.setAttribute( 'aria-label', window.T_Link_copied_to_clipboard );
|
2023-02-09 23:35:46 +00:00
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-s'+(isRtl?'e':'w') );
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initCodeClipboard(){
|
2023-06-16 19:15:05 +00:00
|
|
|
function getCodeText( node ){
|
|
|
|
var text = node.textContent;
|
|
|
|
// remove a trailing line break, this may most likely
|
|
|
|
// come from the browser / Hugo transformation
|
|
|
|
text = text.replace( /\n$/, '' );
|
|
|
|
// removes leading $ signs from text in an assumption
|
|
|
|
// that this has to be the unix prompt marker - weird
|
|
|
|
return text.replace( /^\$\s/gm, '' );
|
|
|
|
}
|
|
|
|
|
2023-02-03 22:26:54 +00:00
|
|
|
function fallbackMessage( action ){
|
2022-02-25 22:25:58 +00:00
|
|
|
var actionMsg = '';
|
|
|
|
var actionKey = (action === 'cut' ? 'X' : 'C');
|
|
|
|
if (/iPhone|iPad/i.test(navigator.userAgent)) {
|
|
|
|
actionMsg = 'No support :(';
|
|
|
|
}
|
|
|
|
else if (/Mac/i.test(navigator.userAgent)) {
|
|
|
|
actionMsg = 'Press ⌘-' + actionKey + ' to ' + action;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
actionMsg = 'Press Ctrl-' + actionKey + ' to ' + action;
|
|
|
|
}
|
|
|
|
return actionMsg;
|
|
|
|
}
|
|
|
|
|
2023-06-16 19:15:05 +00:00
|
|
|
if( !window.disableHighlightWrapFix ){
|
|
|
|
// if the highlight shortcode was used with table lineno mode, the generated DOM
|
|
|
|
// is a table, containg exactly one row with two cells, the first cell for all linenos
|
|
|
|
// the second with the code;
|
|
|
|
// this does not look nice if the code gets wrapped around, so we reformat the table
|
|
|
|
// by creating a row for each line, containing the two cells but with only the content of
|
|
|
|
// one line
|
|
|
|
var codeTables = Array.from( document.querySelectorAll( 'code' ) ).reduce( function(a, code){
|
|
|
|
// collect all tbody's without duplicates that need our treatment
|
|
|
|
if( code.parentNode.tagName.toLowerCase() == 'pre' &&
|
|
|
|
code.parentNode.parentNode.tagName.toLowerCase() == 'td' &&
|
|
|
|
code.parentNode.parentNode.parentNode.tagName.toLowerCase() == 'tr' &&
|
|
|
|
code.parentNode.parentNode.parentNode.parentNode.tagName.toLowerCase() == 'tbody' &&
|
|
|
|
code.parentNode.parentNode.parentNode.querySelector( 'td:first-child > pre > code' ) == code &&
|
|
|
|
( !a.length || a[a.length-1] != code.parentNode.parentNode.parentNode.parentNode ) ){
|
|
|
|
var table = code.parentNode.parentNode.parentNode.parentNode;
|
|
|
|
a.push( table );
|
|
|
|
}
|
|
|
|
return a;
|
|
|
|
}, [] );
|
|
|
|
for( var i = 0; i < codeTables.length; i++ ){
|
|
|
|
// now treat the table (tbody);
|
|
|
|
// first we collect some data, setting up our row template and collect the text
|
|
|
|
// representation of the code for later usage with copy-to-clipboard
|
|
|
|
var table = codeTables[i];
|
|
|
|
var text = getCodeText( table.querySelector( 'td:last-child code' ) );
|
|
|
|
var tr = table.querySelector( 'tr' ).cloneNode();
|
|
|
|
tr.appendChild( table.querySelector( 'td:first-child' ).cloneNode() )
|
|
|
|
.appendChild( table.querySelector( 'td:first-child pre' ).cloneNode() )
|
|
|
|
.appendChild( table.querySelector( 'td:first-child code' ).cloneNode() )
|
|
|
|
.classList.add( 'nocode' );
|
|
|
|
tr.appendChild( table.querySelector( 'td:last-child' ).cloneNode() )
|
|
|
|
.appendChild( table.querySelector( 'td:last-child pre' ).cloneNode() )
|
|
|
|
.appendChild( table.querySelector( 'td:last-child code' ).cloneNode() )
|
|
|
|
.classList.add( 'nocode' );
|
|
|
|
|
|
|
|
// select lineno and code cell of first line that contains all the content
|
|
|
|
var linenums = table.querySelectorAll( 'td:first-child code > span' );
|
|
|
|
var codes = table.querySelectorAll( 'td:last-child code > span' );
|
|
|
|
for( var j = 0; j < linenums.length; j++ ){
|
|
|
|
// now create a new table row by cloning our template
|
|
|
|
// and transfering the original content
|
|
|
|
var clonedTr = tr.cloneNode(true);
|
|
|
|
var code1 = clonedTr.querySelector( 'td:first-child code' );
|
|
|
|
var code2 = clonedTr.querySelector( 'td:last-child code' );
|
|
|
|
code1.appendChild( linenums[j] );
|
|
|
|
code2.appendChild( codes[j] );
|
|
|
|
table.appendChild( clonedTr );
|
|
|
|
}
|
|
|
|
// in the end we have an empty first row, that needs to be deleted
|
|
|
|
table.querySelector( 'tr:first-child' ).remove();
|
|
|
|
// we delete the reformat marker of the first code cell to allow the
|
|
|
|
// copy-to-clipboard functionality
|
|
|
|
table.querySelector( 'tr:first-child td:last-child code' ).classList.remove( 'nocode' );
|
|
|
|
// put the text representation into a data attribute
|
|
|
|
table.querySelector( 'tr:first-child td:last-child code' ).dataset[ 'code' ] = text;
|
|
|
|
// finally mark our tbody to apply special CSS styling
|
|
|
|
table.parentNode.parentNode.parentNode.classList.add( 'wrapfix' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var codeElements = document.querySelectorAll( 'code:not(.nocode)' );
|
2023-02-03 22:26:54 +00:00
|
|
|
for( var i = 0; i < codeElements.length; i++ ){
|
|
|
|
var code = codeElements[i];
|
|
|
|
var text = code.textContent;
|
2023-02-04 21:51:04 +00:00
|
|
|
var inPre = code.parentNode.tagName.toLowerCase() == 'pre';
|
2023-06-15 21:18:24 +00:00
|
|
|
// avoid copy-to-clipboard for highlight shortcode in table lineno mode
|
2023-06-16 19:15:05 +00:00
|
|
|
var isFirstLineCell = inPre &&
|
2023-06-15 21:18:24 +00:00
|
|
|
code.parentNode.parentNode.tagName.toLowerCase() == 'td' &&
|
2023-06-16 19:15:05 +00:00
|
|
|
code.parentNode.parentNode.parentNode.querySelector( 'td:first-child > pre > code' ) == code;
|
2023-02-03 22:26:54 +00:00
|
|
|
|
2023-06-16 19:15:05 +00:00
|
|
|
if( !isFirstLineCell && ( inPre || text.length > 5 ) ){
|
2023-02-03 22:26:54 +00:00
|
|
|
var clip = new ClipboardJS( '.copy-to-clipboard-button', {
|
|
|
|
text: function( trigger ){
|
2023-06-15 17:38:49 +00:00
|
|
|
if( !( trigger.previousElementSibling && trigger.previousElementSibling.matches( 'code' ) ) ){
|
|
|
|
return '';
|
|
|
|
}
|
2023-06-16 19:15:05 +00:00
|
|
|
// if we already have a text representation, return it
|
|
|
|
var code = trigger.previousElementSibling;
|
|
|
|
if( code.dataset.code ){
|
|
|
|
return code.dataset.code;
|
|
|
|
}
|
2023-06-15 17:38:49 +00:00
|
|
|
// if highlight shortcode used in inline lineno mode, remove lineno nodes before generating text
|
2023-06-16 19:15:05 +00:00
|
|
|
code = code.cloneNode( true );
|
|
|
|
Array.from( code.querySelectorAll( '*:scope > span > span:first-child:not(:last-child)' ) ).forEach( function( lineno ){
|
2023-06-15 17:38:49 +00:00
|
|
|
lineno.remove();
|
|
|
|
});
|
2023-06-16 19:15:05 +00:00
|
|
|
// generate and save generated text for repeated usage
|
|
|
|
var text = getCodeText( code );
|
|
|
|
trigger.previousElementSibling.dataset[ 'code' ] = text;
|
|
|
|
return text;
|
2022-02-25 22:25:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-02-03 22:26:54 +00:00
|
|
|
clip.on( 'success', function( e ){
|
2022-02-25 22:25:58 +00:00
|
|
|
e.clearSelection();
|
2023-02-24 23:33:36 +00:00
|
|
|
var inPre = e.trigger.parentNode.tagName.toLowerCase() == 'pre';
|
2023-02-03 22:26:54 +00:00
|
|
|
e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard );
|
2023-02-09 23:35:46 +00:00
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (inPre ? 'w' : 's'+(isRtl?'e':'w')) );
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
|
|
|
|
2023-02-03 22:26:54 +00:00
|
|
|
clip.on( 'error', function( e ){
|
2023-02-24 23:33:36 +00:00
|
|
|
var inPre = e.trigger.parentNode.tagName.toLowerCase() == 'pre';
|
2023-02-03 22:26:54 +00:00
|
|
|
e.trigger.setAttribute( 'aria-label', fallbackMessage(e.action) );
|
2023-02-09 23:35:46 +00:00
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (inPre ? 'w' : 's'+(isRtl?'e':'w')) );
|
2023-02-03 22:26:54 +00:00
|
|
|
var f = function(){
|
|
|
|
e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard );
|
2023-02-09 23:35:46 +00:00
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (inPre ? 'w' : 's'+(isRtl?'e':'w')) );
|
2023-02-03 22:26:54 +00:00
|
|
|
document.removeEventListener( 'copy', f );
|
|
|
|
};
|
|
|
|
document.addEventListener( 'copy', f );
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
|
|
|
|
2023-02-03 22:26:54 +00:00
|
|
|
code.classList.add( 'copy-to-clipboard-code' );
|
2022-02-25 22:25:58 +00:00
|
|
|
if( inPre ){
|
2023-02-03 22:26:54 +00:00
|
|
|
code.classList.add( 'copy-to-clipboard' );
|
2023-02-24 23:06:37 +00:00
|
|
|
code.parentNode.classList.add( 'pre-code' );
|
2022-02-25 22:25:58 +00:00
|
|
|
}
|
|
|
|
else{
|
2023-02-03 22:26:54 +00:00
|
|
|
var clone = code.cloneNode( true );
|
|
|
|
var span = document.createElement( 'span' );
|
|
|
|
span.classList.add( 'copy-to-clipboard' );
|
|
|
|
span.appendChild( clone );
|
2023-02-04 21:51:04 +00:00
|
|
|
code.parentNode.replaceChild( span, code );
|
2023-02-03 22:26:54 +00:00
|
|
|
code = clone;
|
2022-02-25 22:25:58 +00:00
|
|
|
}
|
2023-02-03 22:26:54 +00:00
|
|
|
var button = document.createElement( 'span' );
|
|
|
|
button.classList.add( 'copy-to-clipboard-button' );
|
|
|
|
button.setAttribute( 'title', window.T_Copy_to_clipboard );
|
|
|
|
button.innerHTML = '<i class="fas fa-copy"></i>';
|
|
|
|
button.addEventListener( 'mouseleave', function() {
|
|
|
|
this.removeAttribute( 'aria-label' );
|
|
|
|
this.classList.remove( 'tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw' );
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
2023-02-04 21:51:04 +00:00
|
|
|
code.parentNode.insertBefore( button, code.nextSibling );
|
2022-02-25 22:25:58 +00:00
|
|
|
}
|
2023-02-03 22:26:54 +00:00
|
|
|
}
|
2022-02-25 22:25:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function initArrowNav(){
|
2022-07-03 11:31:55 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-25 22:25:58 +00:00
|
|
|
// button navigation
|
2023-02-04 00:55:05 +00:00
|
|
|
var prev = document.querySelector( 'a.nav-prev' );
|
|
|
|
prev && prev.addEventListener( 'click', navPrev );
|
|
|
|
var next = document.querySelector( 'a.nav-next' );
|
|
|
|
next && next.addEventListener( 'click', navNext );
|
2022-02-25 22:25:58 +00:00
|
|
|
|
|
|
|
// keyboard navigation
|
2023-01-22 22:47:56 +00:00
|
|
|
// avoid prev/next navigation if we are not at the start/end of the
|
|
|
|
// horizontal area
|
|
|
|
var el = document.querySelector('#body-inner');
|
2023-02-08 23:54:12 +00:00
|
|
|
var scrollStart = 0;
|
|
|
|
var scrollEnd = 0;
|
2023-01-22 22:47:56 +00:00
|
|
|
document.addEventListener('keydown', function(event){
|
|
|
|
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
|
2023-02-08 23:54:12 +00:00
|
|
|
if( event.which == dir_key_start ){
|
|
|
|
if( !scrollStart && +el.scrollLeft.toFixed()*dir_scroll <= 0 ){
|
2023-02-04 00:55:05 +00:00
|
|
|
prev && prev.click();
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
else if( scrollStart != -1 ){
|
|
|
|
clearTimeout( scrollStart );
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
scrollStart = -1;
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
if( event.which == dir_key_end ){
|
|
|
|
if( !scrollEnd && +el.scrollLeft.toFixed()*dir_scroll + +el.clientWidth.toFixed() >= +el.scrollWidth.toFixed() ){
|
2023-02-04 00:55:05 +00:00
|
|
|
next && next.click();
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
else if( scrollEnd != -1 ){
|
|
|
|
clearTimeout( scrollEnd );
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
scrollEnd = -1;
|
2022-11-11 00:07:24 +00:00
|
|
|
}
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
document.addEventListener('keyup', function(event){
|
|
|
|
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
|
2023-02-08 23:54:12 +00:00
|
|
|
if( event.which == dir_key_start ){
|
2023-01-22 22:47:56 +00:00
|
|
|
// check for false indication if keyup is delayed after navigation
|
2023-02-08 23:54:12 +00:00
|
|
|
if( scrollStart == -1 ){
|
|
|
|
scrollStart = setTimeout( function(){ scrollStart = 0; }, 300 );
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-08 23:54:12 +00:00
|
|
|
if( event.which == dir_key_end ){
|
|
|
|
if( scrollEnd == -1 ){
|
|
|
|
scrollEnd = setTimeout( function(){ scrollEnd = 0; }, 300 );
|
2023-01-22 22:47:56 +00:00
|
|
|
}
|
2022-11-11 00:07:24 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// avoid keyboard navigation for input fields
|
2023-01-29 16:05:10 +00:00
|
|
|
document.querySelectorAll( formelements ).forEach( function( e ){
|
|
|
|
e.addEventListener( 'keydown', function( event ){
|
2023-02-08 23:54:12 +00:00
|
|
|
if( event.which == dir_key_start || event.which == dir_key_end ){
|
2023-01-29 16:05:10 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
});
|
2022-02-25 22:25:58 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 23:24:37 +00:00
|
|
|
function initMenuScrollbar(){
|
2022-04-02 13:30:16 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-12 12:07:36 +00:00
|
|
|
var elm = document.querySelector('#content-wrapper');
|
|
|
|
var elt = document.querySelector('#TableOfContents');
|
|
|
|
|
2022-11-18 20:10:44 +00:00
|
|
|
var autofocus = true;
|
2022-03-06 10:46:10 +00:00
|
|
|
document.addEventListener('keydown', function(event){
|
2022-02-28 00:20:19 +00:00
|
|
|
// for initial keyboard scrolling support, no element
|
|
|
|
// may be hovered, but we still want to react on
|
|
|
|
// cursor/page up/down. because we can't hack
|
|
|
|
// the scrollbars implementation, we try to trick
|
|
|
|
// it and give focus to the scrollbar - only
|
|
|
|
// to just remove the focus right after scrolling
|
|
|
|
// happend
|
2022-11-18 20:10:44 +00:00
|
|
|
autofocus = false;
|
|
|
|
if( event.shiftKey || event.altKey || event.ctrlKey || event.metaKey || event.which < 32 || event.which > 40 ){
|
|
|
|
// if tab key was pressed, we are ended with our initial
|
|
|
|
// focus job
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-12 12:07:36 +00:00
|
|
|
var c = elc && elc.matches(':hover');
|
|
|
|
var m = elm && elm.matches(':hover');
|
|
|
|
var t = elt && elt.matches(':hover');
|
2022-03-06 10:46:10 +00:00
|
|
|
var f = event.target.matches( formelements );
|
2022-06-06 21:58:37 +00:00
|
|
|
if( !c && !m && !t && !f ){
|
2022-02-28 00:20:19 +00:00
|
|
|
// only do this hack if none of our scrollbars
|
|
|
|
// is hovered
|
|
|
|
// if we are showing the sidebar as a flyout we
|
|
|
|
// want to scroll the content-wrapper, otherwise we want
|
|
|
|
// to scroll the body
|
2022-06-06 21:58:37 +00:00
|
|
|
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 ){
|
2022-05-30 13:11:22 +00:00
|
|
|
psm && psm.scrollbarY.focus();
|
2022-02-28 00:20:19 +00:00
|
|
|
}
|
|
|
|
else{
|
2022-06-06 21:58:37 +00:00
|
|
|
document.querySelector('#body-inner').focus();
|
2022-05-30 13:11:22 +00:00
|
|
|
psc && psc.scrollbarY.focus();
|
2022-02-28 00:20:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// scrollbars will install their own keyboard handlers
|
|
|
|
// that need to be executed inbetween our own handlers
|
2022-05-30 13:11:22 +00:00
|
|
|
// PSC removed for #242 #243 #244
|
2022-06-12 12:07:36 +00:00
|
|
|
// psc = elc && new PerfectScrollbar('#body-inner');
|
|
|
|
psm = elm && new PerfectScrollbar('#content-wrapper');
|
|
|
|
pst = elt && new PerfectScrollbar('#TableOfContents');
|
2022-02-28 00:20:19 +00:00
|
|
|
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 ){
|
2022-05-30 13:11:22 +00:00
|
|
|
psc && psc.scrollbarY.blur();
|
|
|
|
psm && psm.scrollbarY.blur();
|
2022-06-06 21:58:37 +00:00
|
|
|
pst && pst.scrollbarY.blur();
|
2022-02-28 00:20:19 +00:00
|
|
|
autofocus = false;
|
|
|
|
}
|
2022-02-25 23:24:37 +00:00
|
|
|
});
|
2022-04-03 10:12:47 +00:00
|
|
|
// on resize, we have to redraw the scrollbars to let new height
|
|
|
|
// affect their size
|
|
|
|
window.addEventListener('resize', function(){
|
2023-02-10 16:04:08 +00:00
|
|
|
pst && setTimeout( function(){ pst.update(); }, 10 );
|
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
|
|
|
psc && setTimeout( function(){ psc.update(); }, 10 );
|
2022-04-03 10:12:47 +00:00
|
|
|
});
|
|
|
|
// now that we may have collapsible menus, we need to call a resize
|
|
|
|
// for the menu scrollbar if sections are expanded/collapsed
|
2023-02-24 22:30:54 +00:00
|
|
|
document.querySelectorAll('#sidebar .collapsible-menu input').forEach( function(e){
|
2022-04-03 10:12:47 +00:00
|
|
|
e.addEventListener('change', function(){
|
2023-02-10 16:04:08 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
2022-04-03 10:12:47 +00:00
|
|
|
});
|
|
|
|
});
|
2023-02-08 23:54:12 +00:00
|
|
|
// bugfix for PS in RTL mode: the initial scrollbar position is off;
|
|
|
|
// calling update() once, fixes this
|
2023-02-10 16:04:08 +00:00
|
|
|
pst && setTimeout( function(){ pst.update(); }, 10 );
|
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
|
|
|
psc && setTimeout( function(){ psc.update(); }, 10 );
|
2022-07-02 18:46:11 +00:00
|
|
|
|
2023-02-08 23:54:12 +00:00
|
|
|
// finally, we want to adjust the contents end padding if there is a scrollbar visible
|
2022-07-02 18:46:11 +00:00
|
|
|
window.addEventListener('resize', adjustContentWidth );
|
|
|
|
adjustContentWidth();
|
2022-02-25 23:24:37 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 22:13:36 +00:00
|
|
|
function imageEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
var image = event.target;
|
|
|
|
image.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 21:58:37 +00:00
|
|
|
function sidebarEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'sidebar-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', sidebarEscapeHandler );
|
2022-11-17 16:48:48 +00:00
|
|
|
documentFocus();
|
2022-06-06 21:58:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tocEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'toc-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', tocEscapeHandler );
|
2022-11-17 16:48:48 +00:00
|
|
|
documentFocus();
|
2022-06-06 21:58:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 23:36:30 +00:00
|
|
|
function sidebarShortcutHandler( event ){
|
2022-11-11 00:07:24 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 78 /* n */ ){
|
2022-06-06 23:36:30 +00:00
|
|
|
showNav();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:48:48 +00:00
|
|
|
function searchShortcutHandler( event ){
|
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 70 /* f */ ){
|
|
|
|
showSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 23:36:30 +00:00
|
|
|
function tocShortcutHandler( event ){
|
2022-11-11 00:07:24 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 84 /* t */ ){
|
2022-06-06 23:36:30 +00:00
|
|
|
showToc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editShortcutHandler( event ){
|
2022-11-11 00:07:24 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 87 /* w */ ){
|
2022-06-06 23:36:30 +00:00
|
|
|
showEdit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printShortcutHandler( event ){
|
2022-11-11 00:07:24 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 80 /* p */ ){
|
2022-06-06 23:36:30 +00:00
|
|
|
showPrint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:48:48 +00:00
|
|
|
function showSearch(){
|
|
|
|
var s = document.querySelector( '#search-by' );
|
2022-11-20 22:01:48 +00:00
|
|
|
if( !s ){
|
|
|
|
return;
|
|
|
|
}
|
2022-11-17 16:48:48 +00:00
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
if( s == document.activeElement ){
|
|
|
|
if( b.classList.contains( 'sidebar-flyout' ) ){
|
|
|
|
showNav();
|
|
|
|
}
|
|
|
|
documentFocus();
|
|
|
|
} else {
|
|
|
|
if( !b.classList.contains( 'sidebar-flyout' ) ){
|
|
|
|
showNav();
|
|
|
|
}
|
|
|
|
s.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 23:36:30 +00:00
|
|
|
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 );
|
2022-11-17 16:48:48 +00:00
|
|
|
documentFocus();
|
2022-06-06 23:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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' ) ){
|
2023-02-10 16:04:08 +00:00
|
|
|
pst && setTimeout( function(){ pst.update(); }, 10 );
|
2022-11-17 16:48:48 +00:00
|
|
|
pst && pst.scrollbarY.focus();
|
|
|
|
document.querySelector( '.toc-wrapper ul a' ).focus();
|
2022-06-06 23:36:30 +00:00
|
|
|
document.addEventListener( 'keydown', tocEscapeHandler );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
document.removeEventListener( 'keydown', tocEscapeHandler );
|
2022-11-17 16:48:48 +00:00
|
|
|
documentFocus();
|
2022-06-06 23:36:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-29 16:05:10 +00:00
|
|
|
function navPrev(){
|
|
|
|
var e = document.querySelector( 'a.nav-prev' );
|
|
|
|
location.href = e && e.getAttribute( 'href' );
|
|
|
|
};
|
|
|
|
|
|
|
|
function navNext(){
|
|
|
|
var e = document.querySelector( 'a.nav-next' );
|
|
|
|
location.href = e && e.getAttribute( 'href' );
|
|
|
|
};
|
|
|
|
|
2022-02-25 23:24:37 +00:00
|
|
|
function initToc(){
|
2022-06-06 23:36:30 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
2022-02-28 00:20:19 +00:00
|
|
|
}
|
2022-06-06 23:36:30 +00:00
|
|
|
|
|
|
|
document.addEventListener( 'keydown', editShortcutHandler );
|
|
|
|
document.addEventListener( 'keydown', printShortcutHandler );
|
|
|
|
document.addEventListener( 'keydown', sidebarShortcutHandler );
|
2022-11-17 16:48:48 +00:00
|
|
|
document.addEventListener( 'keydown', searchShortcutHandler );
|
2022-06-06 23:36:30 +00:00
|
|
|
document.addEventListener( 'keydown', tocShortcutHandler );
|
2022-02-25 23:24:37 +00:00
|
|
|
|
2022-02-28 00:20:19 +00:00
|
|
|
document.querySelector( '#sidebar-overlay' ).addEventListener( 'click', showNav );
|
|
|
|
document.querySelector( '#sidebar-toggle' ).addEventListener( 'click', showNav );
|
|
|
|
document.querySelector( '#toc-overlay' ).addEventListener( 'click', showToc );
|
|
|
|
var t = document.querySelector( '#toc-menu' );
|
|
|
|
var p = document.querySelector( '.progress' );
|
|
|
|
if( t && p ){
|
|
|
|
// we may not have a toc
|
|
|
|
t.addEventListener( 'click', showToc );
|
|
|
|
p.addEventListener( 'click', showToc );
|
2022-02-25 23:24:37 +00:00
|
|
|
}
|
2022-06-07 18:30:50 +00:00
|
|
|
|
|
|
|
// finally give initial focus to allow keyboard scrolling in FF
|
2022-11-17 16:48:48 +00:00
|
|
|
documentFocus();
|
2022-02-25 23:24:37 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 00:20:19 +00:00
|
|
|
function initSwipeHandler(){
|
|
|
|
if( !touchsupport ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var startx = null;
|
|
|
|
var starty = null;
|
|
|
|
var handleStartX = function(evt) {
|
|
|
|
startx = evt.touches[0].clientX;
|
|
|
|
starty = evt.touches[0].clientY;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
var handleMoveX = function(evt) {
|
|
|
|
if( startx !== null ){
|
|
|
|
var diffx = startx - evt.touches[0].clientX;
|
|
|
|
var diffy = starty - evt.touches[0].clientY || .1 ;
|
|
|
|
if( diffx / Math.abs( diffy ) < 2 ){
|
|
|
|
// detect mostly vertical swipes and reset our starting pos
|
|
|
|
// to not detect a horizontal move if vertical swipe is unprecise
|
|
|
|
startx = evt.touches[0].clientX;
|
|
|
|
}
|
|
|
|
else if( diffx > 30 ){
|
|
|
|
startx = null;
|
|
|
|
starty = null;
|
2022-06-06 21:58:37 +00:00
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'sidebar-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', sidebarEscapeHandler );
|
2022-11-17 16:48:48 +00:00
|
|
|
documentFocus();
|
2022-02-28 00:20:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
var handleEndX = function(evt) {
|
|
|
|
startx = null;
|
|
|
|
starty = null;
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
document.querySelector( '#sidebar-overlay' ).addEventListener("touchstart", handleStartX, false);
|
|
|
|
document.querySelector( '#sidebar' ).addEventListener("touchstart", handleStartX, false);
|
|
|
|
document.querySelectorAll( '#sidebar *' ).forEach( function(e){ e.addEventListener("touchstart", handleStartX); }, false);
|
|
|
|
document.querySelector( '#sidebar-overlay' ).addEventListener("touchmove", handleMoveX, false);
|
|
|
|
document.querySelector( '#sidebar' ).addEventListener("touchmove", handleMoveX, false);
|
|
|
|
document.querySelectorAll( '#sidebar *' ).forEach( function(e){ e.addEventListener("touchmove", handleMoveX); }, false);
|
|
|
|
document.querySelector( '#sidebar-overlay' ).addEventListener("touchend", handleEndX, false);
|
|
|
|
document.querySelector( '#sidebar' ).addEventListener("touchend", handleEndX, false);
|
|
|
|
document.querySelectorAll( '#sidebar *' ).forEach( function(e){ e.addEventListener("touchend", handleEndX); }, false);
|
|
|
|
}
|
|
|
|
|
2023-02-04 22:13:36 +00:00
|
|
|
function initImage(){
|
|
|
|
document.querySelectorAll( '.lightbox' ).forEach( function(e){ e.addEventListener("keydown", imageEscapeHandler); }, false);
|
|
|
|
}
|
|
|
|
|
2022-07-03 13:41:08 +00:00
|
|
|
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( /^\/+\//, '/' );
|
2023-01-29 16:05:10 +00:00
|
|
|
document.querySelectorAll( '[data-nav-id="'+url+'"]' ).forEach( function( e ){
|
|
|
|
e.classList.remove( 'visited' );
|
|
|
|
});
|
2022-07-03 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initHistory() {
|
|
|
|
var visitedItem = baseUriFull + 'visited-url/'
|
2023-01-29 16:05:10 +00:00
|
|
|
sessionStorage.setItem( visitedItem+document.querySelector( 'body' ).dataset.url, 1);
|
2022-07-03 13:41:08 +00:00
|
|
|
|
|
|
|
// 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( /^\/+\//, '/' );
|
2023-01-29 16:05:10 +00:00
|
|
|
document.querySelectorAll( '[data-nav-id="'+url+'"]' ).forEach( function( e ){
|
|
|
|
e.classList.add( 'visited' );
|
|
|
|
});
|
2022-07-03 13:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 08:36:45 +00:00
|
|
|
function initScrollPositionSaver(){
|
|
|
|
function savePosition( event ){
|
|
|
|
var state = window.history.state || {};
|
|
|
|
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
2023-02-12 13:11:53 +00:00
|
|
|
state.contentScrollTop = +elc.scrollTop;
|
2023-02-12 08:36:45 +00:00
|
|
|
window.history.replaceState( state, '', window.location );
|
|
|
|
};
|
|
|
|
window.addEventListener( 'pagehide', savePosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToPositions() {
|
|
|
|
// show active menu entry
|
|
|
|
window.setTimeout( function(){
|
2023-02-24 22:30:54 +00:00
|
|
|
var e = document.querySelector( '#sidebar li.active a' );
|
2021-10-16 23:18:04 +00:00
|
|
|
if( e && e.scrollIntoView ){
|
|
|
|
e.scrollIntoView({
|
|
|
|
block: 'center',
|
|
|
|
});
|
|
|
|
}
|
2023-02-12 08:36:45 +00:00
|
|
|
}, 10 );
|
|
|
|
|
|
|
|
// scroll the content to point of interest;
|
|
|
|
// if we have a scroll position saved, the user was here
|
|
|
|
// before in his history stack and we want to reposition
|
|
|
|
// to the position he was when he left the page;
|
|
|
|
// otherwise if he used page search before, we want to position
|
|
|
|
// to its last outcome;
|
|
|
|
// otherwise he may want to see a specific fragment
|
|
|
|
|
|
|
|
var state = window.history.state || {};
|
|
|
|
state = ( typeof state === 'object') ? state : {};
|
2023-02-12 13:11:53 +00:00
|
|
|
if( state.hasOwnProperty( 'contentScrollTop' ) ){
|
2023-02-12 08:36:45 +00:00
|
|
|
window.setTimeout( function(){
|
2023-02-12 13:11:53 +00:00
|
|
|
elc.scrollTop = +state.contentScrollTop;
|
2023-02-12 08:36:45 +00:00
|
|
|
}, 10 );
|
|
|
|
return;
|
|
|
|
}
|
2021-10-16 23:18:04 +00:00
|
|
|
|
2023-02-12 13:11:53 +00:00
|
|
|
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
|
|
|
if( search && search.length ){
|
|
|
|
var found = elementContains( search, elc );
|
|
|
|
var searchedElem = found.length && found[ 0 ];
|
|
|
|
if( searchedElem ){
|
|
|
|
searchedElem.scrollIntoView( true );
|
|
|
|
var scrolledY = window.scrollY;
|
|
|
|
if( scrolledY ){
|
|
|
|
window.scroll( 0, scrolledY - 125 );
|
|
|
|
}
|
2023-02-12 08:36:45 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( window.location.hash && window.location.hash.length > 1 ){
|
|
|
|
window.setTimeout( function(){
|
|
|
|
try{
|
|
|
|
var e = document.querySelector( window.location.hash );
|
|
|
|
if( e && e.scrollIntoView ){
|
|
|
|
e.scrollIntoView({
|
|
|
|
block: 'start',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch( e ){}
|
|
|
|
}, 10 );
|
2022-04-02 13:34:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-01 14:43:15 +00:00
|
|
|
function mark() {
|
|
|
|
// mark some additional stuff as searchable
|
2023-02-04 15:02:34 +00:00
|
|
|
var topbarLinks = document.querySelectorAll( '#topbar a:not(.topbar-link):not(.btn)' );
|
2023-02-01 14:43:15 +00:00
|
|
|
for( var i = 0; i < topbarLinks.length; i++ ){
|
|
|
|
topbarLinks[i].classList.add( 'highlight' );
|
|
|
|
}
|
|
|
|
|
2023-02-04 15:22:06 +00:00
|
|
|
var bodyInnerLinks = document.querySelectorAll( '#body-inner a:not(.lightbox-link):not(.btn):not(.lightbox)' );
|
2023-02-01 14:43:15 +00:00
|
|
|
for( var i = 0; i < bodyInnerLinks.length; i++ ){
|
|
|
|
bodyInnerLinks[i].classList.add( 'highlight' );
|
|
|
|
}
|
|
|
|
|
|
|
|
var value = sessionStorage.getItem( baseUriFull + 'search-value' );
|
|
|
|
var highlightableElements = document.querySelectorAll( '.highlightable' );
|
|
|
|
highlight( highlightableElements, value, { element: 'mark' } );
|
|
|
|
|
|
|
|
var markedElements = document.querySelectorAll( 'mark' );
|
|
|
|
for( var i = 0; i < markedElements.length; i++ ){
|
|
|
|
var parent = markedElements[i].parentNode;
|
|
|
|
while( parent && parent.classList ){
|
|
|
|
if( parent.classList.contains( 'expand' ) ){
|
2023-02-03 07:58:48 +00:00
|
|
|
var expandInputs = parent.querySelectorAll( 'input:not(.expand-marked)' );
|
|
|
|
if( expandInputs.length ){
|
|
|
|
expandInputs[0].classList.add( 'expand-marked' );
|
|
|
|
expandInputs[0].dataset.checked = expandInputs[0].checked ? 'true' : 'false';
|
|
|
|
expandInputs[0].checked = true;
|
|
|
|
}
|
2023-02-01 14:43:15 +00:00
|
|
|
}
|
2023-02-24 22:30:54 +00:00
|
|
|
if( parent.tagName.toLowerCase() === 'li' && parent.parentNode && parent.parentNode.tagName.toLowerCase() === 'ul' && parent.parentNode.classList.contains( 'collapsible-menu' )){
|
|
|
|
var toggleInputs = parent.querySelectorAll( 'input:not(.menu-marked)' );
|
2023-02-03 07:58:48 +00:00
|
|
|
if( toggleInputs.length ){
|
2023-02-01 14:43:15 +00:00
|
|
|
toggleInputs[0].classList.add( 'menu-marked' );
|
|
|
|
toggleInputs[0].dataset.checked = toggleInputs[0].checked ? 'true' : 'false';
|
|
|
|
toggleInputs[0].checked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent = parent.parentNode;
|
|
|
|
}
|
|
|
|
}
|
2023-02-10 16:04:08 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
2022-07-26 22:31:56 +00:00
|
|
|
}
|
2022-11-17 21:13:11 +00:00
|
|
|
window.relearn.markSearch = mark;
|
2022-07-26 22:31:56 +00:00
|
|
|
|
2023-02-01 14:43:15 +00:00
|
|
|
function highlight( es, words, options ){
|
|
|
|
var settings = {
|
|
|
|
className: 'highlight',
|
|
|
|
element: 'span',
|
|
|
|
caseSensitive: false,
|
|
|
|
wordsOnly: false
|
|
|
|
};
|
|
|
|
Object.assign( settings, options );
|
|
|
|
|
|
|
|
if( !words ){ return; }
|
|
|
|
if( words.constructor === String ){
|
|
|
|
words = [ words ];
|
|
|
|
}
|
|
|
|
words = words.filter( function( word, i ){
|
|
|
|
return word != '';
|
2022-07-26 22:31:56 +00:00
|
|
|
});
|
2023-02-01 14:43:15 +00:00
|
|
|
words = words.map( function( word, i ){
|
|
|
|
return word.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
|
|
});
|
|
|
|
if( words.length == 0 ){ return this; }
|
|
|
|
|
|
|
|
var flag = settings.caseSensitive ? '' : 'i';
|
|
|
|
var pattern = "(" + words.join( '|' ) + ')';
|
|
|
|
if( settings.wordsOnly ){
|
|
|
|
pattern = '\\b' + pattern + '\\b';
|
|
|
|
}
|
|
|
|
var re = new RegExp( pattern, flag );
|
|
|
|
|
|
|
|
for( var i = 0; i < es.length; i++ ){
|
|
|
|
highlightNode( es[i], re, settings.element, settings.className );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function highlightNode( node, re, nodeName, className ){
|
|
|
|
if( node.nodeType === 3 && node.parentElement && node.parentElement.namespaceURI == 'http://www.w3.org/1999/xhtml' ) { // text nodes
|
|
|
|
var match = node.data.match( re );
|
|
|
|
if( match ){
|
|
|
|
var highlight = document.createElement( nodeName || 'span' );
|
|
|
|
highlight.className = className || 'highlight';
|
|
|
|
var wordNode = node.splitText( match.index );
|
|
|
|
wordNode.splitText( match[0].length );
|
|
|
|
var wordClone = wordNode.cloneNode( true );
|
|
|
|
highlight.appendChild( wordClone );
|
|
|
|
wordNode.parentNode.replaceChild( highlight, wordNode );
|
|
|
|
return 1; //skip added node in parent
|
|
|
|
}
|
|
|
|
} else if( (node.nodeType === 1 && node.childNodes) && // only element nodes that have children
|
|
|
|
!/(script|style)/i.test(node.tagName) && // ignore script and style nodes
|
|
|
|
!(node.tagName === nodeName.toUpperCase() && node.className === className) ){ // skip if already highlighted
|
|
|
|
for( var i = 0; i < node.childNodes.length; i++ ){
|
|
|
|
i += highlightNode( node.childNodes[i], re, nodeName, className );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
function unmark() {
|
|
|
|
sessionStorage.removeItem( baseUriFull + 'search-value' );
|
|
|
|
var markedElements = document.querySelectorAll( 'mark' );
|
|
|
|
for( var i = 0; i < markedElements.length; i++ ){
|
|
|
|
var parent = markedElements[i].parentNode;
|
|
|
|
while( parent && parent.classList ){
|
2023-02-24 22:30:54 +00:00
|
|
|
if( parent.tagName.toLowerCase() === 'li' && parent.parentNode && parent.parentNode.tagName.toLowerCase() === 'ul' && parent.parentNode.classList.contains( 'collapsible-menu' )){
|
|
|
|
var toggleInputs = parent.querySelectorAll( 'input.menu-marked' );
|
2023-02-03 07:58:48 +00:00
|
|
|
if( toggleInputs.length ){
|
2023-02-01 14:43:15 +00:00
|
|
|
toggleInputs[0].checked = toggleInputs[0].dataset.checked === 'true';
|
|
|
|
toggleInputs[0].dataset.checked = null;
|
|
|
|
toggleInputs[0].classList.remove( 'menu-marked' );
|
2023-02-03 07:58:48 +00:00
|
|
|
}
|
2023-02-01 14:43:15 +00:00
|
|
|
}
|
2023-02-03 07:58:48 +00:00
|
|
|
if( parent.classList.contains( 'expand' ) ){
|
|
|
|
var expandInputs = parent.querySelectorAll( 'input.expand-marked' );
|
|
|
|
if( expandInputs.length ){
|
|
|
|
expandInputs[0].checked = expandInputs[0].dataset.checked === 'true';
|
|
|
|
expandInputs[0].dataset.checked = null;
|
|
|
|
expandInputs[0].classList.remove( 'expand-marked' );
|
|
|
|
}
|
2023-02-01 14:43:15 +00:00
|
|
|
}
|
|
|
|
parent = parent.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var highlighted = document.querySelectorAll( '.highlightable' );
|
|
|
|
unhighlight( highlighted, { element: 'mark' } );
|
2023-02-10 16:04:08 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
2022-07-26 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:43:15 +00:00
|
|
|
function unhighlight( es, options ){
|
|
|
|
var settings = {
|
|
|
|
className: 'highlight',
|
|
|
|
element: 'span'
|
|
|
|
};
|
|
|
|
Object.assign( settings, options );
|
|
|
|
|
|
|
|
for( var i = 0; i < es.length; i++ ){
|
|
|
|
var highlightedElements = es[i].querySelectorAll( settings.element + '.' + settings.className );
|
|
|
|
for( var j = 0; j < highlightedElements.length; j++ ){
|
|
|
|
var parent = highlightedElements[j].parentNode;
|
|
|
|
parent.replaceChild( highlightedElements[j].firstChild, highlightedElements[j] );
|
|
|
|
parent.normalize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-01-29 23:31:15 +00:00
|
|
|
// replace jQuery.createPseudo with https://stackoverflow.com/a/66318392
|
|
|
|
function elementContains( txt, e ){
|
|
|
|
var regex = RegExp( txt, 'i' );
|
|
|
|
var nodes = [];
|
|
|
|
if( e ){
|
|
|
|
var tree = document.createTreeWalker( e, 4 /* NodeFilter.SHOW_TEXT */, function( node ){
|
|
|
|
return regex.test( node.data );
|
2023-02-04 15:53:47 +00:00
|
|
|
}, false );
|
2023-01-29 23:31:15 +00:00
|
|
|
var node = null;
|
|
|
|
while( node = tree.nextNode() ){
|
|
|
|
nodes.push( node.parentElement );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchInputHandler( value ){
|
2022-11-17 16:48:48 +00:00
|
|
|
unmark();
|
2023-01-29 23:31:15 +00:00
|
|
|
if( value.length ){
|
|
|
|
sessionStorage.setItem( baseUriFull+'search-value', value );
|
2022-11-17 16:48:48 +00:00
|
|
|
mark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 22:31:56 +00:00
|
|
|
function initSearch() {
|
2022-11-17 21:13:11 +00:00
|
|
|
// sync input/escape between searchbox and searchdetail
|
2023-01-29 23:31:15 +00:00
|
|
|
var inputs = document.querySelectorAll( 'input.search-by' );
|
|
|
|
inputs.forEach( function( e ){
|
|
|
|
e.addEventListener( 'keydown', function( event ){
|
|
|
|
if( event.key == 'Escape' ){
|
|
|
|
var input = event.target;
|
2023-02-04 15:02:34 +00:00
|
|
|
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
|
|
|
if( !search || !search.length ){
|
|
|
|
input.blur();
|
|
|
|
}
|
2023-01-29 23:31:15 +00:00
|
|
|
searchInputHandler( '' );
|
|
|
|
inputs.forEach( function( e ){
|
|
|
|
e.value = '';
|
|
|
|
});
|
2023-02-04 15:02:34 +00:00
|
|
|
if( !search || !search.length ){
|
|
|
|
documentFocus();
|
|
|
|
}
|
2023-01-29 23:31:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
e.addEventListener( 'input', function( event ){
|
|
|
|
var input = event.target;
|
|
|
|
var value = input.value;
|
|
|
|
searchInputHandler( value );
|
|
|
|
inputs.forEach( function( e ){
|
|
|
|
if( e != input ){
|
|
|
|
e.value = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-07-26 22:31:56 +00:00
|
|
|
});
|
2022-11-17 16:48:48 +00:00
|
|
|
|
2023-01-29 23:31:15 +00:00
|
|
|
document.querySelectorAll( '[data-search-clear]' ).forEach( function( e ){
|
|
|
|
e.addEventListener( 'click', function(){
|
|
|
|
inputs.forEach( function( e ){
|
|
|
|
e.value = '';
|
2023-02-04 15:49:35 +00:00
|
|
|
var event = document.createEvent( 'Event' );
|
|
|
|
event.initEvent( 'input', false, false );
|
|
|
|
e.dispatchEvent( event );
|
2023-01-29 23:31:15 +00:00
|
|
|
});
|
|
|
|
unmark();
|
|
|
|
});
|
2022-07-26 22:31:56 +00:00
|
|
|
});
|
2022-11-17 21:13:11 +00:00
|
|
|
|
2023-01-29 23:31:15 +00:00
|
|
|
var urlParams = new URLSearchParams( window.location.search );
|
|
|
|
var value = urlParams.get( 'search-by' );
|
2022-11-18 08:03:15 +00:00
|
|
|
if( value ){
|
2023-01-29 23:31:15 +00:00
|
|
|
sessionStorage.setItem( baseUriFull+'search-value', value );
|
2022-11-17 21:13:11 +00:00
|
|
|
}
|
2022-07-26 22:31:56 +00:00
|
|
|
mark();
|
|
|
|
|
2023-02-12 08:36:45 +00:00
|
|
|
// set initial search value for inputs on page load
|
2023-01-29 23:31:15 +00:00
|
|
|
if( sessionStorage.getItem( baseUriFull+'search-value' ) ){
|
2023-02-12 08:36:45 +00:00
|
|
|
var search = sessionStorage.getItem( baseUriFull+'search-value' );
|
2023-01-29 23:31:15 +00:00
|
|
|
inputs.forEach( function( e ){
|
2023-02-12 08:36:45 +00:00
|
|
|
e.value = search;
|
2023-02-04 15:49:35 +00:00
|
|
|
var event = document.createEvent( 'Event' );
|
|
|
|
event.initEvent( 'input', false, false );
|
|
|
|
e.dispatchEvent( event );
|
2023-01-29 23:31:15 +00:00
|
|
|
});
|
2022-07-26 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
2022-11-17 21:13:11 +00:00
|
|
|
window.relearn.isSearchInit = true;
|
|
|
|
window.relearn.runInitialSearch && window.relearn.runInitialSearch();
|
2022-07-26 22:31:56 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 22:36:00 +00:00
|
|
|
ready( function(){
|
2022-02-25 22:25:58 +00:00
|
|
|
initArrowNav();
|
2022-02-28 00:20:19 +00:00
|
|
|
initMermaid();
|
2023-05-14 21:06:26 +00:00
|
|
|
initOpenapi();
|
2022-02-25 23:24:37 +00:00
|
|
|
initMenuScrollbar();
|
|
|
|
initToc();
|
2022-02-28 00:20:19 +00:00
|
|
|
initAnchorClipboard();
|
|
|
|
initCodeClipboard();
|
2023-06-06 16:16:06 +00:00
|
|
|
fixCodeTabs();
|
2022-02-28 00:20:19 +00:00
|
|
|
restoreTabSelections();
|
|
|
|
initSwipeHandler();
|
2022-07-03 13:41:08 +00:00
|
|
|
initHistory();
|
2022-07-26 22:31:56 +00:00
|
|
|
initSearch();
|
2023-02-04 22:13:36 +00:00
|
|
|
initImage();
|
2023-02-12 08:36:45 +00:00
|
|
|
initScrollPositionSaver();
|
|
|
|
scrollToPositions();
|
2021-10-16 23:18:04 +00:00
|
|
|
});
|
|
|
|
|
2022-07-17 18:04:59 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
|
2023-05-14 21:06:26 +00:00
|
|
|
function useOpenapi( config ){
|
|
|
|
if( config.css && config.css.startsWith( '/' ) ){
|
|
|
|
config.css = baseUri + config.css;
|
2022-07-17 18:04:59 +00:00
|
|
|
}
|
|
|
|
}
|
2023-05-14 21:06:26 +00:00
|
|
|
if( window.themeUseOpenapi ){
|
|
|
|
useOpenapi( window.themeUseOpenapi );
|
2022-07-17 18:04:59 +00:00
|
|
|
}
|