Update the documentation pages

This commit is contained in:
OpenIddict Bot
2020-07-03 21:51:56 +00:00
parent f4f15466c4
commit cf7d02d6d9
20 changed files with 870 additions and 792 deletions

View File

@@ -8,6 +8,7 @@ $(function () {
var hide = 'hide';
var util = new utility();
workAroundFixedHeaderForAnchors();
highlight();
enableSearch();
@@ -21,6 +22,7 @@ $(function () {
renderLogo();
breakText();
renderTabs();
window.refresh = function (article) {
// Update markup result
@@ -32,22 +34,24 @@ $(function () {
renderTables();
renderAlerts();
renderAffix();
renderTabs();
}
// Add this event listener when needed
// window.addEventListener('content-update', contentUpdate);
function breakText() {
$(".xref").addClass("text-break");
var texts = $(".text-break");
texts.each(function () {
$(this).text(function (index, text) {
return util.breakText(text);
})
$(this).breakWord();
});
}
// Styling for tables in conceptual documents using Bootstrap.
// See http://getbootstrap.com/css/#tables
function renderTables() {
$('table').addClass('table table-bordered table-striped table-condensed');
$('table').addClass('table table-bordered table-striped table-condensed').wrap('<div class=\"table-responsive\"></div>');
}
// Styling for alerts.
@@ -180,7 +184,7 @@ $(function () {
}
searchData = JSON.parse(this.responseText);
for (var prop in searchData) {
if (searchData.hasOwnProperty(prop)){
if (searchData.hasOwnProperty(prop)) {
lunrIndex.add(searchData[prop]);
}
}
@@ -219,6 +223,9 @@ $(function () {
$("body").bind("queryReady", function () {
worker.postMessage({ q: query });
});
if (query && (query.length >= 3)) {
worker.postMessage({ q: query });
}
});
}
@@ -340,6 +347,14 @@ $(function () {
} else {
$('#navbar ul a.active').parents('li').addClass(active);
renderBreadcrumb();
showSearch();
}
function showSearch() {
if ($('#search-results').length !== 0) {
$('#search').show();
$('body').trigger("searchEvent");
}
}
function loadNavbar() {
@@ -352,10 +367,7 @@ $(function () {
if (tocPath) tocPath = tocPath.replace(/\\/g, '/');
$.get(navbarPath, function (data) {
$(data).find("#toc>ul").appendTo("#navbar");
if ($('#search-results').length !== 0) {
$('#search').show();
$('body').trigger("searchEvent");
}
showSearch();
var index = navbarPath.lastIndexOf('/');
var navrel = '';
if (index > -1) {
@@ -370,7 +382,6 @@ $(function () {
href = navrel + href;
$(e).attr("href", href);
// TODO: currently only support one level navbar
var isActive = false;
var originalHref = e.name;
if (originalHref) {
@@ -380,7 +391,10 @@ $(function () {
}
} else {
if (util.getAbsolutePath(href) === currentAbsPath) {
isActive = true;
var dropdown = $(e).attr('data-toggle') == "dropdown"
if (!dropdown) {
isActive = true;
}
}
}
if (isActive) {
@@ -470,7 +484,7 @@ $(function () {
function filterNavItem(name, text) {
if (!text) return true;
if (name.toLowerCase().indexOf(text.toLowerCase()) > -1) return true;
if (name && name.toLowerCase().indexOf(text.toLowerCase()) > -1) return true;
return false;
}
});
@@ -500,9 +514,7 @@ $(function () {
$(e).addClass(active);
}
$(e).text(function (index, text) {
return util.breakText(text);
})
$(e).breakWord();
});
renderSidebar();
@@ -532,84 +544,86 @@ $(function () {
//Setup Affix
function renderAffix() {
var hierarchy = getHierarchy();
if (hierarchy.length > 0) {
if (hierarchy && hierarchy.length > 0) {
var html = '<h5 class="title">In This Article</h5>'
html += util.formList(hierarchy, ['nav', 'bs-docs-sidenav']);
$("#affix").empty().append(html);
if ($('footer').is(':visible')) {
$(".sideaffix").css("bottom", "70px");
}
$('#affix').on('activate.bs.scrollspy', function (e) {
if (e.target) {
if ($(e.target).find('li.active').length > 0) {
return;
}
var top = $(e.target).position().top;
$(e.target).parents('li').each(function (i, e) {
top += $(e).position().top;
});
var container = $('#affix > ul');
var height = container.height();
container.scrollTop(container.scrollTop() + top - height / 2);
$('#affix a').click(function(e) {
var scrollspy = $('[data-spy="scroll"]').data()['bs.scrollspy'];
var target = e.target.hash;
if (scrollspy && target) {
scrollspy.activate(target);
}
})
});
}
function getHierarchy() {
// supported headers are h1, h2, h3, and h4
// The topest header is ignored
var selector = ".article article";
var affixSelector = "#affix";
var headers = ['h4', 'h3', 'h2', 'h1'];
var hierarchy = [];
var toppestIndex = -1;
var startIndex = -1;
// 1. get header hierarchy
for (var i = headers.length - 1; i >= 0; i--) {
var header = $(selector + " " + headers[i]);
var length = header.length;
var $headers = $($.map(['h1', 'h2', 'h3', 'h4'], function (h) { return ".article article " + h; }).join(", "));
// If contains no header in current selector, find the next one
if (length === 0) continue;
// If the toppest header contains only one item, e.g. title, ignore
if (length === 1 && hierarchy.length === 0 && toppestIndex < 0) {
toppestIndex = i;
continue;
// a stack of hierarchy items that are currently being built
var stack = [];
$headers.each(function (i, e) {
if (!e.id) {
return;
}
// Get second level children
var nextLevelSelector = i > 0 ? headers[i - 1] : null;
var prevSelector;
for (var j = length - 1; j >= 0; j--) {
var e = header[j];
var id = e.id;
if (!id) continue; // For affix, id is a must-have
var item = {
name: htmlEncode($(e).text()),
href: "#" + id,
items: []
};
if (nextLevelSelector) {
var selector = '#' + cssEscape(id) + "~" + nextLevelSelector;
var currentSelector = selector;
if (prevSelector) currentSelector += ":not(" + prevSelector + ")";
$(header[j]).siblings(currentSelector).each(function (index, e) {
if (e.id) {
item.items.push({
name: htmlEncode($(e).text()), // innerText decodes text while innerHTML not
href: "#" + e.id
})
}
})
prevSelector = selector;
var item = {
name: htmlEncode($(e).text()),
href: "#" + e.id,
items: []
};
if (!stack.length) {
stack.push({ type: e.tagName, siblings: [item] });
return;
}
var frame = stack[stack.length - 1];
if (e.tagName === frame.type) {
frame.siblings.push(item);
} else if (e.tagName[1] > frame.type[1]) {
// we are looking at a child of the last element of frame.siblings.
// push a frame onto the stack. After we've finished building this item's children,
// we'll attach it as a child of the last element
stack.push({ type: e.tagName, siblings: [item] });
} else { // e.tagName[1] < frame.type[1]
// we are looking at a sibling of an ancestor of the current item.
// pop frames from the stack, building items as we go, until we reach the correct level at which to attach this item.
while (e.tagName[1] < stack[stack.length - 1].type[1]) {
buildParent();
}
if (e.tagName === stack[stack.length - 1].type) {
stack[stack.length - 1].siblings.push(item);
} else {
stack.push({ type: e.tagName, siblings: [item] });
}
hierarchy.push(item);
}
break;
};
hierarchy.reverse();
return hierarchy;
});
while (stack.length > 1) {
buildParent();
}
function buildParent() {
var childrenToAttach = stack.pop();
var parentFrame = stack[stack.length - 1];
var parent = parentFrame.siblings[parentFrame.siblings.length - 1];
$.each(childrenToAttach.siblings, function (i, child) {
parent.items.push(child);
});
}
if (stack.length > 0) {
var topLevel = stack.pop().siblings;
if (topLevel.length === 1) { // if there's only one topmost header, dump it
return topLevel[0].items;
}
return topLevel;
}
return undefined;
}
function htmlEncode(str) {
@@ -715,13 +729,277 @@ $(function () {
});
}
function renderTabs() {
var contentAttrs = {
id: 'data-bi-id',
name: 'data-bi-name',
type: 'data-bi-type'
};
var Tab = (function () {
function Tab(li, a, section) {
this.li = li;
this.a = a;
this.section = section;
}
Object.defineProperty(Tab.prototype, "tabIds", {
get: function () { return this.a.getAttribute('data-tab').split(' '); },
enumerable: true,
configurable: true
});
Object.defineProperty(Tab.prototype, "condition", {
get: function () { return this.a.getAttribute('data-condition'); },
enumerable: true,
configurable: true
});
Object.defineProperty(Tab.prototype, "visible", {
get: function () { return !this.li.hasAttribute('hidden'); },
set: function (value) {
if (value) {
this.li.removeAttribute('hidden');
this.li.removeAttribute('aria-hidden');
}
else {
this.li.setAttribute('hidden', 'hidden');
this.li.setAttribute('aria-hidden', 'true');
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Tab.prototype, "selected", {
get: function () { return !this.section.hasAttribute('hidden'); },
set: function (value) {
if (value) {
this.a.setAttribute('aria-selected', 'true');
this.a.tabIndex = 0;
this.section.removeAttribute('hidden');
this.section.removeAttribute('aria-hidden');
}
else {
this.a.setAttribute('aria-selected', 'false');
this.a.tabIndex = -1;
this.section.setAttribute('hidden', 'hidden');
this.section.setAttribute('aria-hidden', 'true');
}
},
enumerable: true,
configurable: true
});
Tab.prototype.focus = function () {
this.a.focus();
};
return Tab;
}());
initTabs(document.body);
function initTabs(container) {
var queryStringTabs = readTabsQueryStringParam();
var elements = container.querySelectorAll('.tabGroup');
var state = { groups: [], selectedTabs: [] };
for (var i = 0; i < elements.length; i++) {
var group = initTabGroup(elements.item(i));
if (!group.independent) {
updateVisibilityAndSelection(group, state);
state.groups.push(group);
}
}
container.addEventListener('click', function (event) { return handleClick(event, state); });
if (state.groups.length === 0) {
return state;
}
selectTabs(queryStringTabs, container);
updateTabsQueryStringParam(state);
notifyContentUpdated();
return state;
}
function initTabGroup(element) {
var group = {
independent: element.hasAttribute('data-tab-group-independent'),
tabs: []
};
var li = element.firstElementChild.firstElementChild;
while (li) {
var a = li.firstElementChild;
a.setAttribute(contentAttrs.name, 'tab');
var dataTab = a.getAttribute('data-tab').replace(/\+/g, ' ');
a.setAttribute('data-tab', dataTab);
var section = element.querySelector("[id=\"" + a.getAttribute('aria-controls') + "\"]");
var tab = new Tab(li, a, section);
group.tabs.push(tab);
li = li.nextElementSibling;
}
element.setAttribute(contentAttrs.name, 'tab-group');
element.tabGroup = group;
return group;
}
function updateVisibilityAndSelection(group, state) {
var anySelected = false;
var firstVisibleTab;
for (var _i = 0, _a = group.tabs; _i < _a.length; _i++) {
var tab = _a[_i];
tab.visible = tab.condition === null || state.selectedTabs.indexOf(tab.condition) !== -1;
if (tab.visible) {
if (!firstVisibleTab) {
firstVisibleTab = tab;
}
}
tab.selected = tab.visible && arraysIntersect(state.selectedTabs, tab.tabIds);
anySelected = anySelected || tab.selected;
}
if (!anySelected) {
for (var _b = 0, _c = group.tabs; _b < _c.length; _b++) {
var tabIds = _c[_b].tabIds;
for (var _d = 0, tabIds_1 = tabIds; _d < tabIds_1.length; _d++) {
var tabId = tabIds_1[_d];
var index = state.selectedTabs.indexOf(tabId);
if (index === -1) {
continue;
}
state.selectedTabs.splice(index, 1);
}
}
var tab = firstVisibleTab;
tab.selected = true;
state.selectedTabs.push(tab.tabIds[0]);
}
}
function getTabInfoFromEvent(event) {
if (!(event.target instanceof HTMLElement)) {
return null;
}
var anchor = event.target.closest('a[data-tab]');
if (anchor === null) {
return null;
}
var tabIds = anchor.getAttribute('data-tab').split(' ');
var group = anchor.parentElement.parentElement.parentElement.tabGroup;
if (group === undefined) {
return null;
}
return { tabIds: tabIds, group: group, anchor: anchor };
}
function handleClick(event, state) {
var info = getTabInfoFromEvent(event);
if (info === null) {
return;
}
event.preventDefault();
info.anchor.href = 'javascript:';
setTimeout(function () { return info.anchor.href = '#' + info.anchor.getAttribute('aria-controls'); });
var tabIds = info.tabIds, group = info.group;
var originalTop = info.anchor.getBoundingClientRect().top;
if (group.independent) {
for (var _i = 0, _a = group.tabs; _i < _a.length; _i++) {
var tab = _a[_i];
tab.selected = arraysIntersect(tab.tabIds, tabIds);
}
}
else {
if (arraysIntersect(state.selectedTabs, tabIds)) {
return;
}
var previousTabId = group.tabs.filter(function (t) { return t.selected; })[0].tabIds[0];
state.selectedTabs.splice(state.selectedTabs.indexOf(previousTabId), 1, tabIds[0]);
for (var _b = 0, _c = state.groups; _b < _c.length; _b++) {
var group_1 = _c[_b];
updateVisibilityAndSelection(group_1, state);
}
updateTabsQueryStringParam(state);
}
notifyContentUpdated();
var top = info.anchor.getBoundingClientRect().top;
if (top !== originalTop && event instanceof MouseEvent) {
window.scrollTo(0, window.pageYOffset + top - originalTop);
}
}
function selectTabs(tabIds) {
for (var _i = 0, tabIds_1 = tabIds; _i < tabIds_1.length; _i++) {
var tabId = tabIds_1[_i];
var a = document.querySelector(".tabGroup > ul > li > a[data-tab=\"" + tabId + "\"]:not([hidden])");
if (a === null) {
return;
}
a.dispatchEvent(new CustomEvent('click', { bubbles: true }));
}
}
function readTabsQueryStringParam() {
var qs = parseQueryString();
var t = qs.tabs;
if (t === undefined || t === '') {
return [];
}
return t.split(',');
}
function updateTabsQueryStringParam(state) {
var qs = parseQueryString();
qs.tabs = state.selectedTabs.join();
var url = location.protocol + "//" + location.host + location.pathname + "?" + toQueryString(qs) + location.hash;
if (location.href === url) {
return;
}
history.replaceState({}, document.title, url);
}
function toQueryString(args) {
var parts = [];
for (var name_1 in args) {
if (args.hasOwnProperty(name_1) && args[name_1] !== '' && args[name_1] !== null && args[name_1] !== undefined) {
parts.push(encodeURIComponent(name_1) + '=' + encodeURIComponent(args[name_1]));
}
}
return parts.join('&');
}
function parseQueryString(queryString) {
var match;
var pl = /\+/g;
var search = /([^&=]+)=?([^&]*)/g;
var decode = function (s) { return decodeURIComponent(s.replace(pl, ' ')); };
if (queryString === undefined) {
queryString = '';
}
queryString = queryString.substring(1);
var urlParams = {};
while (match = search.exec(queryString)) {
urlParams[decode(match[1])] = decode(match[2]);
}
return urlParams;
}
function arraysIntersect(a, b) {
for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
var itemA = a_1[_i];
for (var _a = 0, b_1 = b; _a < b_1.length; _a++) {
var itemB = b_1[_a];
if (itemA === itemB) {
return true;
}
}
}
return false;
}
function notifyContentUpdated() {
// Dispatch this event when needed
// window.dispatchEvent(new CustomEvent('content-update'));
}
}
function utility() {
this.getAbsolutePath = getAbsolutePath;
this.isRelativePath = isRelativePath;
this.isAbsolutePath = isAbsolutePath;
this.getDirectory = getDirectory;
this.formList = formList;
this.breakText = breakText;
function getAbsolutePath(href) {
// Use anchor to normalize href
@@ -731,6 +1009,9 @@ $(function () {
}
function isRelativePath(href) {
if (href === undefined || href === '' || href[0] === '/') {
return false;
}
return !isAbsolutePath(href);
}
@@ -747,7 +1028,6 @@ $(function () {
}
}
function formList(item, classes) {
var level = 1;
var model = {
@@ -776,9 +1056,95 @@ $(function () {
}
}
function breakText(text) {
/**
* Add <wbr> into long word.
* @param {String} text - The word to break. It should be in plain text without HTML tags.
*/
function breakPlainText(text) {
if (!text) return text;
return text.replace(/([a-z])([A-Z])|(\.)(\w)/g, '$1$3\u200B$2$4')
return text.replace(/([a-z])([A-Z])|(\.)(\w)/g, '$1$3<wbr>$2$4')
}
/**
* Add <wbr> into long word. The jQuery element should contain no html tags.
* If the jQuery element contains tags, this function will not change the element.
*/
$.fn.breakWord = function () {
if (this.html() == this.text()) {
this.html(function (index, text) {
return breakPlainText(text);
})
}
return this;
}
}
})
// adjusted from https://stackoverflow.com/a/13067009/1523776
function workAroundFixedHeaderForAnchors() {
var HISTORY_SUPPORT = !!(history && history.pushState);
var ANCHOR_REGEX = /^#[^ ]+$/;
function getFixedOffset() {
return $('header').first().height();
}
/**
* If the provided href is an anchor which resolves to an element on the
* page, scroll to it.
* @param {String} href
* @return {Boolean} - Was the href an anchor.
*/
function scrollIfAnchor(href, pushToHistory) {
var match, rect, anchorOffset;
if (!ANCHOR_REGEX.test(href)) {
return false;
}
match = document.getElementById(href.slice(1));
if (match) {
rect = match.getBoundingClientRect();
anchorOffset = window.pageYOffset + rect.top - getFixedOffset();
window.scrollTo(window.pageXOffset, anchorOffset);
// Add the state to history as-per normal anchor links
if (HISTORY_SUPPORT && pushToHistory) {
history.pushState({}, document.title, location.pathname + href);
}
}
return !!match;
}
/**
* Attempt to scroll to the current location's hash.
*/
function scrollToCurrent() {
scrollIfAnchor(window.location.hash);
}
/**
* If the click event's target was an anchor, fix the scroll position.
*/
function delegateAnchors(e) {
var elem = e.target;
if (scrollIfAnchor(elem.getAttribute('href'), true)) {
e.preventDefault();
}
}
$(window).on('hashchange', scrollToCurrent);
$(window).load(function () {
// scroll to the anchor if present, offset by the header
scrollToCurrent();
});
$(document).ready(function () {
// Exclude tabbed content case
$('a:not([data-tab])').click(function (e) { delegateAnchors(e); });
});
}
});