2022-11-17 21:12:18 +00:00
|
|
|
window.relearn = window.relearn || {};
|
|
|
|
|
2022-03-27 16:42:11 +00:00
|
|
|
var theme = true;
|
2022-02-28 00:19:32 +00:00
|
|
|
var isIE = /*@cc_on!@*/false || !!document.documentMode;
|
2022-03-13 11:36:48 +00:00
|
|
|
if( isIE ){
|
2022-02-28 00:19:32 +00:00
|
|
|
// we don't support sidebar flyout in IE
|
2022-03-13 11:36:48 +00:00
|
|
|
document.querySelector( 'body' ).classList.remove( 'mobile-support' );
|
|
|
|
}
|
|
|
|
else{
|
2022-02-28 00:19:32 +00:00
|
|
|
document.querySelector( 'body' ).classList.add( 'mobile-support' );
|
|
|
|
}
|
2023-05-14 21:05:07 +00:00
|
|
|
|
2022-04-02 13:29:34 +00:00
|
|
|
var isPrint = document.querySelector( 'body' ).classList.contains( 'print' );
|
|
|
|
|
2023-02-08 23:53:11 +00:00
|
|
|
var isRtl = document.querySelector( 'html' ).getAttribute( 'dir' ) == 'rtl';
|
2023-07-27 19:17:43 +00:00
|
|
|
var lang = document.querySelector( 'html' ).getAttribute( 'lang' );
|
2023-02-08 23:53:11 +00:00
|
|
|
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:19:32 +00:00
|
|
|
var touchsupport = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)
|
|
|
|
|
2022-03-06 10:45:33 +00:00
|
|
|
var formelements = 'button, datalist, fieldset, input, label, legend, meter, optgroup, option, output, progress, select, textarea';
|
|
|
|
|
2022-06-06 21:58:00 +00:00
|
|
|
// PerfectScrollbar
|
|
|
|
var psc;
|
|
|
|
var psm;
|
2023-09-14 22:23:41 +00:00
|
|
|
var pst = new Map();
|
2023-09-23 08:18:31 +00:00
|
|
|
var elc = document.querySelector('#R-body-inner');
|
2022-11-17 16:29:01 +00:00
|
|
|
|
2023-08-31 10:34:23 +00:00
|
|
|
function regexEscape( s ){
|
|
|
|
return s.replace( /[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&' );
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:29:01 +00:00
|
|
|
function documentFocus(){
|
2023-02-08 23:53:11 +00:00
|
|
|
elc.focus();
|
2022-11-17 16:29:01 +00:00
|
|
|
psc && psc.scrollbarY.focus();
|
|
|
|
}
|
2022-06-06 21:58:00 +00:00
|
|
|
|
2022-07-02 18:29:24 +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:29:01 +00:00
|
|
|
var scrollbarSize = scrollbarWidth();
|
|
|
|
function adjustContentWidth(){
|
2023-02-08 23:53:11 +00:00
|
|
|
var start = parseFloat( getComputedStyle( elc ).getPropertyValue( dir_padding_start ) );
|
|
|
|
var end = start;
|
2022-11-17 16:29:01 +00:00
|
|
|
if( elc.scrollHeight > elc.clientHeight ){
|
2023-02-08 23:53:11 +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:29:01 +00:00
|
|
|
}
|
2023-02-08 23:53:11 +00:00
|
|
|
elc.style[ dir_padding_end ] = '' + end + 'px';
|
2022-11-17 16:29:01 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 15:44: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:45:30 +00:00
|
|
|
var codeTabContents = Array.from( document.querySelectorAll( '.tab-content.tab-panel-style' ) ).filter( function( tabContent ){
|
2023-09-30 19:41:31 +00:00
|
|
|
return tabContent.querySelector( '*:scope > .tab-content-text > div.highlight:only-child, *:scope > .tab-content-text > pre:not(.mermaid).pre-code:only-child');
|
2023-06-06 15:44:06 +00:00
|
|
|
});
|
|
|
|
|
2023-06-08 14:45:30 +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 12:53:22 +00:00
|
|
|
tabButton.classList.remove( 'initial' );
|
|
|
|
tabButton.classList.add( 'code' );
|
2023-06-08 14:45:30 +00:00
|
|
|
tabContent.classList.remove( 'initial' );
|
|
|
|
tabContent.classList.add( 'code' );
|
2023-06-08 12:53:22 +00:00
|
|
|
}
|
|
|
|
// mark code blocks for FF without :has()
|
2023-06-08 14:45:30 +00:00
|
|
|
tabContent.classList.add( 'codify' );
|
2023-06-06 15:44:06 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-03-16 17:21:57 +00:00
|
|
|
function switchTab(tabGroup, tabId) {
|
2023-01-29 15:45:42 +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:06:34 +00:00
|
|
|
return a.concat( Array.from( e.querySelectorAll( '[data-tab-item]' ) ).filter( function( es ){
|
|
|
|
return es.parentNode.parentNode == e;
|
|
|
|
}) );
|
2023-01-29 15:45:42 +00:00
|
|
|
}, [] );
|
|
|
|
var targetTabItems = tabs && tabs.reduce( function( a, e ){
|
2023-02-07 17:06:34 +00:00
|
|
|
return a.concat( Array.from( e.querySelectorAll( '[data-tab-item="'+tabId+'"]' ) ).filter( function( es ){
|
|
|
|
return es.parentNode.parentNode == e;
|
|
|
|
}) );
|
2023-01-29 15:45:42 +00:00
|
|
|
}, [] );
|
2021-03-16 17:21:57 +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:04:42 +00:00
|
|
|
var isButtonEvent = event && event.target && event.target.getBoundingClientRect;
|
2021-03-16 17:21:57 +00:00
|
|
|
if(isButtonEvent){
|
|
|
|
// save button position relative to viewport
|
|
|
|
var yposButton = event.target.getBoundingClientRect().top;
|
|
|
|
}
|
|
|
|
|
2023-11-18 23:55:23 +00:00
|
|
|
allTabItems && allTabItems.forEach( function( e ){ e.classList.remove( 'active' ); e.removeAttribute( 'tabindex' ); });
|
|
|
|
targetTabItems && targetTabItems.forEach( function( e ){ e.classList.add( 'active' ); e.setAttribute( 'tabindex', '-1' ); });
|
2021-03-16 17:21:57 +00:00
|
|
|
|
|
|
|
if(isButtonEvent){
|
2023-09-26 20:22:52 +00:00
|
|
|
initMermaid( true );
|
|
|
|
|
2021-03-16 17:21:57 +00:00
|
|
|
// 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){
|
2024-03-18 20:58:26 +00:00
|
|
|
var selectionsJSON = window.localStorage.getItem(window.relearn.absBaseUri+"/tab-selections");
|
2021-03-16 17:21:57 +00:00
|
|
|
if(selectionsJSON){
|
|
|
|
var tabSelections = JSON.parse(selectionsJSON);
|
|
|
|
}else{
|
|
|
|
var tabSelections = {};
|
|
|
|
}
|
|
|
|
tabSelections[tabGroup] = tabId;
|
2024-03-18 20:58:26 +00:00
|
|
|
window.localStorage.setItem(window.relearn.absBaseUri+"/tab-selections", JSON.stringify(tabSelections));
|
2021-03-16 17:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreTabSelections() {
|
|
|
|
if(window.localStorage){
|
2024-03-18 20:58:26 +00:00
|
|
|
var selectionsJSON = window.localStorage.getItem(window.relearn.absBaseUri+"/tab-selections");
|
2021-03-16 17:21:57 +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:06 +00:00
|
|
|
function initMermaid( update, attrs ) {
|
2023-10-01 11:48:56 +00:00
|
|
|
var doBeside = true;
|
2023-10-01 10:21:29 +00:00
|
|
|
var isImageRtl = false;
|
|
|
|
|
2022-03-27 16:42:11 +00:00
|
|
|
// we are either in update or initialization mode;
|
|
|
|
// during initialization, we want to edit the DOM;
|
2022-07-02 12:01:24 +00:00
|
|
|
// during update we only want to execute if something changed
|
2022-03-27 16:42:11 +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:45:57 +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;
|
2023-08-05 12:05:52 +00:00
|
|
|
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 16:42:11 +00:00
|
|
|
var m = d.exec( graph );
|
2023-07-28 19:13:56 +00:00
|
|
|
var yaml = {};
|
2022-03-27 16:42:11 +00:00
|
|
|
var dir = {};
|
|
|
|
var content = graph;
|
2023-06-09 19:45:57 +00:00
|
|
|
if( m && m.length == 4 ){
|
2023-08-05 12:05:52 +00:00
|
|
|
yaml = m[YAML] ? jsyaml.load( m[YAML] ) : yaml;
|
2023-06-09 19:45:57 +00:00
|
|
|
dir = m[INIT] ? JSON.parse( '{ "init": ' + m[INIT] ).init : dir;
|
|
|
|
content = m[GRAPH] ? m[GRAPH] : content;
|
2022-03-27 16:42:11 +00:00
|
|
|
}
|
2023-06-09 19:45:57 +00:00
|
|
|
var ret = { yaml: yaml, dir: dir, content: content.trim() }
|
|
|
|
return ret;
|
2022-03-27 16:42:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var serializeGraph = function( graph ){
|
2023-08-05 12:05:52 +00:00
|
|
|
var yamlPart = '';
|
|
|
|
if( Object.keys( graph.yaml ).length ){
|
|
|
|
yamlPart = '---\n' + jsyaml.dump( graph.yaml ) + '---\n';
|
2023-07-28 19:13:56 +00:00
|
|
|
}
|
2023-08-05 12:05:52 +00:00
|
|
|
var dirPart = '';
|
|
|
|
if( Object.keys( graph.dir ).length ){
|
|
|
|
dirPart = '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n';
|
2023-08-04 13:19:45 +00:00
|
|
|
}
|
|
|
|
return yamlPart + dirPart + graph.content;
|
2022-03-27 16:42:11 +00:00
|
|
|
};
|
|
|
|
|
2022-07-29 19:55:06 +00:00
|
|
|
var init_func = function( attrs ){
|
2022-03-27 16:42:11 +00:00
|
|
|
var is_initialized = false;
|
2022-07-29 19:55:06 +00:00
|
|
|
var theme = attrs.theme;
|
2022-03-19 19:18:21 +00:00
|
|
|
document.querySelectorAll('.mermaid').forEach( function( element ){
|
2022-03-27 16:42:11 +00:00
|
|
|
var parse = parseGraph( decodeHTML( element.innerHTML ) );
|
2022-03-19 19:18:21 +00:00
|
|
|
|
2023-08-05 12:10:41 +00:00
|
|
|
if( parse.yaml.theme ){
|
|
|
|
parse.yaml.relearn_user_theme = true;
|
|
|
|
}
|
|
|
|
if( parse.dir.theme ){
|
|
|
|
parse.dir.relearn_user_theme = true;
|
|
|
|
}
|
|
|
|
if( !parse.yaml.relearn_user_theme && !parse.dir.relearn_user_theme ){
|
|
|
|
parse.yaml.theme = theme;
|
2022-03-19 19:18:21 +00:00
|
|
|
}
|
2022-03-27 16:42:11 +00:00
|
|
|
is_initialized = true;
|
2022-03-19 19:18:21 +00:00
|
|
|
|
2022-03-27 16:42:11 +00:00
|
|
|
var graph = serializeGraph( parse );
|
2024-03-11 20:37:55 +00:00
|
|
|
var new_element = document.createElement( 'div' );
|
2024-03-17 00:45:14 +00:00
|
|
|
Array.from( element.attributes ).forEach( function( attr ){
|
2024-03-11 20:37:55 +00:00
|
|
|
new_element.setAttribute( attr.name, attr.value );
|
|
|
|
element.removeAttribute( attr.name );
|
2024-03-17 00:45:14 +00:00
|
|
|
});
|
2024-03-11 20:37:55 +00:00
|
|
|
new_element.classList.add( 'mermaid-container' );
|
|
|
|
new_element.classList.remove( 'mermaid' );
|
|
|
|
element.classList.add( 'mermaid' );
|
|
|
|
|
2022-03-27 16:42:11 +00:00
|
|
|
element.innerHTML = graph;
|
2023-08-25 23:26:37 +00:00
|
|
|
if( element.offsetParent !== null ){
|
|
|
|
element.classList.add( 'mermaid-render' );
|
|
|
|
}
|
2022-03-27 16:42:11 +00:00
|
|
|
new_element.innerHTML = '<div class="mermaid-code">' + graph + '</div>' + element.outerHTML;
|
2022-03-19 19:18:21 +00:00
|
|
|
element.parentNode.replaceChild( new_element, element );
|
|
|
|
});
|
2022-03-27 16:42:11 +00:00
|
|
|
return is_initialized;
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:06 +00:00
|
|
|
var update_func = function( attrs ){
|
2022-03-27 16:42:11 +00:00
|
|
|
var is_initialized = false;
|
2022-07-29 19:55:06 +00:00
|
|
|
var theme = attrs.theme;
|
2022-03-27 16:42:11 +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 ) );
|
|
|
|
|
2023-08-25 23:26:37 +00:00
|
|
|
if( element.classList.contains( 'mermaid-render' ) ){
|
|
|
|
if( parse.yaml.relearn_user_theme || parse.dir.relearn_user_theme ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( parse.yaml.theme == theme || parse.dir.theme == theme ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if( element.offsetParent !== null ){
|
|
|
|
element.classList.add( 'mermaid-render' );
|
2022-03-27 16:42:11 +00:00
|
|
|
}
|
2023-08-25 23:26:37 +00:00
|
|
|
else{
|
|
|
|
element.classList.remove( 'mermaid-render' );
|
2023-07-28 19:18:45 +00:00
|
|
|
return;
|
2022-03-27 16:42:11 +00:00
|
|
|
}
|
|
|
|
is_initialized = true;
|
|
|
|
|
2023-08-05 12:10:41 +00:00
|
|
|
parse.yaml.theme = theme;
|
2022-03-27 16:42:11 +00:00
|
|
|
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:06 +00:00
|
|
|
if( !state.is_initialized ){
|
|
|
|
state.is_initialized = true;
|
|
|
|
window.addEventListener( 'beforeprint', function(){
|
|
|
|
initMermaid( true, {
|
|
|
|
'theme': variants.getColorValue( 'PRINT-MERMAID-theme' ),
|
|
|
|
});
|
2024-01-05 15:31:22 +00:00
|
|
|
}.bind( this ) );
|
|
|
|
window.addEventListener( 'afterprint', function(){
|
2022-07-29 19:55:06 +00:00
|
|
|
initMermaid( true );
|
2024-01-05 15:31:22 +00:00
|
|
|
}.bind( this ) );
|
2022-07-29 19:55:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
attrs = attrs || {
|
|
|
|
'theme': variants.getColorValue( 'MERMAID-theme' ),
|
|
|
|
};
|
2023-02-03 23:07:52 +00:00
|
|
|
|
|
|
|
var search;
|
|
|
|
if( update ){
|
2024-03-18 20:58:26 +00:00
|
|
|
search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
2023-02-03 23:07:52 +00:00
|
|
|
unmark();
|
|
|
|
}
|
2022-07-29 19:55:06 +00:00
|
|
|
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
|
2022-03-27 16:42:11 +00:00
|
|
|
if( is_initialized ){
|
2023-08-07 20:37:05 +00:00
|
|
|
mermaid.initialize( Object.assign( { "securityLevel": "antiscript", "startOnLoad": false }, window.relearn.mermaidConfig, { theme: attrs.theme } ) );
|
2023-08-07 21:32:38 +00:00
|
|
|
mermaid.run({
|
2023-09-26 20:22:52 +00:00
|
|
|
postRenderCallback: function( id ){
|
2023-08-07 21:32:38 +00:00
|
|
|
// zoom for Mermaid
|
|
|
|
// https://github.com/mermaid-js/mermaid/issues/1860#issuecomment-1345440607
|
2024-03-11 20:37:55 +00:00
|
|
|
var svgs = d3.selectAll( 'body:not(.print) .mermaid-container.zoomable > .mermaid > #' + id );
|
2023-08-07 21:32:38 +00:00
|
|
|
svgs.each( function(){
|
2023-10-18 20:43:30 +00:00
|
|
|
var parent = this.parentElement;
|
|
|
|
// we need to copy the maxWidth, otherwise our reset button will not align in the upper right
|
|
|
|
parent.style.maxWidth = this.style.maxWidth || this.getAttribute( 'width' );
|
|
|
|
// if no unit is given for the width
|
|
|
|
parent.style.maxWidth = parent.style.maxWidth || 'calc( ' + this.getAttribute( 'width' ) + 'px + 1rem )';
|
2023-08-07 21:32:38 +00:00
|
|
|
var svg = d3.select( this );
|
|
|
|
svg.html( '<g>' + svg.html() + '</g>' );
|
2023-10-18 20:11:33 +00:00
|
|
|
var inner = svg.select( '*:scope > g' );
|
2023-10-26 22:30:30 +00:00
|
|
|
parent.insertAdjacentHTML( 'beforeend', '<span class="svg-reset-button" title="' + window.T_Reset_view + '"><i class="fas fa-undo-alt"></i></span>' );
|
|
|
|
var button = parent.querySelector( '.svg-reset-button' );
|
2023-08-07 21:32:38 +00:00
|
|
|
var zoom = d3.zoom().on( 'zoom', function( e ){
|
2023-09-26 20:22:52 +00:00
|
|
|
inner.attr( 'transform', e.transform );
|
2024-03-17 00:09:46 +00:00
|
|
|
if( e.transform.k == 1 && e.transform.x == 0 && e.transform.y == 0 ){
|
2023-11-18 22:19:35 +00:00
|
|
|
button.classList.remove( 'zoomed' );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
button.classList.add( 'zoomed' );
|
|
|
|
}
|
2023-10-26 22:30:30 +00:00
|
|
|
});
|
|
|
|
button.addEventListener( 'click', function( event ){
|
|
|
|
svg.transition()
|
|
|
|
.duration( 350 )
|
|
|
|
.call( zoom.transform, d3.zoomIdentity );
|
|
|
|
this.setAttribute( 'aria-label', window.T_View_reset );
|
|
|
|
this.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isImageRtl?'e':'w')) );
|
|
|
|
});
|
|
|
|
button.addEventListener( 'mouseleave', function() {
|
|
|
|
if( this.classList.contains( 'tooltipped' ) ){
|
|
|
|
this.classList.remove( 'tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw' );
|
2023-11-18 22:19:35 +00:00
|
|
|
this.removeAttribute( 'aria-label' );
|
2023-10-18 20:43:30 +00:00
|
|
|
}
|
2023-08-07 21:32:38 +00:00
|
|
|
});
|
|
|
|
svg.call( zoom );
|
|
|
|
});
|
|
|
|
},
|
2023-08-25 23:26:37 +00:00
|
|
|
querySelector: '.mermaid.mermaid-render',
|
2023-08-07 21:32:38 +00:00
|
|
|
suppressErrors: true
|
2023-02-04 00:54:13 +00:00
|
|
|
});
|
2021-07-02 19:58:16 +00:00
|
|
|
}
|
2023-02-03 23:07:52 +00:00
|
|
|
if( update && search && search.length ){
|
2024-03-18 20:58:26 +00:00
|
|
|
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', search );
|
2023-02-03 23:07:52 +00:00
|
|
|
mark();
|
|
|
|
}
|
2021-07-02 19:58:16 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 21:05:07 +00:00
|
|
|
function initOpenapi( update, attrs ){
|
|
|
|
if( isIE ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:06 +00:00
|
|
|
var state = this;
|
|
|
|
if( update && !state.is_initialized ){
|
|
|
|
return;
|
|
|
|
}
|
2022-03-27 16:42:11 +00:00
|
|
|
if( typeof variants == 'undefined' ){
|
|
|
|
return;
|
|
|
|
}
|
2022-07-29 19:55:06 +00:00
|
|
|
|
|
|
|
if( !state.is_initialized ){
|
|
|
|
state.is_initialized = true;
|
|
|
|
window.addEventListener( 'beforeprint', function(){
|
2023-05-14 21:05:07 +00:00
|
|
|
initOpenapi( true, { isPrintPreview: true } );
|
2022-07-29 19:55:06 +00:00
|
|
|
}.bind( this ) );
|
|
|
|
window.addEventListener( 'afterprint', function(){
|
2023-05-14 21:05:07 +00:00
|
|
|
initOpenapi( true, { isPrintPreview: false } );
|
2022-07-29 19:55:06 +00:00
|
|
|
}.bind( this ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs = attrs || {
|
2023-05-14 21:05:07 +00:00
|
|
|
isPrintPreview: false
|
2022-07-29 19:55:06 +00:00
|
|
|
};
|
2023-05-14 21:05:07 +00:00
|
|
|
|
|
|
|
function addFunctionToResizeEvent(){
|
|
|
|
|
|
|
|
}
|
|
|
|
function getFirstAncestorByClass(){
|
|
|
|
|
|
|
|
}
|
|
|
|
function renderOpenAPI(oc) {
|
2024-03-18 20:56:21 +00:00
|
|
|
var relBasePath = window.relearn.relBasePath;
|
2023-12-03 14:22:32 +00:00
|
|
|
var mod = window.relearn.themeVariantModifier;
|
2023-05-14 21:05:07 +00:00
|
|
|
var buster = window.themeUseOpenapi.assetsBuster ? '?' + window.themeUseOpenapi.assetsBuster : '';
|
|
|
|
var print = isPrint || attrs.isPrintPreview ? "PRINT-" : "";
|
2024-03-18 20:56:21 +00:00
|
|
|
var theme = print ? `${relBasePath}/css/theme-relearn-light${mod}.css${buster}` : document.querySelector( '#R-variant-style' ).attributes.href.value
|
2023-05-14 21:05:07 +00:00
|
|
|
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>' +
|
2023-07-27 19:17:43 +00:00
|
|
|
'<html lang="' + lang + '" dir="' + (isRtl ? 'rtl' : 'ltr') + '">' +
|
2023-05-14 21:05:07 +00:00
|
|
|
'<head>' +
|
|
|
|
'<link rel="stylesheet" href="' + window.themeUseOpenapi.css + '">' +
|
|
|
|
'<link rel="stylesheet" href="' + theme + '">' +
|
2024-03-18 20:56:21 +00:00
|
|
|
'<link rel="stylesheet" href="' + relBasePath + '/css/swagger.css' + buster + '">' +
|
|
|
|
'<link rel="stylesheet" href="' + relBasePath + '/css/swagger-' + swagger_theme + '.css' + buster + '">' +
|
2023-05-14 21:05:07 +00:00
|
|
|
'</head>' +
|
|
|
|
'<body>' +
|
|
|
|
'<a class="relearn-expander" href="" onclick="return relearn_collapse_all()">Collapse all</a>' +
|
2023-07-19 02:25:10 +00:00
|
|
|
'<a class="relearn-expander" href="" onclick="return relearn_expand_all()">Expand all</a>' +
|
2023-05-14 21:05:07 +00:00
|
|
|
'<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(){
|
2024-03-16 23:27:38 +00:00
|
|
|
var options = {
|
2023-05-14 21:05:07 +00:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
validatorUrl: 'none',
|
2024-03-16 23:27:38 +00:00
|
|
|
};
|
|
|
|
if( oc.dataset.openapiSpec ){
|
2024-03-16 23:47:48 +00:00
|
|
|
try{
|
|
|
|
Object.assign( options, { spec: JSON.parse( oc.dataset.openapiSpec ) });
|
|
|
|
} catch( err ){
|
|
|
|
try{
|
|
|
|
Object.assign( options, { spec: jsyaml.load( oc.dataset.openapiSpec ) });
|
|
|
|
} catch( err ){
|
2024-03-16 23:55:37 +00:00
|
|
|
console.error( 'OpenAPI: file "' + oc.dataset.openapiUrl + '" could not be parsed as JSON or YAML');
|
2024-03-16 23:47:48 +00:00
|
|
|
}
|
|
|
|
}
|
2024-03-16 23:27:38 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
Object.assign( options, { url: oc.dataset.openapiUrl });
|
|
|
|
}
|
|
|
|
SwaggerUIBundle( options );
|
2023-05-14 21:05:07 +00:00
|
|
|
})
|
|
|
|
.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 16:42:11 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 22:24:25 +00:00
|
|
|
function initAnchorClipboard(){
|
2023-05-19 10:59:06 +00:00
|
|
|
document.querySelectorAll( 'h1~h2,h1~h3,h1~h4,h1~h5,h1~h6').forEach( function( element ){
|
2023-02-20 12:54:45 +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:25:57 +00:00
|
|
|
var link = url + "#" + element.id;
|
2022-03-25 14:35:19 +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 12:36:19 +00:00
|
|
|
element.appendChild( new_element );
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
|
2023-02-03 22:25:57 +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:24:25 +00:00
|
|
|
|
2023-02-03 22:25:57 +00:00
|
|
|
var clip = new ClipboardJS( '.anchor' );
|
|
|
|
clip.on( 'success', function( e ){
|
2022-02-25 22:24:25 +00:00
|
|
|
e.clearSelection();
|
2023-02-03 22:25:57 +00:00
|
|
|
e.trigger.setAttribute( 'aria-label', window.T_Link_copied_to_clipboard );
|
2023-02-09 23:34:47 +00:00
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-s'+(isRtl?'e':'w') );
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initCodeClipboard(){
|
2023-06-16 19:13:59 +00:00
|
|
|
function getCodeText( node ){
|
2023-06-21 20:06:16 +00:00
|
|
|
// if highlight shortcode is used in inline lineno mode, remove lineno nodes before generating text, otherwise it doesn't hurt
|
|
|
|
var code = node.cloneNode( true );
|
|
|
|
Array.from( code.querySelectorAll( '*:scope > span > span:first-child:not(:last-child)' ) ).forEach( function( lineno ){
|
|
|
|
lineno.remove();
|
|
|
|
});
|
|
|
|
var text = code.textContent;
|
2023-06-16 19:13:59 +00:00
|
|
|
// remove a trailing line break, this may most likely
|
|
|
|
// come from the browser / Hugo transformation
|
|
|
|
text = text.replace( /\n$/, '' );
|
2023-06-21 20:06:16 +00:00
|
|
|
return text;
|
2023-06-16 19:13:59 +00:00
|
|
|
}
|
|
|
|
|
2023-02-03 22:25:57 +00:00
|
|
|
function fallbackMessage( action ){
|
2022-02-25 22:24:25 +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-21 20:06:16 +00:00
|
|
|
var codeElements = document.querySelectorAll( 'code' );
|
2024-01-05 15:31:22 +00:00
|
|
|
for( var i = 0; i < codeElements.length; i++ ){
|
2023-02-03 22:25:57 +00:00
|
|
|
var code = codeElements[i];
|
2023-06-21 20:06:16 +00:00
|
|
|
var text = getCodeText( code );
|
2023-02-04 21:50:19 +00:00
|
|
|
var inPre = code.parentNode.tagName.toLowerCase() == 'pre';
|
2023-06-21 20:06:16 +00:00
|
|
|
var inTable = inPre &&
|
2024-03-04 19:19:43 +00:00
|
|
|
code.parentNode.parentNode.tagName.toLowerCase() == 'td' &&
|
|
|
|
code.parentNode.parentNode.classList.contains('lntd');
|
2023-06-15 21:17:27 +00:00
|
|
|
// avoid copy-to-clipboard for highlight shortcode in table lineno mode
|
2023-06-21 20:06:16 +00:00
|
|
|
var isFirstLineCell = inTable &&
|
2023-06-16 19:13:59 +00:00
|
|
|
code.parentNode.parentNode.parentNode.querySelector( 'td:first-child > pre > code' ) == code;
|
2023-02-03 22:25:57 +00:00
|
|
|
|
2023-06-16 19:13:59 +00:00
|
|
|
if( !isFirstLineCell && ( inPre || text.length > 5 ) ){
|
2023-02-03 22:25:57 +00:00
|
|
|
code.classList.add( 'copy-to-clipboard-code' );
|
2022-02-25 22:24:25 +00:00
|
|
|
if( inPre ){
|
2023-02-03 22:25:57 +00:00
|
|
|
code.classList.add( 'copy-to-clipboard' );
|
2023-02-24 23:05:38 +00:00
|
|
|
code.parentNode.classList.add( 'pre-code' );
|
2022-02-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
else{
|
2023-06-21 20:27:33 +00:00
|
|
|
var clone = code.cloneNode( true );
|
2023-02-03 22:25:57 +00:00
|
|
|
var span = document.createElement( 'span' );
|
|
|
|
span.classList.add( 'copy-to-clipboard' );
|
2023-06-21 20:27:33 +00:00
|
|
|
span.appendChild( clone );
|
|
|
|
code.parentNode.replaceChild( span, code );
|
|
|
|
code = clone;
|
2022-02-25 22:24:25 +00:00
|
|
|
}
|
2023-02-03 22:25:57 +00:00
|
|
|
var button = document.createElement( 'span' );
|
|
|
|
button.classList.add( 'copy-to-clipboard-button' );
|
|
|
|
button.setAttribute( 'title', window.T_Copy_to_clipboard );
|
2023-09-26 19:27:04 +00:00
|
|
|
button.innerHTML = '<i class="far fa-copy"></i>';
|
2023-02-03 22:25:57 +00:00
|
|
|
button.addEventListener( 'mouseleave', function() {
|
|
|
|
this.removeAttribute( 'aria-label' );
|
|
|
|
this.classList.remove( 'tooltipped', 'tooltipped-w', 'tooltipped-se', 'tooltipped-sw' );
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
2023-06-21 20:06:16 +00:00
|
|
|
if( inTable ){
|
|
|
|
var table = code.parentNode.parentNode.parentNode.parentNode.parentNode;
|
2024-03-18 20:49:45 +00:00
|
|
|
table.dataset.code = text;
|
2023-06-21 20:06:16 +00:00
|
|
|
table.parentNode.insertBefore( button, table.nextSibling );
|
|
|
|
}
|
2023-06-21 23:22:08 +00:00
|
|
|
else if( inPre ){
|
|
|
|
var pre = code.parentNode;
|
2024-03-18 20:49:45 +00:00
|
|
|
pre.dataset.code = text;
|
2023-06-21 23:22:08 +00:00
|
|
|
var p = pre.parentNode;
|
|
|
|
// indented code blocks are missing the div
|
|
|
|
while( p != document && ( p.tagName.toLowerCase() != 'div' || !p.classList.contains( 'highlight' ) ) ){
|
|
|
|
p = p.parentNode;
|
|
|
|
}
|
|
|
|
if( p == document ){
|
|
|
|
var clone = pre.cloneNode( true );
|
|
|
|
var div = document.createElement( 'div' );
|
|
|
|
div.classList.add( 'highlight' );
|
|
|
|
div.appendChild( clone );
|
|
|
|
pre.parentNode.replaceChild( div, pre );
|
|
|
|
pre = clone;
|
|
|
|
}
|
|
|
|
pre.parentNode.insertBefore( button, pre.nextSibling );
|
|
|
|
}
|
2023-06-21 20:06:16 +00:00
|
|
|
else{
|
2024-03-18 20:49:45 +00:00
|
|
|
code.dataset.code = text;
|
2023-06-21 20:06:16 +00:00
|
|
|
code.parentNode.insertBefore( button, code.nextSibling );
|
|
|
|
}
|
2022-02-25 22:24:25 +00:00
|
|
|
}
|
2023-02-03 22:25:57 +00:00
|
|
|
}
|
2023-11-29 16:11:04 +00:00
|
|
|
|
|
|
|
var clip = new ClipboardJS( '.copy-to-clipboard-button', {
|
|
|
|
text: function( trigger ){
|
|
|
|
if( !trigger.previousElementSibling ){
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return trigger.previousElementSibling.dataset.code || '';
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
clip.on( 'success', function( e ){
|
|
|
|
e.clearSelection();
|
|
|
|
var inPre = e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'pre';
|
|
|
|
var isCodeRtl = !inPre ? isRtl : false;
|
|
|
|
var doBeside = inPre || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' );
|
|
|
|
e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard );
|
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) );
|
|
|
|
});
|
|
|
|
|
|
|
|
clip.on( 'error', function( e ){
|
|
|
|
var inPre = e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'pre';
|
|
|
|
var isCodeRtl = !inPre ? isRtl : false;
|
|
|
|
var doBeside = inPre || (e.trigger.previousElementSibling && e.trigger.previousElementSibling.tagName.toLowerCase() == 'table' );
|
|
|
|
e.trigger.setAttribute( 'aria-label', fallbackMessage(e.action) );
|
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) );
|
|
|
|
var f = function(){
|
|
|
|
e.trigger.setAttribute( 'aria-label', window.T_Copied_to_clipboard );
|
|
|
|
e.trigger.classList.add( 'tooltipped', 'tooltipped-' + (doBeside ? 'w' : 's'+(isCodeRtl?'e':'w')) );
|
|
|
|
document.removeEventListener( 'copy', f );
|
|
|
|
};
|
|
|
|
document.addEventListener( 'copy', f );
|
|
|
|
});
|
2022-02-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
|
2023-11-25 13:23:58 +00:00
|
|
|
function initChroma( update ){
|
|
|
|
var chroma = variants.getColorValue( 'CODE-theme' );
|
|
|
|
var link = document.querySelector( '#R-variant-chroma-style' );
|
|
|
|
var old_path = link.getAttribute( 'href' );
|
2024-01-05 15:31:22 +00:00
|
|
|
var new_path = old_path.replace( /^(.*\/chroma-).*?(\.css.*)$/, '$1' + chroma + '$2' );
|
2023-11-25 13:23:58 +00:00
|
|
|
link.setAttribute( 'href', new_path );
|
|
|
|
}
|
|
|
|
|
2024-03-29 20:09:03 +00:00
|
|
|
function initArrowVerticalNav(){
|
|
|
|
var topMain = 0;
|
|
|
|
if( !isPrint ){
|
|
|
|
topMain = document.querySelector("main").getClientRects()[0].top;
|
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('keydown', function(event){
|
|
|
|
var elems = Array.from( document.querySelectorAll( `main :not(.include.hide-first-heading) > :where(
|
|
|
|
.article-subheading,
|
|
|
|
:not(.article-subheading) + h1:not(.a11y-only),
|
|
|
|
h1:not(.a11y-only):first-child,
|
|
|
|
h2, h3, h4, h5, h6
|
|
|
|
),
|
|
|
|
main .include.hide-first-heading > :where( h1, h2, h3, h4, h5, h6 ) ~ :where( h1, h2, h3, h4, h5, h6 )
|
|
|
|
` ));
|
|
|
|
if( !event.shiftKey && !event.ctrlKey && event.altKey && !event.metaKey ){
|
|
|
|
if( event.which == 38 ){ // up
|
|
|
|
var target = isPrint ? document.querySelector( '#R-body' ) : document.querySelector( '.flex-block-wrapper' );
|
|
|
|
elems.some( function( elem, i ){
|
|
|
|
var top = elem.getBoundingClientRect().top;
|
|
|
|
var topBoundary = top - topMain;
|
|
|
|
if( topBoundary > -1 ){
|
|
|
|
target.scrollIntoView();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
target = elem
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else if( event.which == 40 ){ // down
|
|
|
|
elems.some( function( elem, i ){
|
|
|
|
var top = elem.getBoundingClientRect().top;
|
|
|
|
var topBoundary = top - topMain;
|
|
|
|
if( topBoundary > -1 && topBoundary < 1 ){
|
|
|
|
if( i+1 < elems.length ){
|
|
|
|
var target = elems[ i+1 ];
|
|
|
|
target.scrollIntoView();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if( topBoundary >= 1 ){
|
|
|
|
var target = elem;
|
|
|
|
target.scrollIntoView();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initArrowHorizontalNav(){
|
2022-07-03 11:31:08 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-25 22:24:25 +00:00
|
|
|
// button navigation
|
2023-09-18 18:24:49 +00:00
|
|
|
var prev = document.querySelector( '.topbar-button-prev a' );
|
2023-02-04 00:42:21 +00:00
|
|
|
prev && prev.addEventListener( 'click', navPrev );
|
2023-09-18 18:24:49 +00:00
|
|
|
var next = document.querySelector( '.topbar-button-next a' );
|
2023-02-04 00:42:21 +00:00
|
|
|
next && next.addEventListener( 'click', navNext );
|
2022-02-25 22:24:25 +00:00
|
|
|
|
|
|
|
// keyboard navigation
|
2023-01-22 22:46:56 +00:00
|
|
|
// avoid prev/next navigation if we are not at the start/end of the
|
|
|
|
// horizontal area
|
2023-09-23 08:18:31 +00:00
|
|
|
var el = document.querySelector('#R-body-inner');
|
2023-02-08 23:53:11 +00:00
|
|
|
var scrollStart = 0;
|
|
|
|
var scrollEnd = 0;
|
2023-01-22 22:46:56 +00:00
|
|
|
document.addEventListener('keydown', function(event){
|
|
|
|
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
|
2023-02-08 23:53:11 +00:00
|
|
|
if( event.which == dir_key_start ){
|
|
|
|
if( !scrollStart && +el.scrollLeft.toFixed()*dir_scroll <= 0 ){
|
2023-02-04 00:42:21 +00:00
|
|
|
prev && prev.click();
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
2023-02-08 23:53:11 +00:00
|
|
|
else if( scrollStart != -1 ){
|
|
|
|
clearTimeout( scrollStart );
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
2023-02-08 23:53:11 +00:00
|
|
|
scrollStart = -1;
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
2023-02-08 23:53:11 +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:42:21 +00:00
|
|
|
next && next.click();
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
2023-02-08 23:53:11 +00:00
|
|
|
else if( scrollEnd != -1 ){
|
|
|
|
clearTimeout( scrollEnd );
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
2023-02-08 23:53:11 +00:00
|
|
|
scrollEnd = -1;
|
2022-11-11 00:05:42 +00:00
|
|
|
}
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
document.addEventListener('keyup', function(event){
|
|
|
|
if( !event.shiftKey && !event.ctrlKey && !event.altKey && !event.metaKey ){
|
2023-02-08 23:53:11 +00:00
|
|
|
if( event.which == dir_key_start ){
|
2023-01-22 22:46:56 +00:00
|
|
|
// check for false indication if keyup is delayed after navigation
|
2023-02-08 23:53:11 +00:00
|
|
|
if( scrollStart == -1 ){
|
|
|
|
scrollStart = setTimeout( function(){ scrollStart = 0; }, 300 );
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
|
|
|
}
|
2023-02-08 23:53:11 +00:00
|
|
|
if( event.which == dir_key_end ){
|
|
|
|
if( scrollEnd == -1 ){
|
|
|
|
scrollEnd = setTimeout( function(){ scrollEnd = 0; }, 300 );
|
2023-01-22 22:46:56 +00:00
|
|
|
}
|
2022-11-11 00:05:42 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// avoid keyboard navigation for input fields
|
2023-01-29 15:47:34 +00:00
|
|
|
document.querySelectorAll( formelements ).forEach( function( e ){
|
|
|
|
e.addEventListener( 'keydown', function( event ){
|
2023-02-08 23:53:11 +00:00
|
|
|
if( event.which == dir_key_start || event.which == dir_key_end ){
|
2023-01-29 15:47:34 +00:00
|
|
|
event.stopPropagation();
|
|
|
|
}
|
|
|
|
});
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 23:24:07 +00:00
|
|
|
function initMenuScrollbar(){
|
2022-04-02 13:29:34 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-23 08:18:31 +00:00
|
|
|
var elm = document.querySelector('#R-content-wrapper');
|
2023-09-18 18:24:49 +00:00
|
|
|
var elt = document.querySelector('.topbar-button.topbar-flyout .topbar-content-wrapper');
|
2022-06-12 12:06:30 +00:00
|
|
|
|
2022-11-18 20:09:50 +00:00
|
|
|
var autofocus = true;
|
2022-03-06 10:45:33 +00:00
|
|
|
document.addEventListener('keydown', function(event){
|
2022-02-28 00:19:32 +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:09:50 +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:06:30 +00:00
|
|
|
var c = elc && elc.matches(':hover');
|
|
|
|
var m = elm && elm.matches(':hover');
|
|
|
|
var t = elt && elt.matches(':hover');
|
2022-03-06 10:45:33 +00:00
|
|
|
var f = event.target.matches( formelements );
|
2022-06-06 21:58:00 +00:00
|
|
|
if( !c && !m && !t && !f ){
|
2022-02-28 00:19:32 +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
|
2023-09-14 22:23:41 +00:00
|
|
|
var nt = document.querySelector('body').matches('.topbar-flyout');
|
2022-06-06 21:58:00 +00:00
|
|
|
var nm = document.querySelector('body').matches('.sidebar-flyout');
|
|
|
|
if( nt ){
|
2023-09-14 22:23:41 +00:00
|
|
|
var psb = pst.get( document.querySelector('.topbar-button.topbar-flyout') );
|
|
|
|
psb && psb.scrollbarY.focus();
|
2022-06-06 21:58:00 +00:00
|
|
|
}
|
|
|
|
else if( nm ){
|
2022-05-30 13:10:35 +00:00
|
|
|
psm && psm.scrollbarY.focus();
|
2022-02-28 00:19:32 +00:00
|
|
|
}
|
|
|
|
else{
|
2023-09-23 08:18:31 +00:00
|
|
|
document.querySelector('#R-body-inner').focus();
|
2022-05-30 13:10:35 +00:00
|
|
|
psc && psc.scrollbarY.focus();
|
2022-02-28 00:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// scrollbars will install their own keyboard handlers
|
|
|
|
// that need to be executed inbetween our own handlers
|
2022-05-30 13:10:35 +00:00
|
|
|
// PSC removed for #242 #243 #244
|
2023-09-23 08:18:31 +00:00
|
|
|
// psc = elc && new PerfectScrollbar('#R-body-inner');
|
|
|
|
psm = elm && new PerfectScrollbar('#R-content-wrapper');
|
2023-09-18 18:24:49 +00:00
|
|
|
document.querySelectorAll('.topbar-button .topbar-content-wrapper').forEach( function( e ){
|
2023-09-14 22:23:41 +00:00
|
|
|
var button = getTopbarButtonParent( e );
|
|
|
|
if( !button ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pst.set( button, new PerfectScrollbar( e ) );
|
|
|
|
e.addEventListener( 'click', toggleTopbarFlyoutEvent );
|
|
|
|
});
|
|
|
|
|
2022-02-28 00:19:32 +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:10:35 +00:00
|
|
|
psc && psc.scrollbarY.blur();
|
|
|
|
psm && psm.scrollbarY.blur();
|
2023-09-14 22:23:41 +00:00
|
|
|
pst.forEach( function( psb ){
|
|
|
|
psb.scrollbarY.blur();
|
|
|
|
});
|
2022-02-28 00:19:32 +00:00
|
|
|
autofocus = false;
|
|
|
|
}
|
2022-02-25 23:24:07 +00:00
|
|
|
});
|
2022-04-03 10:12:12 +00:00
|
|
|
// on resize, we have to redraw the scrollbars to let new height
|
|
|
|
// affect their size
|
|
|
|
window.addEventListener('resize', function(){
|
2023-09-14 22:23:41 +00:00
|
|
|
pst.forEach( function( psb ){
|
|
|
|
setTimeout( function(){ psb.update(); }, 10 );
|
|
|
|
});
|
2023-02-10 16:02:33 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
|
|
|
psc && setTimeout( function(){ psc.update(); }, 10 );
|
2022-04-03 10:12:12 +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-09-23 08:18:31 +00:00
|
|
|
document.querySelectorAll('#R-sidebar .collapsible-menu input').forEach( function(e){
|
2022-04-03 10:12:12 +00:00
|
|
|
e.addEventListener('change', function(){
|
2023-02-10 16:02:33 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
2022-04-03 10:12:12 +00:00
|
|
|
});
|
|
|
|
});
|
2023-02-08 23:53:11 +00:00
|
|
|
// bugfix for PS in RTL mode: the initial scrollbar position is off;
|
|
|
|
// calling update() once, fixes this
|
2023-09-14 22:23:41 +00:00
|
|
|
pst.forEach( function( psb ){
|
|
|
|
setTimeout( function(){ psb.update(); }, 10 );
|
|
|
|
});
|
2023-02-10 16:02:33 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
|
|
|
psc && setTimeout( function(){ psc.update(); }, 10 );
|
2022-07-02 18:29:24 +00:00
|
|
|
|
2023-02-08 23:53:11 +00:00
|
|
|
// finally, we want to adjust the contents end padding if there is a scrollbar visible
|
2022-07-02 18:29:24 +00:00
|
|
|
window.addEventListener('resize', adjustContentWidth );
|
|
|
|
adjustContentWidth();
|
2022-02-25 23:24:07 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 22:12:40 +00:00
|
|
|
function imageEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
var image = event.target;
|
|
|
|
image.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 22:23:41 +00:00
|
|
|
function navShortcutHandler( event ){
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 78 /* n */ ){
|
2023-09-14 22:23:41 +00:00
|
|
|
toggleNav();
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:29:01 +00:00
|
|
|
function searchShortcutHandler( event ){
|
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 70 /* f */ ){
|
|
|
|
showSearch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 23:35:54 +00:00
|
|
|
function tocShortcutHandler( event ){
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 84 /* t */ ){
|
2023-09-14 22:23:41 +00:00
|
|
|
toggleToc();
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function editShortcutHandler( event ){
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 87 /* w */ ){
|
2022-06-06 23:35:54 +00:00
|
|
|
showEdit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function printShortcutHandler( event ){
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 80 /* p */ ){
|
2022-06-06 23:35:54 +00:00
|
|
|
showPrint();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 16:29:01 +00:00
|
|
|
function showSearch(){
|
2023-09-23 08:18:31 +00:00
|
|
|
var s = document.querySelector( '#R-search-by' );
|
2022-11-20 22:00:40 +00:00
|
|
|
if( !s ){
|
|
|
|
return;
|
|
|
|
}
|
2022-11-17 16:29:01 +00:00
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
if( s == document.activeElement ){
|
|
|
|
if( b.classList.contains( 'sidebar-flyout' ) ){
|
2023-09-14 22:23:41 +00:00
|
|
|
closeNav();
|
2022-11-17 16:29:01 +00:00
|
|
|
}
|
|
|
|
documentFocus();
|
|
|
|
} else {
|
|
|
|
if( !b.classList.contains( 'sidebar-flyout' ) ){
|
2023-09-14 22:23:41 +00:00
|
|
|
openNav();
|
2022-11-17 16:29:01 +00:00
|
|
|
}
|
|
|
|
s.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 22:23:41 +00:00
|
|
|
function openNav(){
|
|
|
|
closeSomeTopbarButtonFlyout();
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.add( 'sidebar-flyout' );
|
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
|
|
|
psm && psm.scrollbarY.focus();
|
2023-09-23 08:18:31 +00:00
|
|
|
var a = document.querySelector( '#R-sidebar a' )
|
2023-09-14 22:23:41 +00:00
|
|
|
if( a ){
|
|
|
|
a.focus();
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
2023-09-14 22:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function closeNav(){
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'sidebar-flyout' );
|
|
|
|
documentFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleNav(){
|
2022-06-06 23:35:54 +00:00
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
if( b.classList.contains( 'sidebar-flyout' ) ){
|
2023-09-14 22:23:41 +00:00
|
|
|
closeNav();
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
|
|
|
else{
|
2023-09-14 22:23:41 +00:00
|
|
|
openNav();
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 22:23:41 +00:00
|
|
|
function navEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
closeNav();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getTopbarButtonParent( e ){
|
|
|
|
var button = e;
|
|
|
|
while( button && !button.classList.contains( 'topbar-button' ) ){
|
|
|
|
button = button.parentElement;
|
|
|
|
}
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
function openTopbarButtonFlyout( button ){
|
|
|
|
closeNav();
|
|
|
|
var body = document.querySelector( 'body' );
|
|
|
|
button.classList.add( 'topbar-flyout' );
|
|
|
|
body.classList.add( 'topbar-flyout' );
|
|
|
|
var psb = pst.get( button );
|
|
|
|
psb && setTimeout( function(){ psb.update(); }, 10 );
|
|
|
|
psb && psb.scrollbarY.focus();
|
2023-09-18 18:24:49 +00:00
|
|
|
var a = button.querySelector( '.topbar-content-wrapper a' );
|
2023-09-14 22:23:41 +00:00
|
|
|
if( a ){
|
|
|
|
a.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeTopbarButtonFlyout( button ){
|
|
|
|
var body = document.querySelector( 'body' );
|
|
|
|
button.classList.remove( 'topbar-flyout' );
|
|
|
|
body.classList.remove( 'topbar-flyout' );
|
|
|
|
documentFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeSomeTopbarButtonFlyout(){
|
|
|
|
var someButton = document.querySelector( '.topbar-button.topbar-flyout' );
|
|
|
|
if( someButton ){
|
|
|
|
closeTopbarButtonFlyout( someButton );
|
|
|
|
};
|
|
|
|
return someButton
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleTopbarButtonFlyout( button ){
|
|
|
|
var someButton = closeSomeTopbarButtonFlyout();
|
|
|
|
if( button && button != someButton ){
|
|
|
|
openTopbarButtonFlyout( button );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleTopbarFlyout( e ){
|
|
|
|
var button = getTopbarButtonParent( e );
|
|
|
|
if( !button ){
|
2022-06-06 23:35:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-09-14 22:23:41 +00:00
|
|
|
toggleTopbarButtonFlyout( button );
|
|
|
|
}
|
|
|
|
|
|
|
|
function toggleTopbarFlyoutEvent( event ){
|
2023-09-18 18:24:49 +00:00
|
|
|
if( event.target.classList.contains( 'topbar-content' )
|
|
|
|
|| event.target.classList.contains( 'topbar-content-wrapper' )
|
2023-09-14 22:23:41 +00:00
|
|
|
|| event.target.classList.contains( 'ps__rail-x' )
|
|
|
|
|| event.target.classList.contains( 'ps__rail-y' )
|
|
|
|
|| event.target.classList.contains( 'ps__thumb-x' )
|
|
|
|
|| event.target.classList.contains( 'ps__thumb-y' )
|
|
|
|
){
|
|
|
|
// the scrollbar was used, don't close flyout
|
|
|
|
return;
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
2023-09-14 22:23:41 +00:00
|
|
|
toggleTopbarFlyout( event.target )
|
|
|
|
}
|
|
|
|
|
|
|
|
function topbarFlyoutEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
closeSomeTopbarButtonFlyout();
|
2022-06-06 23:35:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-14 22:23:41 +00:00
|
|
|
function toggleToc(){
|
2023-09-18 18:24:49 +00:00
|
|
|
toggleTopbarButtonFlyout( document.querySelector( '.topbar-button-toc' ) );
|
2023-09-14 22:23:41 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 23:35:54 +00:00
|
|
|
function showEdit(){
|
2023-09-18 18:24:49 +00:00
|
|
|
var l = document.querySelector( '.topbar-button-edit a' );
|
2022-06-06 23:35:54 +00:00
|
|
|
if( l ){
|
|
|
|
l.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPrint(){
|
2023-09-18 18:24:49 +00:00
|
|
|
var l = document.querySelector( '.topbar-button-print a' );
|
2022-06-06 23:35:54 +00:00
|
|
|
if( l ){
|
|
|
|
l.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-29 15:47:34 +00:00
|
|
|
function navPrev(){
|
2023-09-18 18:24:49 +00:00
|
|
|
var e = document.querySelector( '.topbar-button-prev a' );
|
2023-01-29 15:47:34 +00:00
|
|
|
location.href = e && e.getAttribute( 'href' );
|
|
|
|
};
|
|
|
|
|
|
|
|
function navNext(){
|
2023-09-18 18:24:49 +00:00
|
|
|
var e = document.querySelector( '.topbar-button-next a' );
|
2023-01-29 15:47:34 +00:00
|
|
|
location.href = e && e.getAttribute( 'href' );
|
|
|
|
};
|
|
|
|
|
2022-02-25 23:24:07 +00:00
|
|
|
function initToc(){
|
2022-06-06 23:35:54 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
2022-02-28 00:19:32 +00:00
|
|
|
}
|
2022-06-06 23:35:54 +00:00
|
|
|
|
|
|
|
document.addEventListener( 'keydown', editShortcutHandler );
|
2023-09-14 22:23:41 +00:00
|
|
|
document.addEventListener( 'keydown', navShortcutHandler );
|
2022-06-06 23:35:54 +00:00
|
|
|
document.addEventListener( 'keydown', printShortcutHandler );
|
2022-11-17 16:29:01 +00:00
|
|
|
document.addEventListener( 'keydown', searchShortcutHandler );
|
2022-06-06 23:35:54 +00:00
|
|
|
document.addEventListener( 'keydown', tocShortcutHandler );
|
2023-09-14 22:23:41 +00:00
|
|
|
document.addEventListener( 'keydown', navEscapeHandler );
|
|
|
|
document.addEventListener( 'keydown', topbarFlyoutEscapeHandler );
|
2022-02-25 23:24:07 +00:00
|
|
|
|
2023-09-23 08:18:31 +00:00
|
|
|
var b = document.querySelector( '#R-body-overlay' );
|
2023-09-14 22:23:41 +00:00
|
|
|
if( b ){
|
|
|
|
b.addEventListener( 'click', closeNav );
|
2023-09-13 21:25:47 +00:00
|
|
|
}
|
2023-09-23 08:18:31 +00:00
|
|
|
var m = document.querySelector( '#R-main-overlay' );
|
2023-09-14 22:23:41 +00:00
|
|
|
if( m ){
|
|
|
|
m.addEventListener( 'click', closeSomeTopbarButtonFlyout );
|
2022-02-25 23:24:07 +00:00
|
|
|
}
|
2022-06-07 18:24:53 +00:00
|
|
|
|
|
|
|
// finally give initial focus to allow keyboard scrolling in FF
|
2022-11-17 16:29:01 +00:00
|
|
|
documentFocus();
|
2022-02-25 23:24:07 +00:00
|
|
|
}
|
|
|
|
|
2022-02-28 00:19:32 +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;
|
|
|
|
};
|
|
|
|
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;
|
2023-09-14 22:23:41 +00:00
|
|
|
closeNav();
|
2022-02-28 00:19:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
var handleEndX = function(evt) {
|
|
|
|
startx = null;
|
|
|
|
starty = null;
|
|
|
|
};
|
|
|
|
|
2023-09-23 08:18:31 +00:00
|
|
|
var s = document.querySelector( '#R-body-overlay' );
|
2023-11-28 18:56:16 +00:00
|
|
|
s && s.addEventListener("touchstart", handleStartX, { capture: false, passive: true});
|
|
|
|
document.querySelector( '#R-sidebar' ).addEventListener("touchstart", handleStartX, { capture: false, passive: true});
|
|
|
|
document.querySelectorAll( '#R-sidebar *' ).forEach( function(e){ e.addEventListener("touchstart", handleStartX, { capture: false, passive: true}) });
|
|
|
|
s && s.addEventListener("touchmove", handleMoveX, { capture: false, passive: true});
|
|
|
|
document.querySelector( '#R-sidebar' ).addEventListener("touchmove", handleMoveX, { capture: false, passive: true});
|
|
|
|
document.querySelectorAll( '#R-sidebar *' ).forEach( function(e){ e.addEventListener("touchmove", handleMoveX, { capture: false, passive: true}) });
|
|
|
|
s && s.addEventListener("touchend", handleEndX, { capture: false, passive: true});
|
|
|
|
document.querySelector( '#R-sidebar' ).addEventListener("touchend", handleEndX, { capture: false, passive: true});
|
|
|
|
document.querySelectorAll( '#R-sidebar *' ).forEach( function(e){ e.addEventListener("touchend", handleEndX, { capture: false, passive: true}) });
|
2022-02-28 00:19:32 +00:00
|
|
|
}
|
|
|
|
|
2023-02-04 22:12:40 +00:00
|
|
|
function initImage(){
|
2023-08-25 23:26:37 +00:00
|
|
|
document.querySelectorAll( '.lightbox-back' ).forEach( function(e){ e.addEventListener( 'keydown', imageEscapeHandler ); });
|
|
|
|
}
|
|
|
|
|
|
|
|
function initExpand(){
|
|
|
|
document.querySelectorAll( '.expand > input' ).forEach( function(e){ e.addEventListener( 'change', initMermaid.bind( null, true, null ) ); });
|
2023-02-04 22:12:40 +00:00
|
|
|
}
|
|
|
|
|
2022-07-03 13:40:32 +00:00
|
|
|
function clearHistory() {
|
2024-03-18 20:58:26 +00:00
|
|
|
var visitedItem = window.relearn.absBaseUri + '/visited-url/'
|
2022-07-03 13:40:32 +00:00
|
|
|
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 15:47:01 +00:00
|
|
|
document.querySelectorAll( '[data-nav-id="'+url+'"]' ).forEach( function( e ){
|
|
|
|
e.classList.remove( 'visited' );
|
|
|
|
});
|
2022-07-03 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initHistory() {
|
2024-03-18 20:58:26 +00:00
|
|
|
var visitedItem = window.relearn.absBaseUri + '/visited-url/'
|
2023-01-29 15:47:01 +00:00
|
|
|
sessionStorage.setItem( visitedItem+document.querySelector( 'body' ).dataset.url, 1);
|
2022-07-03 13:40:32 +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 15:47:01 +00:00
|
|
|
document.querySelectorAll( '[data-nav-id="'+url+'"]' ).forEach( function( e ){
|
|
|
|
e.classList.add( 'visited' );
|
|
|
|
});
|
2022-07-03 13:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-12 08:35:50 +00:00
|
|
|
function initScrollPositionSaver(){
|
|
|
|
function savePosition( event ){
|
|
|
|
var state = window.history.state || {};
|
|
|
|
state = Object.assign( {}, ( typeof state === 'object' ) ? state : {} );
|
2023-02-12 13:10:55 +00:00
|
|
|
state.contentScrollTop = +elc.scrollTop;
|
2023-02-12 08:35:50 +00:00
|
|
|
window.history.replaceState( state, '', window.location );
|
|
|
|
};
|
2024-03-16 00:14:42 +00:00
|
|
|
|
|
|
|
var ticking = false;
|
|
|
|
elc.addEventListener( 'scroll', function( event ){
|
|
|
|
if( !ticking ){
|
|
|
|
window.requestAnimationFrame( function(){
|
|
|
|
savePosition();
|
|
|
|
ticking = false;
|
|
|
|
});
|
|
|
|
ticking = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
document.addEventListener( "click", savePosition );
|
2023-02-12 08:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function scrollToPositions() {
|
|
|
|
// show active menu entry
|
|
|
|
window.setTimeout( function(){
|
2023-09-23 08:18:31 +00:00
|
|
|
var e = document.querySelector( '#R-sidebar li.active a' );
|
2021-09-05 21:40:20 +00:00
|
|
|
if( e && e.scrollIntoView ){
|
2021-09-04 09:09:38 +00:00
|
|
|
e.scrollIntoView({
|
|
|
|
block: 'center',
|
|
|
|
});
|
|
|
|
}
|
2023-02-12 08:35:50 +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:10:55 +00:00
|
|
|
if( state.hasOwnProperty( 'contentScrollTop' ) ){
|
2023-02-12 08:35:50 +00:00
|
|
|
window.setTimeout( function(){
|
2023-02-12 13:10:55 +00:00
|
|
|
elc.scrollTop = +state.contentScrollTop;
|
2023-02-12 08:35:50 +00:00
|
|
|
}, 10 );
|
|
|
|
return;
|
|
|
|
}
|
2021-09-04 09:09:38 +00:00
|
|
|
|
2024-03-18 20:58:26 +00:00
|
|
|
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
2023-02-12 13:10:55 +00:00
|
|
|
if( search && search.length ){
|
2023-08-31 10:34:23 +00:00
|
|
|
search = regexEscape( search );
|
2023-02-12 13:10:55 +00:00
|
|
|
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:35:50 +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:30:43 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-16 00:14:42 +00:00
|
|
|
window.addEventListener( 'popstate', function ( event ){
|
|
|
|
scrollToPositions();
|
|
|
|
});
|
|
|
|
|
|
|
|
const observer = new PerformanceObserver( function(){
|
|
|
|
scrollToPositions();
|
|
|
|
});
|
|
|
|
observer.observe({ type: "navigation" });
|
|
|
|
|
2023-02-01 14:42:24 +00:00
|
|
|
function mark() {
|
2024-01-05 15:31:22 +00:00
|
|
|
// mark some additional stuff as searchable
|
|
|
|
var bodyInnerLinks = document.querySelectorAll( '#R-body-inner a:not(.lightbox-link):not(.btn):not(.lightbox-back)' );
|
|
|
|
for( var i = 0; i < bodyInnerLinks.length; i++ ){
|
|
|
|
bodyInnerLinks[i].classList.add( 'highlight' );
|
|
|
|
}
|
2023-02-01 14:42:24 +00:00
|
|
|
|
2024-03-18 20:58:26 +00:00
|
|
|
var value = sessionStorage.getItem( window.relearn.absBaseUri + '/search-value' );
|
2023-02-01 14:42:24 +00:00
|
|
|
var highlightableElements = document.querySelectorAll( '.highlightable' );
|
|
|
|
highlight( highlightableElements, value, { element: 'mark' } );
|
|
|
|
|
2024-01-05 15:31:22 +00:00
|
|
|
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' ) ){
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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)' );
|
|
|
|
if( toggleInputs.length ){
|
|
|
|
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:02:33 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
2022-07-26 22:31:08 +00:00
|
|
|
}
|
2022-11-17 21:12:18 +00:00
|
|
|
window.relearn.markSearch = mark;
|
2022-07-26 22:31:08 +00:00
|
|
|
|
2023-02-01 14:42:24 +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:08 +00:00
|
|
|
});
|
2023-02-01 14:42:24 +00:00
|
|
|
words = words.map( function( word, i ){
|
2023-08-31 10:34:23 +00:00
|
|
|
return regexEscape( word );
|
2023-02-01 14:42:24 +00:00
|
|
|
});
|
|
|
|
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 );
|
|
|
|
|
2024-01-05 15:31:22 +00:00
|
|
|
for( var i = 0; i < es.length; i++ ){
|
2023-02-01 14:42:24 +00:00
|
|
|
highlightNode( es[i], re, settings.element, settings.className );
|
2024-01-05 15:31:22 +00:00
|
|
|
}
|
2023-02-01 14:42:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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() {
|
2024-03-18 20:58:26 +00:00
|
|
|
sessionStorage.removeItem( window.relearn.absBaseUri + '/search-value' );
|
2024-01-05 15:31:22 +00:00
|
|
|
var markedElements = document.querySelectorAll( 'mark' );
|
|
|
|
for( var i = 0; i < markedElements.length; i++ ){
|
|
|
|
var parent = markedElements[i].parentNode;
|
|
|
|
while( parent && parent.classList ){
|
|
|
|
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' );
|
|
|
|
if( toggleInputs.length ){
|
|
|
|
toggleInputs[0].checked = toggleInputs[0].dataset.checked === 'true';
|
|
|
|
toggleInputs[0].dataset.checked = null;
|
|
|
|
toggleInputs[0].classList.remove( 'menu-marked' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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' );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
parent = parent.parentNode;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var highlighted = document.querySelectorAll( '.highlightable' );
|
2023-02-01 14:42:24 +00:00
|
|
|
unhighlight( highlighted, { element: 'mark' } );
|
2023-02-10 16:02:33 +00:00
|
|
|
psm && setTimeout( function(){ psm.update(); }, 10 );
|
2022-07-26 22:31:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-01 14:42:24 +00:00
|
|
|
function unhighlight( es, options ){
|
|
|
|
var settings = {
|
|
|
|
className: 'highlight',
|
|
|
|
element: 'span'
|
|
|
|
};
|
|
|
|
Object.assign( settings, options );
|
|
|
|
|
2024-01-05 15:31:22 +00:00
|
|
|
for( var i = 0; i < es.length; i++ ){
|
2023-02-01 14:42:24 +00:00
|
|
|
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();
|
|
|
|
}
|
2024-01-05 15:31:22 +00:00
|
|
|
}
|
2023-02-01 14:42:24 +00:00
|
|
|
};
|
|
|
|
|
2023-01-29 22:58:43 +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:05 +00:00
|
|
|
}, false );
|
2023-01-29 22:58:43 +00:00
|
|
|
var node = null;
|
|
|
|
while( node = tree.nextNode() ){
|
|
|
|
nodes.push( node.parentElement );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nodes;
|
|
|
|
}
|
|
|
|
|
|
|
|
function searchInputHandler( value ){
|
2022-11-17 16:29:01 +00:00
|
|
|
unmark();
|
2023-01-29 22:58:43 +00:00
|
|
|
if( value.length ){
|
2024-03-18 20:58:26 +00:00
|
|
|
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', value );
|
2022-11-17 16:29:01 +00:00
|
|
|
mark();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-26 22:31:08 +00:00
|
|
|
function initSearch() {
|
2022-11-17 21:12:18 +00:00
|
|
|
// sync input/escape between searchbox and searchdetail
|
2023-01-29 22:58:43 +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;
|
2024-03-18 20:58:26 +00:00
|
|
|
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
2023-02-04 15:01:42 +00:00
|
|
|
if( !search || !search.length ){
|
|
|
|
input.blur();
|
|
|
|
}
|
2023-01-29 22:58:43 +00:00
|
|
|
searchInputHandler( '' );
|
|
|
|
inputs.forEach( function( e ){
|
|
|
|
e.value = '';
|
|
|
|
});
|
2023-02-04 15:01:42 +00:00
|
|
|
if( !search || !search.length ){
|
|
|
|
documentFocus();
|
|
|
|
}
|
2023-01-29 22:58:43 +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:08 +00:00
|
|
|
});
|
2022-11-17 16:29:01 +00:00
|
|
|
|
2023-01-29 22:58:43 +00:00
|
|
|
document.querySelectorAll( '[data-search-clear]' ).forEach( function( e ){
|
|
|
|
e.addEventListener( 'click', function(){
|
|
|
|
inputs.forEach( function( e ){
|
|
|
|
e.value = '';
|
2023-02-04 15:48:43 +00:00
|
|
|
var event = document.createEvent( 'Event' );
|
|
|
|
event.initEvent( 'input', false, false );
|
|
|
|
e.dispatchEvent( event );
|
2023-01-29 22:58:43 +00:00
|
|
|
});
|
|
|
|
unmark();
|
|
|
|
});
|
2022-07-26 22:31:08 +00:00
|
|
|
});
|
2022-11-17 21:12:18 +00:00
|
|
|
|
2023-01-29 22:58:43 +00:00
|
|
|
var urlParams = new URLSearchParams( window.location.search );
|
|
|
|
var value = urlParams.get( 'search-by' );
|
2022-11-18 08:02:39 +00:00
|
|
|
if( value ){
|
2024-03-18 20:58:26 +00:00
|
|
|
sessionStorage.setItem( window.relearn.absBaseUri+'/search-value', value );
|
2022-11-17 21:12:18 +00:00
|
|
|
}
|
2022-07-26 22:31:08 +00:00
|
|
|
mark();
|
|
|
|
|
2023-02-12 08:35:50 +00:00
|
|
|
// set initial search value for inputs on page load
|
2024-03-18 20:58:26 +00:00
|
|
|
if( sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' ) ){
|
|
|
|
var search = sessionStorage.getItem( window.relearn.absBaseUri+'/search-value' );
|
2023-01-29 22:58:43 +00:00
|
|
|
inputs.forEach( function( e ){
|
2023-02-12 08:35:50 +00:00
|
|
|
e.value = search;
|
2023-02-04 15:48:43 +00:00
|
|
|
var event = document.createEvent( 'Event' );
|
|
|
|
event.initEvent( 'input', false, false );
|
|
|
|
e.dispatchEvent( event );
|
2023-01-29 22:58:43 +00:00
|
|
|
});
|
2022-07-26 22:31:08 +00:00
|
|
|
}
|
|
|
|
|
2022-11-17 21:12:18 +00:00
|
|
|
window.relearn.isSearchInit = true;
|
|
|
|
window.relearn.runInitialSearch && window.relearn.runInitialSearch();
|
2022-07-26 22:31:08 +00:00
|
|
|
}
|
|
|
|
|
2023-08-12 21:11:21 +00:00
|
|
|
function updateTheme( detail ){
|
|
|
|
if( window.relearn.lastVariant == detail.variant ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.relearn.lastVariant = detail.variant;
|
|
|
|
|
2023-11-25 13:23:58 +00:00
|
|
|
initChroma( true );
|
2023-08-12 21:11:21 +00:00
|
|
|
initMermaid( true );
|
|
|
|
initOpenapi( true );
|
|
|
|
document.dispatchEvent( new CustomEvent( 'themeVariantLoaded', {
|
|
|
|
detail: detail
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
2023-12-03 17:16:04 +00:00
|
|
|
(function(){
|
|
|
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
|
|
|
|
initChroma( true );
|
|
|
|
initMermaid( true );
|
|
|
|
initOpenapi( true );
|
|
|
|
});
|
|
|
|
})();
|
|
|
|
|
2022-07-17 17:42:07 +00:00
|
|
|
function useMermaid( config ){
|
2022-07-17 17:52:23 +00:00
|
|
|
if( !Object.assign ){
|
|
|
|
// We don't support Mermaid for IE11 anyways, so bail out early
|
|
|
|
return;
|
|
|
|
}
|
2023-08-07 20:37:05 +00:00
|
|
|
window.relearn.mermaidConfig = config;
|
2022-07-17 17:42:07 +00:00
|
|
|
if (typeof mermaid != 'undefined' && typeof mermaid.mermaidAPI != 'undefined') {
|
2023-08-04 13:13:42 +00:00
|
|
|
mermaid.initialize( Object.assign( { "securityLevel": "antiscript", "startOnLoad": false }, config ) );
|
2022-07-17 17:42:07 +00:00
|
|
|
if( config.theme && variants ){
|
2023-09-23 08:18:31 +00:00
|
|
|
var write_style = variants.findLoadedStylesheet( 'R-variant-style' );
|
2022-07-17 17:42:07 +00:00
|
|
|
write_style.setProperty( '--CONFIG-MERMAID-theme', config.theme );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-17 17:52:23 +00:00
|
|
|
if( window.themeUseMermaid ){
|
|
|
|
useMermaid( window.themeUseMermaid );
|
2022-07-17 17:42:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-14 21:05:07 +00:00
|
|
|
function useOpenapi( config ){
|
2024-03-16 20:23:31 +00:00
|
|
|
if( config.css && config.cssInProject ){
|
2024-03-18 20:56:21 +00:00
|
|
|
config.css = window.relearn.relBasePath + config.css;
|
2024-03-16 17:40:06 +00:00
|
|
|
}
|
2022-07-17 17:42:07 +00:00
|
|
|
}
|
2023-05-14 21:05:07 +00:00
|
|
|
if( window.themeUseOpenapi ){
|
|
|
|
useOpenapi( window.themeUseOpenapi );
|
2022-07-17 17:42:07 +00:00
|
|
|
}
|
2023-09-18 18:24:49 +00:00
|
|
|
|
|
|
|
ready( function(){
|
2024-03-29 20:09:03 +00:00
|
|
|
initArrowVerticalNav();
|
|
|
|
initArrowHorizontalNav();
|
2023-09-18 18:24:49 +00:00
|
|
|
initMermaid();
|
|
|
|
initOpenapi();
|
|
|
|
initMenuScrollbar();
|
|
|
|
initToc();
|
|
|
|
initAnchorClipboard();
|
|
|
|
initCodeClipboard();
|
|
|
|
fixCodeTabs();
|
|
|
|
restoreTabSelections();
|
|
|
|
initSwipeHandler();
|
|
|
|
initHistory();
|
|
|
|
initSearch();
|
|
|
|
initImage();
|
|
|
|
initExpand();
|
|
|
|
initScrollPositionSaver();
|
|
|
|
});
|
|
|
|
|
|
|
|
(function(){
|
|
|
|
var body = document.querySelector( 'body' );
|
2023-09-23 08:18:31 +00:00
|
|
|
var topbar = document.querySelector( '#R-topbar' );
|
2023-09-18 18:24:49 +00:00
|
|
|
function addTopbarButtonInfos(){
|
|
|
|
// initially add some management infos to buttons and areas
|
|
|
|
var areas = body.querySelectorAll( '.topbar-area' );
|
|
|
|
areas.forEach( function( area ){
|
|
|
|
area.dataset.area = 'area-' + area.dataset.area;
|
|
|
|
var buttons = area.querySelectorAll( ':scope > .topbar-button' );
|
|
|
|
buttons.forEach( function( button ){
|
|
|
|
button.dataset.origin = area.dataset.area;
|
|
|
|
button.dataset.action = 'show';
|
|
|
|
var placeholder = document.createElement( 'div' );
|
|
|
|
placeholder.classList.add( 'topbar-placeholder' );
|
|
|
|
placeholder.dataset.action = 'show';
|
|
|
|
button.insertAdjacentElement( 'afterend', placeholder );
|
|
|
|
});
|
|
|
|
var placeholder = document.createElement( 'div' );
|
|
|
|
area.insertAdjacentElement( 'beforeend', placeholder );
|
|
|
|
var hidden = document.createElement( 'div' );
|
|
|
|
hidden.classList.add( 'topbar-hidden' );
|
|
|
|
hidden.dataset.area = area.dataset.area;
|
|
|
|
var hplaceholder = document.createElement( 'div' );
|
|
|
|
hidden.insertAdjacentElement( 'beforeend', hplaceholder );
|
|
|
|
area.insertAdjacentElement( 'afterend', hidden );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function moveAreaTopbarButtons( width ){
|
|
|
|
topbar.querySelectorAll( '.topbar-hidden .topbar-button' ).forEach( function( button ){
|
|
|
|
// move hidden to origins area
|
|
|
|
var placeholder = button.parentNode.parentNode.querySelector( ':scope > .topbar-area .topbar-placeholder[data-action="hide"]' );
|
|
|
|
placeholder.dataset.action = 'show';
|
|
|
|
button.dataset.action = 'show';
|
|
|
|
placeholder.insertAdjacentElement( 'beforebegin', button );
|
|
|
|
});
|
|
|
|
topbar.querySelectorAll( '.topbar-area .topbar-button' ).forEach( function( button ){
|
|
|
|
var current_area = button.dataset.action;
|
|
|
|
var origin_area = button.dataset.origin;
|
|
|
|
if( current_area != 'show' && origin_area != current_area ){
|
|
|
|
// move moved to origins area
|
|
|
|
var placeholder = topbar.querySelector( '.topbar-area[data-area="' + origin_area + '"] > .topbar-placeholder[data-action="' + current_area + '"]' );
|
|
|
|
placeholder.dataset.action = 'show';
|
|
|
|
button.dataset.action = 'show';
|
|
|
|
placeholder.insertAdjacentElement( 'beforebegin', button );
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Array.from( topbar.querySelectorAll( '.topbar-area .topbar-button' ) ).reverse().forEach( function( button ){
|
|
|
|
var parent = button.parentElement;
|
|
|
|
var current_area = parent.dataset.area;
|
|
|
|
var action = button.dataset[ 'width' + width.toUpperCase() ];
|
|
|
|
if( action == 'show' ){
|
|
|
|
}
|
|
|
|
else if( action == 'hide' ){
|
|
|
|
// move to origins hidden
|
|
|
|
var hidden = button.parentNode.parentNode.querySelector( ':scope > .topbar-hidden > *' );
|
|
|
|
var placeholder = button.nextSibling;
|
|
|
|
placeholder.dataset.action = action;
|
|
|
|
button.dataset.action = action;
|
|
|
|
hidden.insertAdjacentElement( 'beforebegin', button );
|
|
|
|
}
|
|
|
|
else if( action != current_area ){
|
|
|
|
// move to action area
|
|
|
|
var dest = button.parentNode.parentNode.querySelector( '.topbar-area[data-area="' + action + '"] > *' );
|
|
|
|
if( dest ){
|
|
|
|
var placeholder = button.nextSibling;
|
|
|
|
placeholder.dataset.action = action;
|
|
|
|
button.dataset.action = action;
|
|
|
|
dest.insertAdjacentElement( 'beforebegin', button );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
function moveTopbarButtons(){
|
2024-03-11 22:52:26 +00:00
|
|
|
var isS = body.classList.contains( 'menu-width-s' );
|
|
|
|
var isM = body.classList.contains( 'menu-width-m' );
|
|
|
|
var isL = body.classList.contains( 'menu-width-l' );
|
2023-09-18 18:24:49 +00:00
|
|
|
// move buttons once, width has a distinct value
|
|
|
|
if( isS && !isM && !isL ){
|
|
|
|
moveAreaTopbarButtons( 's' )
|
|
|
|
}
|
|
|
|
else if( !isS && isM && !isL ){
|
|
|
|
moveAreaTopbarButtons( 'm' )
|
|
|
|
}
|
|
|
|
else if( !isS && !isM && isL ){
|
|
|
|
moveAreaTopbarButtons( 'l' )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function adjustEmptyTopbarContents(){
|
|
|
|
var buttons = Array.from( document.querySelectorAll( '.topbar-button > .topbar-content > .topbar-content-wrapper' ) );
|
|
|
|
// we have to reverse order to make sure to handle innermost areas first
|
|
|
|
buttons.reverse().forEach( function( wrapper ){
|
|
|
|
var button = getTopbarButtonParent( wrapper );
|
|
|
|
if( button ){
|
|
|
|
var isEmpty = true;
|
|
|
|
var area = wrapper.querySelector( ':scope > .topbar-area');
|
|
|
|
if( area ){
|
|
|
|
// if it's an area, we have to check each contained button
|
|
|
|
// manually for its display property
|
|
|
|
var areabuttons = area.querySelectorAll( ':scope > .topbar-button' );
|
|
|
|
isEmpty = true;
|
|
|
|
areabuttons.forEach( function( ab ){
|
|
|
|
if( ab.style.display != 'none' ){
|
|
|
|
isEmpty = false;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
var clone = wrapper.cloneNode( true );
|
|
|
|
var irrelevant = clone.querySelectorAll( "div.ps__rail-x, div.ps__rail-y" );
|
|
|
|
irrelevant.forEach(function( e ) {
|
|
|
|
e.parentNode.removeChild( e );
|
|
|
|
});
|
|
|
|
isEmpty = !clone.innerHTML.trim();
|
|
|
|
}
|
|
|
|
button.querySelector( 'button' ).disabled = isEmpty;
|
|
|
|
button.style.display = isEmpty && button.dataset.contentEmpty == 'hide' ? 'none' : 'inline-block';
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2024-03-11 22:52:26 +00:00
|
|
|
function setWidthS(e){ body.classList[ e.matches ? "add" : "remove" ]( 'menu-width-s' ); }
|
|
|
|
function setWidthM(e){ body.classList[ e.matches ? "add" : "remove" ]( 'menu-width-m' ); }
|
|
|
|
function setWidthL(e){ body.classList[ e.matches ? "add" : "remove" ]( 'menu-width-l' ); }
|
2023-09-18 18:24:49 +00:00
|
|
|
function onWidthChange( setWidth, e ){
|
|
|
|
setWidth( e );
|
|
|
|
moveTopbarButtons();
|
|
|
|
adjustEmptyTopbarContents();
|
|
|
|
}
|
2023-10-05 06:51:31 +00:00
|
|
|
var mqs = window.matchMedia( 'only screen and (max-width: 47.999rem)' );
|
2023-09-18 18:24:49 +00:00
|
|
|
mqs.addEventListener( 'change', onWidthChange.bind( null, setWidthS ) );
|
2023-10-05 06:51:31 +00:00
|
|
|
var mqm = window.matchMedia( 'only screen and (min-width: 48rem) and (max-width: 59.999rem)' );
|
2023-09-18 18:24:49 +00:00
|
|
|
mqm.addEventListener( 'change', onWidthChange.bind( null, setWidthM ) );
|
|
|
|
var mql = window.matchMedia( 'only screen and (min-width: 60rem)' );
|
|
|
|
mql.addEventListener( 'change', onWidthChange.bind( null, setWidthL ) );
|
|
|
|
|
|
|
|
addTopbarButtonInfos();
|
|
|
|
setWidthS( mqs );
|
|
|
|
setWidthM( mqm );
|
|
|
|
setWidthL( mql );
|
|
|
|
moveTopbarButtons();
|
|
|
|
adjustEmptyTopbarContents();
|
|
|
|
})();
|
2024-03-11 22:52:26 +00:00
|
|
|
|
|
|
|
(function(){
|
|
|
|
var body = document.querySelector( 'body' );
|
|
|
|
function setWidth(e){ body.classList[ e.matches ? "add" : "remove" ]( 'main-width-max' ); }
|
|
|
|
function onWidthChange( setWidth, e ){
|
|
|
|
setWidth( e );
|
|
|
|
}
|
|
|
|
var width = variants.getColorValue( 'MAIN-WIDTH-MAX' );
|
|
|
|
var mqm = window.matchMedia( 'screen and ( min-width: ' + width + ')' );
|
|
|
|
mqm.addEventListener( 'change', onWidthChange.bind( null, setWidth ) );
|
|
|
|
setWidth( mqm );
|
|
|
|
})();
|