NBash
483 строки · 15.5 Кб
1/*
2@licstart The following is the entire license notice for the JavaScript code in this file.
3
4The MIT License (MIT)
5
6Copyright (C) 1997-2020 by Dimitri van Heesch
7
8Permission is hereby granted, free of charge, to any person obtaining a copy of this software
9and associated documentation files (the "Software"), to deal in the Software without restriction,
10including without limitation the rights to use, copy, modify, merge, publish, distribute,
11sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all copies or
15substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
18BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
23@licend The above is the entire license notice for the JavaScript code in this file
24*/
25
26function initNavTree(toroot,relpath) {27let navTreeSubIndices = [];28const ARROW_DOWN = '▼';29const ARROW_RIGHT = '►';30const NAVPATH_COOKIE_NAME = '85fe94dddf165f44ed4872b508947595_'+'navpath';31
32const getData = function(varName) {33const i = varName.lastIndexOf('/');34const n = i>=0 ? varName.substring(i+1) : varName;35return eval(n.replace(/-/g,'_'));36}37
38const stripPath = function(uri) {39return uri.substring(uri.lastIndexOf('/')+1);40}41
42const stripPath2 = function(uri) {43const i = uri.lastIndexOf('/');44const s = uri.substring(i+1);45const m = uri.substring(0,i+1).match(/\/d\w\/d\w\w\/$/);46return m ? uri.substring(i-6) : s;47}48
49const hashValue = function() {50return $(location).attr('hash').substring(1).replace(/[^\w-]/g,'');51}52
53const hashUrl = function() {54return '#'+hashValue();55}56
57const pathName = function() {58return $(location).attr('pathname').replace(/[^-A-Za-z0-9+&@#/%?=~_|!:,.;()]/g, '');59}60
61const storeLink = function(link) {62if (!$("#nav-sync").hasClass('sync')) {63Cookie.writeSetting(NAVPATH_COOKIE_NAME,link,0);64}65}66
67const deleteLink = function() {68Cookie.eraseSetting(NAVPATH_COOKIE_NAME);69}70
71const cachedLink = function() {72return Cookie.readSetting(NAVPATH_COOKIE_NAME,'');73}74
75const getScript = function(scriptName,func) {76const head = document.getElementsByTagName("head")[0];77const script = document.createElement('script');78script.id = scriptName;79script.type = 'text/javascript';80script.onload = func;81script.src = scriptName+'.js';82head.appendChild(script);83}84
85const createIndent = function(o,domNode,node) {86let level=-1;87let n = node;88while (n.parentNode) { level++; n=n.parentNode; }89if (node.childrenData) {90const imgNode = document.createElement("span");91imgNode.className = 'arrow';92imgNode.style.paddingLeft=(16*level).toString()+'px';93imgNode.innerHTML=ARROW_RIGHT;94node.plus_img = imgNode;95node.expandToggle = document.createElement("a");96node.expandToggle.href = "javascript:void(0)";97node.expandToggle.onclick = function() {98if (node.expanded) {99$(node.getChildrenUL()).slideUp("fast");100node.plus_img.innerHTML=ARROW_RIGHT;101node.expanded = false;102} else {103expandNode(o, node, false, true);104}105}106node.expandToggle.appendChild(imgNode);107domNode.appendChild(node.expandToggle);108} else {109let span = document.createElement("span");110span.className = 'arrow';111span.style.width = 16*(level+1)+'px';112span.innerHTML = ' ';113domNode.appendChild(span);114}115}116
117let animationInProgress = false;118
119const gotoAnchor = function(anchor,aname) {120let pos, docContent = $('#doc-content');121let ancParent = $(anchor.parent());122if (ancParent.hasClass('memItemLeft') || ancParent.hasClass('memtitle') ||123ancParent.hasClass('fieldname') || ancParent.hasClass('fieldtype') ||124ancParent.is(':header')) {125pos = ancParent.position().top;126} else if (anchor.position()) {127pos = anchor.position().top;128}129if (pos) {130const dcOffset = docContent.offset().top;131const dcHeight = docContent.height();132const dcScrHeight = docContent[0].scrollHeight133const dcScrTop = docContent.scrollTop();134let dist = Math.abs(Math.min(pos-dcOffset,dcScrHeight-dcHeight-dcScrTop));135animationInProgress = true;136docContent.animate({137scrollTop: pos + dcScrTop - dcOffset138},Math.max(50,Math.min(500,dist)),function() {139animationInProgress=false;140if (anchor.parent().attr('class')=='memItemLeft') {141let rows = $('.memberdecls tr[class$="'+hashValue()+'"]');142glowEffect(rows.children(),300); // member without details143} else if (anchor.parent().attr('class')=='fieldname') {144glowEffect(anchor.parent().parent(),1000); // enum value145} else if (anchor.parent().attr('class')=='fieldtype') {146glowEffect(anchor.parent().parent(),1000); // struct field147} else if (anchor.parent().is(":header")) {148glowEffect(anchor.parent(),1000); // section header149} else {150glowEffect(anchor.next(),1000); // normal member151}152});153}154}155
156const newNode = function(o, po, text, link, childrenData, lastNode) {157const node = {158children : [],159childrenData : childrenData,160depth : po.depth + 1,161relpath : po.relpath,162isLast : lastNode,163li : document.createElement("li"),164parentNode : po,165itemDiv : document.createElement("div"),166labelSpan : document.createElement("span"),167label : document.createTextNode(text),168expanded : false,169childrenUL : null,170getChildrenUL : function() {171if (!this.childrenUL) {172this.childrenUL = document.createElement("ul");173this.childrenUL.className = "children_ul";174this.childrenUL.style.display = "none";175this.li.appendChild(node.childrenUL);176}177return node.childrenUL;178},179};180
181node.itemDiv.className = "item";182node.labelSpan.className = "label";183createIndent(o,node.itemDiv,node);184node.itemDiv.appendChild(node.labelSpan);185node.li.appendChild(node.itemDiv);186
187const a = document.createElement("a");188node.labelSpan.appendChild(a);189po.getChildrenUL().appendChild(node.li);190a.appendChild(node.label);191if (link) {192let url;193if (link.substring(0,1)=='^') {194url = link.substring(1);195link = url;196} else {197url = node.relpath+link;198}199a.className = stripPath(link.replace('#',':'));200if (link.indexOf('#')!=-1) {201const aname = '#'+link.split('#')[1];202const srcPage = stripPath(pathName());203const targetPage = stripPath(link.split('#')[0]);204a.href = srcPage!=targetPage ? url : aname;205a.onclick = function() {206storeLink(link);207aPPar = $(a).parent().parent();208if (!aPPar.hasClass('selected')) {209$('.item').removeClass('selected');210$('.item').removeAttr('id');211aPPar.addClass('selected');212aPPar.attr('id','selected');213}214const anchor = $(aname);215gotoAnchor(anchor,aname);216};217} else {218a.href = url;219a.onclick = () => storeLink(link);220}221} else if (childrenData != null) {222a.className = "nolink";223a.href = "javascript:void(0)";224a.onclick = node.expandToggle.onclick;225}226return node;227}228
229const showRoot = function() {230const headerHeight = $("#top").height();231const footerHeight = $("#nav-path").height();232const windowHeight = $(window).height() - headerHeight - footerHeight;233(function() { // retry until we can scroll to the selected item234try {235const navtree=$('#nav-tree');236navtree.scrollTo('#selected',100,{offset:-windowHeight/2});237} catch (err) {238setTimeout(arguments.callee, 0);239}240})();241}242
243const expandNode = function(o, node, imm, setFocus) {244if (node.childrenData && !node.expanded) {245if (typeof(node.childrenData)==='string') {246const varName = node.childrenData;247getScript(node.relpath+varName,function() {248node.childrenData = getData(varName);249expandNode(o, node, imm, setFocus);250});251} else {252if (!node.childrenVisited) {253getNode(o, node);254}255$(node.getChildrenUL()).slideDown("fast");256node.plus_img.innerHTML = ARROW_DOWN;257node.expanded = true;258if (setFocus) {259$(node.expandToggle).focus();260}261}262}263}264
265const glowEffect = function(n,duration) {266n.addClass('glow').delay(duration).queue(function(next) {267$(this).removeClass('glow');next();268});269}270
271const highlightAnchor = function() {272const aname = hashUrl();273const anchor = $(aname);274gotoAnchor(anchor,aname);275}276
277const selectAndHighlight = function(hash,n) {278let a;279if (hash) {280const link=stripPath(pathName())+':'+hash.substring(1);281a=$('.item a[class$="'+link+'"]');282}283if (a && a.length) {284a.parent().parent().addClass('selected');285a.parent().parent().attr('id','selected');286highlightAnchor();287} else if (n) {288$(n.itemDiv).addClass('selected');289$(n.itemDiv).attr('id','selected');290}291let topOffset=5;292if ($('#nav-tree-contents .item:first').hasClass('selected')) {293topOffset+=25;294}295$('#nav-sync').css('top',topOffset+'px');296showRoot();297}298
299const showNode = function(o, node, index, hash) {300if (node && node.childrenData) {301if (typeof(node.childrenData)==='string') {302const varName = node.childrenData;303getScript(node.relpath+varName,function() {304node.childrenData = getData(varName);305showNode(o,node,index,hash);306});307} else {308if (!node.childrenVisited) {309getNode(o, node);310}311$(node.getChildrenUL()).css({'display':'block'});312node.plus_img.innerHTML = ARROW_DOWN;313node.expanded = true;314const n = node.children[o.breadcrumbs[index]];315if (index+1<o.breadcrumbs.length) {316showNode(o,n,index+1,hash);317} else if (typeof(n.childrenData)==='string') {318const varName = n.childrenData;319getScript(n.relpath+varName,function() {320n.childrenData = getData(varName);321node.expanded=false;322showNode(o,node,index,hash); // retry with child node expanded323});324} else {325const rootBase = stripPath(o.toroot.replace(/\..+$/, ''));326if (rootBase=="index" || rootBase=="pages" || rootBase=="search") {327expandNode(o, n, true, false);328}329selectAndHighlight(hash,n);330}331}332} else {333selectAndHighlight(hash);334}335}336
337const removeToInsertLater = function(element) {338const parentNode = element.parentNode;339const nextSibling = element.nextSibling;340parentNode.removeChild(element);341return function() {342if (nextSibling) {343parentNode.insertBefore(element, nextSibling);344} else {345parentNode.appendChild(element);346}347};348}349
350const getNode = function(o, po) {351const insertFunction = removeToInsertLater(po.li);352po.childrenVisited = true;353const l = po.childrenData.length-1;354for (let i in po.childrenData) {355const nodeData = po.childrenData[i];356po.children[i] = newNode(o, po, nodeData[0], nodeData[1], nodeData[2], i==l);357}358insertFunction();359}360
361const gotoNode = function(o,subIndex,root,hash,relpath) {362const nti = navTreeSubIndices[subIndex][root+hash];363o.breadcrumbs = $.extend(true, [], nti ? nti : navTreeSubIndices[subIndex][root]);364if (!o.breadcrumbs && root!=NAVTREE[0][1]) { // fallback: show index365navTo(o,NAVTREE[0][1],"",relpath);366$('.item').removeClass('selected');367$('.item').removeAttr('id');368}369if (o.breadcrumbs) {370o.breadcrumbs.unshift(0); // add 0 for root node371showNode(o, o.node, 0, hash);372}373}374
375const navTo = function(o,root,hash,relpath) {376const link = cachedLink();377if (link) {378const parts = link.split('#');379root = parts[0];380hash = parts.length>1 ? '#'+parts[1].replace(/[^\w-]/g,'') : '';381}382if (hash.match(/^#l\d+$/)) {383const anchor=$('a[name='+hash.substring(1)+']');384glowEffect(anchor.parent(),1000); // line number385hash=''; // strip line number anchors386}387const url=root+hash;388let i=-1;389while (NAVTREEINDEX[i+1]<=url) i++;390if (i==-1) { i=0; root=NAVTREE[0][1]; } // fallback: show index391if (navTreeSubIndices[i]) {392gotoNode(o,i,root,hash,relpath)393} else {394getScript(relpath+'navtreeindex'+i,function() {395navTreeSubIndices[i] = eval('NAVTREEINDEX'+i);396if (navTreeSubIndices[i]) {397gotoNode(o,i,root,hash,relpath);398}399});400}401}402
403const showSyncOff = function(n,relpath) {404n.html('<img src="'+relpath+'sync_off.png" title="'+SYNCOFFMSG+'"/>');405}406
407const showSyncOn = function(n,relpath) {408n.html('<img src="'+relpath+'sync_on.png" title="'+SYNCONMSG+'"/>');409}410
411const o = {412toroot : toroot,413node : {414childrenData : NAVTREE,415children : [],416childrenUL : document.createElement("ul"),417getChildrenUL : function() { return this.childrenUL },418li : document.getElementById("nav-tree-contents"),419depth : 0,420relpath : relpath,421expanded : false,422isLast : true,423plus_img : document.createElement("span"),424},425};426o.node.li.appendChild(o.node.childrenUL);427o.node.plus_img.className = 'arrow';428o.node.plus_img.innerHTML = ARROW_RIGHT;429
430const navSync = $('#nav-sync');431if (cachedLink()) {432showSyncOff(navSync,relpath);433navSync.removeClass('sync');434} else {435showSyncOn(navSync,relpath);436}437
438navSync.click(() => {439const navSync = $('#nav-sync');440if (navSync.hasClass('sync')) {441navSync.removeClass('sync');442showSyncOff(navSync,relpath);443storeLink(stripPath2(pathName())+hashUrl());444} else {445navSync.addClass('sync');446showSyncOn(navSync,relpath);447deleteLink();448}449});450
451navTo(o,toroot,hashUrl(),relpath);452showRoot();453
454$(window).bind('hashchange', () => {455if (!animationInProgress) {456if (window.location.hash && window.location.hash.length>1) {457let a;458if ($(location).attr('hash')) {459const clslink=stripPath(pathName())+':'+hashValue();460a=$('.item a[class$="'+clslink.replace(/</g,'\\3c ')+'"]');461}462if (a==null || !$(a).parent().parent().hasClass('selected')) {463$('.item').removeClass('selected');464$('.item').removeAttr('id');465}466const link=stripPath2(pathName());467navTo(o,link,hashUrl(),relpath);468} else {469$('#doc-content').scrollTop(0);470$('.item').removeClass('selected');471$('.item').removeAttr('id');472navTo(o,toroot,hashUrl(),relpath);473}474}475});476
477$("div.toc a[href]").click(function(e) {478e.preventDefault();479const aname = $(this).attr("href");480gotoAnchor($(aname),aname);481});482}
483/* @license-end */
484