NBash
134 строки · 5.7 Кб
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*/
25function initMenu(relPath,searchEnabled,serverSide,searchPage,search,treeview) {26function makeTree(data,relPath) {27let result='';28if ('children' in data) {29result+='<ul>';30for (let i in data.children) {31let url;32const link = data.children[i].url;33if (link.substring(0,1)=='^') {34url = link.substring(1);35} else {36url = relPath+link;37}38result+='<li><a href="'+url+'">'+39data.children[i].text+'</a>'+40makeTree(data.children[i],relPath)+'</li>';41}42result+='</ul>';43}44return result;45}46let searchBoxHtml;47if (searchEnabled) {48if (serverSide) {49searchBoxHtml='<div id="MSearchBox" class="MSearchBoxInactive">'+50'<div class="left">'+51'<form id="FSearchBox" action="'+relPath+searchPage+52'" method="get"><span id="MSearchSelectExt"> </span>'+53'<input type="text" id="MSearchField" name="query" value="" placeholder="'+search+54'" size="20" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)"'+55' onblur="searchBox.OnSearchFieldFocus(false)"/>'+56'</form>'+57'</div>'+58'<div class="right"></div>'+59'</div>';60} else {61searchBoxHtml='<div id="MSearchBox" class="MSearchBoxInactive">'+62'<span class="left">'+63'<span id="MSearchSelect" onmouseover="return searchBox.OnSearchSelectShow()"'+64' onmouseout="return searchBox.OnSearchSelectHide()"> </span>'+65'<input type="text" id="MSearchField" value="" placeholder="'+search+66'" accesskey="S" onfocus="searchBox.OnSearchFieldFocus(true)" '+67'onblur="searchBox.OnSearchFieldFocus(false)" '+68'onkeyup="searchBox.OnSearchFieldChange(event)"/>'+69'</span>'+70'<span class="right"><a id="MSearchClose" '+71'href="javascript:searchBox.CloseResultsWindow()">'+72'<img id="MSearchCloseImg" border="0" src="'+relPath+73'search/close.svg" alt=""/></a>'+74'</span>'+75'</div>';76}77}78
79$('#main-nav').before('<div class="sm sm-dox"><input id="main-menu-state" type="checkbox"/>'+80'<label class="main-menu-btn" for="main-menu-state">'+81'<span class="main-menu-btn-icon"></span> '+82'Toggle main menu visibility</label>'+83'<span id="searchBoxPos1" style="position:absolute;right:8px;top:8px;height:36px;"></span>'+84'</div>');85$('#main-nav').append(makeTree(menudata,relPath));86$('#main-nav').children(':first').addClass('sm sm-dox').attr('id','main-menu');87if (searchBoxHtml) {88$('#main-menu').append('<li id="searchBoxPos2" style="float:right"></li>');89}90const $mainMenuState = $('#main-menu-state');91let prevWidth = 0;92if ($mainMenuState.length) {93const initResizableIfExists = function() {94if (typeof initResizable==='function') initResizable(treeview);95}96// animate mobile menu97$mainMenuState.change(function() {98const $menu = $('#main-menu');99let options = { duration: 250, step: initResizableIfExists };100if (this.checked) {101options['complete'] = () => $menu.css('display', 'block');102$menu.hide().slideDown(options);103} else {104options['complete'] = () => $menu.css('display', 'none');105$menu.show().slideUp(options);106}107});108// set default menu visibility109const resetState = function() {110const $menu = $('#main-menu');111const newWidth = $(window).outerWidth();112if (newWidth!=prevWidth) {113if ($(window).outerWidth()<768) {114$mainMenuState.prop('checked',false); $menu.hide();115$('#searchBoxPos1').html(searchBoxHtml);116$('#searchBoxPos2').hide();117} else {118$menu.show();119$('#searchBoxPos1').empty();120$('#searchBoxPos2').html(searchBoxHtml);121$('#searchBoxPos2').show();122}123if (typeof searchBox!=='undefined') {124searchBox.CloseResultsWindow();125}126prevWidth = newWidth;127}128}129$(window).ready(function() { resetState(); initResizableIfExists(); });130$(window).resize(resetState);131}132$('#main-menu').smartmenus();133}
134/* @license-end */
135