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' );
|
|
|
|
}
|
2022-04-02 13:29:34 +00:00
|
|
|
var isPrint = document.querySelector( 'body' ).classList.contains( 'print' );
|
|
|
|
|
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-22 22:08:07 +00:00
|
|
|
// rapidoc: #280 disable broad document syntax highlightning
|
|
|
|
window.Prism = window.Prism || {};
|
|
|
|
Prism.manual = true;
|
|
|
|
|
2022-06-06 21:58:00 +00:00
|
|
|
// PerfectScrollbar
|
|
|
|
var psc;
|
|
|
|
var psm;
|
|
|
|
var pst;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-03-16 17:21:57 +00:00
|
|
|
function switchTab(tabGroup, tabId) {
|
2022-06-22 20:16:22 +00:00
|
|
|
var tabs = jQuery(".tab-panel").has("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']");
|
|
|
|
var allTabItems = tabs.find("[data-tab-group='"+tabGroup+"']");
|
|
|
|
var targetTabItems = tabs.find("[data-tab-group='"+tabGroup+"'][data-tab-item='"+tabId+"']");
|
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
|
|
|
|
var isButtonEvent = event != undefined;
|
|
|
|
|
|
|
|
if(isButtonEvent){
|
|
|
|
// save button position relative to viewport
|
|
|
|
var yposButton = event.target.getBoundingClientRect().top;
|
|
|
|
}
|
|
|
|
|
|
|
|
allTabItems.removeClass("active");
|
|
|
|
targetTabItems.addClass("active");
|
|
|
|
|
|
|
|
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 17:26:20 +00:00
|
|
|
var selectionsJSON = window.localStorage.getItem(baseUriFull+"tab-selections");
|
2021-03-16 17:21:57 +00:00
|
|
|
if(selectionsJSON){
|
|
|
|
var tabSelections = JSON.parse(selectionsJSON);
|
|
|
|
}else{
|
|
|
|
var tabSelections = {};
|
|
|
|
}
|
|
|
|
tabSelections[tabGroup] = tabId;
|
2022-03-07 17:26:20 +00:00
|
|
|
window.localStorage.setItem(baseUriFull+"tab-selections", JSON.stringify(tabSelections));
|
2021-03-16 17:21:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function restoreTabSelections() {
|
|
|
|
if(window.localStorage){
|
2022-03-07 17:26:20 +00:00
|
|
|
var selectionsJSON = window.localStorage.getItem(baseUriFull+"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 ) {
|
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 ){
|
|
|
|
var d = /^\s*(%%\s*\{\s*\w+\s*:([^%]*?)%%\s*\n?)/g;
|
|
|
|
var m = d.exec( graph );
|
|
|
|
var dir = {};
|
|
|
|
var content = graph;
|
|
|
|
if( m && m.length == 3 ){
|
|
|
|
dir = JSON.parse( '{ "dummy": ' + m[2] ).dummy;
|
|
|
|
content = graph.substring( d.lastIndex );
|
|
|
|
}
|
|
|
|
return { dir: dir, content: content };
|
|
|
|
};
|
|
|
|
|
|
|
|
var serializeGraph = function( graph ){
|
|
|
|
return '%%{init: ' + JSON.stringify( graph.dir ) + '}%%\n' + graph.content;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2022-03-27 16:42:11 +00:00
|
|
|
if( parse.dir.theme ){
|
|
|
|
parse.dir.relearn_user_theme = true;
|
2022-03-19 19:18:21 +00:00
|
|
|
}
|
2022-03-27 16:42:11 +00:00
|
|
|
if( !parse.dir.relearn_user_theme ){
|
|
|
|
parse.dir.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 );
|
|
|
|
element.innerHTML = graph;
|
2022-03-19 19:18:21 +00:00
|
|
|
var new_element = document.createElement( 'div' );
|
|
|
|
new_element.classList.add( 'mermaid-container' );
|
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 ) );
|
|
|
|
|
|
|
|
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:06 +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' ),
|
|
|
|
};
|
|
|
|
var is_initialized = ( update ? update_func( attrs ) : init_func( attrs ) );
|
2022-03-27 16:42:11 +00:00
|
|
|
if( is_initialized ){
|
2022-03-19 19:18:21 +00:00
|
|
|
mermaid.init();
|
2021-11-09 20:05:54 +00:00
|
|
|
$(".mermaid svg").svgPanZoom({});
|
2021-07-02 19:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-29 19:55:06 +00:00
|
|
|
function initSwagger( update, attrs ){
|
|
|
|
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(){
|
|
|
|
initSwagger( true, {
|
|
|
|
'bg-color': variants.getColorValue( 'PRINT-MAIN-BG-color' ),
|
|
|
|
'mono-font': variants.getColorValue( 'PRINT-CODE-font' ),
|
|
|
|
'primary-color': variants.getColorValue( 'PRINT-TAG-BG-color' ),
|
|
|
|
'regular-font': variants.getColorValue( 'PRINT-MAIN-font' ),
|
|
|
|
'text-color': variants.getColorValue( 'PRINT-MAIN-TEXT-color' ),
|
|
|
|
'theme': variants.getColorValue( 'PRINT-SWAGGER-theme' ),
|
|
|
|
});
|
|
|
|
}.bind( this ) );
|
|
|
|
window.addEventListener( 'afterprint', function(){
|
|
|
|
initSwagger( true );
|
|
|
|
}.bind( this ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs = attrs || {
|
|
|
|
'bg-color': variants.getColorValue( 'MAIN-BG-color' ),
|
|
|
|
'mono-font': variants.getColorValue( 'CODE-font' ),
|
|
|
|
'primary-color': variants.getColorValue( 'TAG-BG-color' ),
|
|
|
|
'regular-font': variants.getColorValue( 'MAIN-font' ),
|
|
|
|
'text-color': variants.getColorValue( 'MAIN-TEXT-color' ),
|
|
|
|
'theme': variants.getColorValue( 'SWAGGER-theme' ),
|
|
|
|
};
|
2022-03-27 16:42:11 +00:00
|
|
|
document.querySelectorAll( 'rapi-doc' ).forEach( function( e ){
|
2022-07-29 19:55:06 +00:00
|
|
|
Object.keys( attrs ).forEach( function( key ){
|
|
|
|
/* this doesn't work for FF 102, maybe related to custom elements? */
|
|
|
|
e.setAttribute( key, attrs[key] );
|
2022-03-27 20:24:06 +00:00
|
|
|
});
|
2022-03-27 16:42:11 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 22:24:25 +00:00
|
|
|
function initAnchorClipboard(){
|
2022-03-25 14:35:19 +00:00
|
|
|
document.querySelectorAll( 'h1~h2,h1~h3,h1~h4,h1~h5,h1~h6').forEach( function( element ){
|
2022-02-25 22:24:25 +00:00
|
|
|
var url = encodeURI(document.location.origin + document.location.pathname);
|
2022-03-25 14:35:19 +00:00
|
|
|
var link = url + "#"+element.id;
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
$(".anchor").on('mouseleave', function(e) {
|
2022-11-07 19:57:17 +00:00
|
|
|
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-se tooltipped-sw');
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
|
2022-03-25 14:35:19 +00:00
|
|
|
var clip = new ClipboardJS('.anchor');
|
2022-02-25 22:24:25 +00:00
|
|
|
clip.on('success', function(e) {
|
|
|
|
e.clearSelection();
|
2022-11-07 19:57:17 +00:00
|
|
|
var rtl = $(e.trigger).closest('*[dir]').attr('dir') == 'rtl';
|
|
|
|
$(e.trigger).attr('aria-label', window.T_Link_copied_to_clipboard).addClass('tooltipped tooltipped-s'+(rtl?'e':'w') );
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initCodeClipboard(){
|
|
|
|
function fallbackMessage(action) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('code').each(function() {
|
2022-07-03 13:10:53 +00:00
|
|
|
var code = $(this);
|
|
|
|
var text = code.text();
|
|
|
|
var parent = code.parent();
|
|
|
|
var inPre = parent.prop('tagName') == 'PRE';
|
2022-02-25 22:24:25 +00:00
|
|
|
|
2022-07-03 13:10:53 +00:00
|
|
|
if (inPre || text.length > 5) {
|
2022-02-25 22:24:25 +00:00
|
|
|
var clip = new ClipboardJS('.copy-to-clipboard-button', {
|
|
|
|
text: function(trigger) {
|
|
|
|
var text = $(trigger).prev('code').text();
|
|
|
|
// 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, '');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
clip.on('success', function(e) {
|
|
|
|
e.clearSelection();
|
|
|
|
var inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
2022-11-07 19:57:17 +00:00
|
|
|
var rtl = $(e.trigger).closest('*[dir]').attr('dir') == 'rtl';
|
|
|
|
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'+(rtl?'e':'w')));
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
clip.on('error', function(e) {
|
|
|
|
var inPre = $(e.trigger).parent().prop('tagName') == 'PRE';
|
2022-11-07 19:57:17 +00:00
|
|
|
var rtl = $(this).closest('*[dir]').attr('dir') == 'rtl';
|
|
|
|
$(e.trigger).attr('aria-label', fallbackMessage(e.action)).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'+(rtl?'e':'w')));
|
2022-02-25 22:24:25 +00:00
|
|
|
$(document).one('copy', function(){
|
2022-11-07 19:57:17 +00:00
|
|
|
$(e.trigger).attr('aria-label', window.T_Copied_to_clipboard).addClass('tooltipped tooltipped-' + (inPre ? 'w' : 's'+(rtl?'e':'w')));
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
code.addClass('copy-to-clipboard-code');
|
|
|
|
if( inPre ){
|
2022-11-01 01:00:50 +00:00
|
|
|
parent.addClass( 'copy-to-clipboard' ).addClass( 'pre-code' );
|
2022-02-25 22:24:25 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
code.replaceWith($('<span/>', {'class': 'copy-to-clipboard'}).append(code.clone() ));
|
|
|
|
code = parent.children('.copy-to-clipboard').last().children('.copy-to-clipboard-code');
|
|
|
|
}
|
|
|
|
code.after( $('<span>').addClass("copy-to-clipboard-button").attr("title", window.T_Copy_to_clipboard).append("<i class='fas fa-copy'></i>") );
|
|
|
|
code.next('.copy-to-clipboard-button').on('mouseleave', function() {
|
2022-11-07 19:57:17 +00:00
|
|
|
var rtl = $(this).closest('*[dir]').attr('dir') == 'rtl';
|
|
|
|
$(this).attr('aria-label', null).removeClass('tooltipped tooltipped-w tooltipped-se tooltipped-sw');
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initArrowNav(){
|
2022-07-03 11:31:08 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-02-25 22:24:25 +00:00
|
|
|
// button navigation
|
|
|
|
jQuery(function() {
|
|
|
|
jQuery('a.nav-prev').click(function(){
|
|
|
|
location.href = jQuery(this).attr('href');
|
|
|
|
});
|
|
|
|
jQuery('a.nav-next').click(function() {
|
|
|
|
location.href = jQuery(this).attr('href');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// keyboard navigation
|
|
|
|
jQuery(document).keydown(function(e) {
|
2022-11-11 00:05:42 +00:00
|
|
|
if(!e.shiftKey && !e.ctrlKey && !e.altKey && !e.metaKey){
|
|
|
|
if(e.which == '37') {
|
|
|
|
jQuery('a.nav-prev').click();
|
|
|
|
}
|
|
|
|
if(e.which == '39') {
|
|
|
|
jQuery('a.nav-next').click();
|
|
|
|
}
|
|
|
|
}
|
2022-02-25 22:24:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// avoid keyboard navigation for input fields
|
2022-03-06 10:45:33 +00:00
|
|
|
jQuery(formelements).keydown(function (e) {
|
2022-02-25 22:24:25 +00:00
|
|
|
if (e.which == '37' || e.which == '39') {
|
|
|
|
e.stopPropagation();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-02-25 23:24:07 +00:00
|
|
|
function initMenuScrollbar(){
|
2022-04-02 13:29:34 +00:00
|
|
|
if( isPrint ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-12 12:06:30 +00:00
|
|
|
var elc = document.querySelector('#body-inner');
|
|
|
|
var elm = document.querySelector('#content-wrapper');
|
|
|
|
var elt = document.querySelector('#TableOfContents');
|
|
|
|
|
2022-02-28 00:19:32 +00:00
|
|
|
var autofocus = false;
|
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-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
|
|
|
|
autofocus = true;
|
|
|
|
// if we are showing the sidebar as a flyout we
|
|
|
|
// want to scroll the content-wrapper, otherwise we want
|
|
|
|
// to scroll the body
|
2022-06-06 21:58:00 +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:10:35 +00:00
|
|
|
psm && psm.scrollbarY.focus();
|
2022-02-28 00:19:32 +00:00
|
|
|
}
|
|
|
|
else{
|
2022-06-06 21:58:00 +00:00
|
|
|
document.querySelector('#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
|
2022-06-12 12:06:30 +00:00
|
|
|
// psc = elc && new PerfectScrollbar('#body-inner');
|
|
|
|
psm = elm && new PerfectScrollbar('#content-wrapper');
|
|
|
|
pst = elt && new PerfectScrollbar('#TableOfContents');
|
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();
|
2022-06-06 21:58:00 +00:00
|
|
|
pst && pst.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(){
|
2022-06-06 21:58:00 +00:00
|
|
|
pst && pst.update();
|
2022-04-03 10:12:12 +00:00
|
|
|
psm && psm.update();
|
|
|
|
psc && psc.update();
|
|
|
|
});
|
|
|
|
// now that we may have collapsible menus, we need to call a resize
|
|
|
|
// for the menu scrollbar if sections are expanded/collapsed
|
|
|
|
document.querySelectorAll('#sidebar .collapsible-menu input.toggle').forEach( function(e){
|
|
|
|
e.addEventListener('change', function(){
|
|
|
|
psm && psm.update();
|
|
|
|
});
|
|
|
|
});
|
2022-07-02 18:29:24 +00:00
|
|
|
|
|
|
|
// finally, we want to adjust the contents right padding if there is a scrollbar visible
|
|
|
|
var scrollbarSize = scrollbarWidth();
|
|
|
|
function adjustContentWidth(){
|
|
|
|
var left = parseFloat( getComputedStyle( elc ).getPropertyValue( 'padding-left' ) );
|
|
|
|
var right = left;
|
|
|
|
if( elc.scrollHeight > elc.clientHeight ){
|
|
|
|
// if we have a scrollbar reduce the right margin by the scrollbar width
|
|
|
|
right = Math.max( 0, left - scrollbarSize );
|
|
|
|
}
|
|
|
|
elc.style[ 'padding-right' ] = '' + right + 'px';
|
|
|
|
}
|
|
|
|
window.addEventListener('resize', adjustContentWidth );
|
|
|
|
adjustContentWidth();
|
2022-02-25 23:24:07 +00:00
|
|
|
}
|
|
|
|
|
2022-06-06 21:58:00 +00:00
|
|
|
function sidebarEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'sidebar-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', sidebarEscapeHandler );
|
|
|
|
document.querySelector( '#body-inner' ).focus();
|
|
|
|
psc && psc.scrollbarY.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tocEscapeHandler( event ){
|
|
|
|
if( event.key == "Escape" ){
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'toc-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', tocEscapeHandler );
|
|
|
|
document.querySelector( '#body-inner' ).focus();
|
|
|
|
psc && psc.scrollbarY.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 23:35:54 +00:00
|
|
|
function sidebarShortcutHandler( event ){
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 78 /* n */ ){
|
2022-06-06 23:35:54 +00:00
|
|
|
showNav();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function tocShortcutHandler( event ){
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !event.shiftKey && event.altKey && event.ctrlKey && !event.metaKey && event.which == 84 /* t */ ){
|
2022-06-06 23:35:54 +00:00
|
|
|
showToc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showNav(){
|
|
|
|
if( !document.querySelector( '#sidebar-overlay' ) ){
|
|
|
|
// we may not have a flyout
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.toggle( 'sidebar-flyout' );
|
|
|
|
if( b.classList.contains( 'sidebar-flyout' ) ){
|
|
|
|
b.classList.remove( 'toc-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', tocEscapeHandler );
|
|
|
|
document.addEventListener( 'keydown', sidebarEscapeHandler );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
document.removeEventListener( 'keydown', sidebarEscapeHandler );
|
|
|
|
document.querySelector( '#body-inner' ).focus();
|
|
|
|
psc && psc.scrollbarY.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showToc(){
|
|
|
|
var t = document.querySelector( '#toc-menu' );
|
|
|
|
if( !t ){
|
|
|
|
// we may not have a toc
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.toggle( 'toc-flyout' );
|
|
|
|
if( b.classList.contains( 'toc-flyout' ) ){
|
|
|
|
pst && pst.update();
|
|
|
|
document.addEventListener( 'keydown', tocEscapeHandler );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
document.removeEventListener( 'keydown', tocEscapeHandler );
|
|
|
|
document.querySelector( '#body-inner' ).focus();
|
|
|
|
psc && psc.scrollbarY.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showEdit(){
|
|
|
|
var l = document.querySelector( '#top-github-link a' );
|
|
|
|
if( l ){
|
|
|
|
l.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function showPrint(){
|
|
|
|
var l = document.querySelector( '#top-print-link a' );
|
|
|
|
if( l ){
|
|
|
|
l.click();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|
|
|
|
document.addEventListener( 'keydown', printShortcutHandler );
|
|
|
|
document.addEventListener( 'keydown', sidebarShortcutHandler );
|
|
|
|
document.addEventListener( 'keydown', tocShortcutHandler );
|
|
|
|
// avoid keyboard navigation for input fields
|
|
|
|
jQuery(formelements).keydown(function (e) {
|
2022-11-11 00:05:42 +00:00
|
|
|
if( !e.shiftKey && e.altKey && e.ctrlKey && !e.metaKey){
|
|
|
|
if( e.which == 78 /* n */ || e.which == 84 /* t */ || e.which == 87 /* w */ || e.which == 80 /* p */ ){
|
2022-06-06 23:35:54 +00:00
|
|
|
e.stopPropagation();
|
|
|
|
}
|
2022-06-06 21:58:00 +00:00
|
|
|
}
|
2022-06-06 23:35:54 +00:00
|
|
|
});
|
2022-02-25 23:24:07 +00:00
|
|
|
|
2022-02-28 00:19:32 +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:07 +00:00
|
|
|
}
|
2022-06-07 18:24:53 +00:00
|
|
|
|
|
|
|
// finally give initial focus to allow keyboard scrolling in FF
|
|
|
|
document.querySelector( '#body-inner' ).focus();
|
|
|
|
psc && psc.scrollbarY.focus();
|
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;
|
|
|
|
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:00 +00:00
|
|
|
var b = document.querySelector( 'body' );
|
|
|
|
b.classList.remove( 'sidebar-flyout' );
|
|
|
|
document.removeEventListener( 'keydown', sidebarEscapeHandler );
|
|
|
|
document.querySelector( '#body-inner' ).focus();
|
|
|
|
psc && psc.scrollbarY.focus();
|
2022-02-28 00:19:32 +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);
|
|
|
|
}
|
|
|
|
|
2022-07-03 13:40:32 +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( /^\/+\//, '/' );
|
|
|
|
jQuery('[data-nav-id="' + url + '"]').removeClass('visited');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function initHistory() {
|
|
|
|
var visitedItem = baseUriFull + 'visited-url/'
|
|
|
|
sessionStorage.setItem(visitedItem+jQuery('body').data('url'), 1);
|
|
|
|
|
|
|
|
// loop through the sessionStorage and see if something should be marked as visited
|
|
|
|
for( var item in sessionStorage ){
|
|
|
|
if( item.substring( 0, visitedItem.length ) === visitedItem && sessionStorage.getItem( item ) == 1 ){
|
|
|
|
var url = item.substring( visitedItem.length );
|
|
|
|
// in case we have `relativeURLs=true` we have to strip the
|
|
|
|
// relative path to root
|
|
|
|
url = url.replace( /\.\.\//g, '/' ).replace( /^\/+\//, '/' );
|
|
|
|
jQuery('[data-nav-id="' + url + '"]').addClass('visited');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-04 09:09:38 +00:00
|
|
|
function scrollToActiveMenu() {
|
|
|
|
window.setTimeout(function(){
|
2022-04-02 13:30:43 +00:00
|
|
|
var e = document.querySelector( '#sidebar ul.topics 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',
|
|
|
|
});
|
|
|
|
}
|
2022-02-28 00:19:32 +00:00
|
|
|
}, 10);
|
2021-09-04 09:09:38 +00:00
|
|
|
}
|
|
|
|
|
2022-04-02 13:30:43 +00:00
|
|
|
function scrollToFragment() {
|
|
|
|
if( !window.location.hash || window.location.hash.length <= 1 ){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.setTimeout(function(){
|
|
|
|
var e = document.querySelector( window.location.hash );
|
|
|
|
if( e && e.scrollIntoView ){
|
|
|
|
e.scrollIntoView({
|
|
|
|
block: 'start',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
}
|
|
|
|
|
2022-07-26 22:31:08 +00:00
|
|
|
function mark(){
|
|
|
|
var value = sessionStorage.getItem(baseUriFull+'search-value');
|
|
|
|
$(".highlightable").highlight(value, { element: 'mark' });
|
|
|
|
$("mark").parents(".expand").addClass("expand-marked");
|
|
|
|
$("mark").parents("li").each( function(){
|
|
|
|
var i = jQuery(this).children("input.toggle:not(.menu-marked)");
|
|
|
|
if( i.length ){
|
|
|
|
e = jQuery(i[0]);
|
|
|
|
e.attr("data-checked", (e.prop('checked')?"true":"false")).addClass("menu-marked");
|
|
|
|
i[0].checked = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
psm && psm.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
function unmark(){
|
|
|
|
sessionStorage.removeItem(baseUriFull+'search-value');
|
|
|
|
$("mark").parents("li").each( function(){
|
|
|
|
var i = jQuery(this).children("input.toggle.menu-marked");
|
|
|
|
if( i.length ){
|
|
|
|
e = jQuery(i[0]);
|
|
|
|
i[0].checked = (e.attr("data-checked")=="true");
|
|
|
|
e.attr("data-checked", null).removeClass("menu-marked");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$("mark").parents(".expand-marked").removeClass("expand-marked");
|
|
|
|
$(".highlightable").unhighlight({ element: 'mark' })
|
|
|
|
psm && psm.update();
|
|
|
|
}
|
|
|
|
|
|
|
|
function initSearch() {
|
|
|
|
jQuery('[data-search-input]').on('input', function() {
|
|
|
|
var input = jQuery(this);
|
|
|
|
var value = input.val();
|
|
|
|
unmark();
|
|
|
|
if (value.length) {
|
|
|
|
sessionStorage.setItem(baseUriFull+'search-value', value);
|
|
|
|
mark();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
jQuery('[data-search-clear]').on('click', function() {
|
|
|
|
jQuery('[data-search-input]').val('').trigger('input');
|
|
|
|
unmark();
|
|
|
|
});
|
|
|
|
mark();
|
|
|
|
|
|
|
|
// custom sizzle case insensitive "contains" pseudo selector
|
|
|
|
$.expr[":"].contains = $.expr.createPseudo(function(arg) {
|
|
|
|
return function( elem ) {
|
|
|
|
return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
// set initial search value on page load
|
|
|
|
if (sessionStorage.getItem(baseUriFull+'search-value')) {
|
|
|
|
var searchValue = sessionStorage.getItem(baseUriFull+'search-value')
|
|
|
|
$('[data-search-input]').val(searchValue);
|
|
|
|
$('[data-search-input]').trigger('input');
|
|
|
|
var searchedElem = $('#body-inner').find(':contains(' + searchValue + ')').get(0);
|
|
|
|
if (searchedElem) {
|
|
|
|
searchedElem.scrollIntoView(true);
|
|
|
|
var scrolledY = window.scrollY;
|
|
|
|
if(scrolledY){
|
|
|
|
window.scroll(0, scrolledY - 125);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// mark some additonal stuff as searchable
|
|
|
|
$('#topbar a:not(:has(img)):not(.btn)').addClass('highlight');
|
|
|
|
$('#body-inner a:not(:has(img)):not(.btn):not(a[rel="footnote"])').addClass('highlight');
|
|
|
|
}
|
|
|
|
|
2016-03-17 11:01:39 +00:00
|
|
|
// debouncing function from John Hann
|
|
|
|
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
|
|
|
|
(function($, sr) {
|
|
|
|
|
|
|
|
var debounce = function(func, threshold, execAsap) {
|
|
|
|
var timeout;
|
|
|
|
|
|
|
|
return function debounced() {
|
|
|
|
var obj = this, args = arguments;
|
|
|
|
|
|
|
|
function delayed() {
|
|
|
|
if (!execAsap)
|
|
|
|
func.apply(obj, args);
|
|
|
|
timeout = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (timeout)
|
|
|
|
clearTimeout(timeout);
|
|
|
|
else if (execAsap)
|
|
|
|
func.apply(obj, args);
|
|
|
|
|
|
|
|
timeout = setTimeout(delayed, threshold || 100);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
// smartresize
|
|
|
|
jQuery.fn[sr] = function(fn) { return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
|
|
|
|
|
|
|
|
})(jQuery, 'smartresize');
|
|
|
|
|
2021-07-02 19:58:16 +00:00
|
|
|
jQuery(function() {
|
2022-02-25 22:24:25 +00:00
|
|
|
initArrowNav();
|
2022-02-28 00:19:32 +00:00
|
|
|
initMermaid();
|
2022-03-27 16:42:11 +00:00
|
|
|
initSwagger();
|
2022-02-25 23:24:07 +00:00
|
|
|
initMenuScrollbar();
|
2022-02-28 00:19:32 +00:00
|
|
|
scrollToActiveMenu();
|
2022-04-02 13:30:43 +00:00
|
|
|
scrollToFragment();
|
2022-02-25 23:24:07 +00:00
|
|
|
initToc();
|
2022-02-28 00:19:32 +00:00
|
|
|
initAnchorClipboard();
|
|
|
|
initCodeClipboard();
|
|
|
|
restoreTabSelections();
|
|
|
|
initSwipeHandler();
|
2022-07-03 13:40:32 +00:00
|
|
|
initHistory();
|
2022-07-26 22:31:08 +00:00
|
|
|
initSearch();
|
2016-03-17 11:01:39 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.extend({
|
|
|
|
highlight: function(node, re, nodeName, className) {
|
2021-09-13 19:09:44 +00:00
|
|
|
if (node.nodeType === 3 && node.parentElement && node.parentElement.namespaceURI == 'http://www.w3.org/1999/xhtml') { // text nodes
|
2016-03-17 11:01:39 +00:00
|
|
|
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 += jQuery.highlight(node.childNodes[i], re, nodeName, className);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
jQuery.fn.unhighlight = function(options) {
|
|
|
|
var settings = {
|
|
|
|
className: 'highlight',
|
|
|
|
element: 'span'
|
|
|
|
};
|
|
|
|
jQuery.extend(settings, options);
|
|
|
|
|
|
|
|
return this.find(settings.element + "." + settings.className).each(function() {
|
|
|
|
var parent = this.parentNode;
|
|
|
|
parent.replaceChild(this.firstChild, this);
|
|
|
|
parent.normalize();
|
|
|
|
}).end();
|
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.fn.highlight = function(words, options) {
|
|
|
|
var settings = {
|
|
|
|
className: 'highlight',
|
|
|
|
element: 'span',
|
|
|
|
caseSensitive: false,
|
|
|
|
wordsOnly: false
|
|
|
|
};
|
|
|
|
jQuery.extend(settings, options);
|
|
|
|
|
|
|
|
if (!words) { return; }
|
|
|
|
|
|
|
|
if (words.constructor === String) {
|
|
|
|
words = [words];
|
|
|
|
}
|
|
|
|
words = jQuery.grep(words, function(word, i) {
|
|
|
|
return word != '';
|
|
|
|
});
|
|
|
|
words = jQuery.map(words, 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);
|
|
|
|
|
|
|
|
return this.each(function() {
|
|
|
|
jQuery.highlight(this, re, settings.element, settings.className);
|
|
|
|
});
|
|
|
|
};
|
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;
|
|
|
|
}
|
2022-07-17 17:42:07 +00:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-07-17 17:52:23 +00:00
|
|
|
if( window.themeUseMermaid ){
|
|
|
|
useMermaid( window.themeUseMermaid );
|
2022-07-17 17:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function useSwagger( config ){
|
|
|
|
if( config.theme && variants ){
|
|
|
|
var write_style = variants.findLoadedStylesheet( 'variant-style' );
|
|
|
|
write_style.setProperty( '--CONFIG-SWAGGER-theme', config.theme );
|
|
|
|
}
|
|
|
|
}
|
2022-07-17 17:52:23 +00:00
|
|
|
if( window.themeUseSwagger ){
|
|
|
|
useSwagger( window.themeUseSwagger );
|
2022-07-17 17:42:07 +00:00
|
|
|
}
|