| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
function initMenu(relPath,searchEnabled,serverSide,searchPage,search) { |
| 26 |
function makeTree(data,relPath) { |
| 27 |
let result=''; |
| 28 |
if ('children' in data) { |
| 29 |
result+='<ul>'; |
| 30 |
for (let i in data.children) { |
| 31 |
let url; |
| 32 |
const link = data.children[i].url; |
| 33 |
if (link.substring(0,1)=='^') { |
| 34 |
url = link.substring(1); |
| 35 |
} else { |
| 36 |
url = relPath+link; |
| 37 |
} |
| 38 |
result+='<li><a href="'+url+'">'+ |
| 39 |
data.children[i].text+'</a>'+ |
| 40 |
makeTree(data.children[i],relPath)+'</li>'; |
| 41 |
} |
| 42 |
result+='</ul>'; |
| 43 |
} |
| 44 |
return result; |
| 45 |
} |
| 46 |
let searchBoxHtml; |
| 47 |
if (searchEnabled) { |
| 48 |
if (serverSide) { |
| 49 |
searchBoxHtml='<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 { |
| 61 |
searchBoxHtml='<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'); |
| 87 |
if (searchBoxHtml) { |
| 88 |
$('#main-menu').append('<li id="searchBoxPos2" style="float:right"></li>'); |
| 89 |
} |
| 90 |
const $mainMenuState = $('#main-menu-state'); |
| 91 |
let prevWidth = 0; |
| 92 |
if ($mainMenuState.length) { |
| 93 |
const initResizableIfExists = function() { |
| 94 |
if (typeof initResizable==='function') initResizable(); |
| 95 |
} |
| 96 |
|
| 97 |
$mainMenuState.change(function() { |
| 98 |
const $menu = $('#main-menu'); |
| 99 |
let options = { duration: 250, step: initResizableIfExists }; |
| 100 |
if (this.checked) { |
| 101 |
options['complete'] = () => $menu.css('display', 'block'); |
| 102 |
$menu.hide().slideDown(options); |
| 103 |
} else { |
| 104 |
options['complete'] = () => $menu.css('display', 'none'); |
| 105 |
$menu.show().slideUp(options); |
| 106 |
} |
| 107 |
}); |
| 108 |
|
| 109 |
const resetState = function() { |
| 110 |
const $menu = $('#main-menu'); |
| 111 |
const newWidth = $(window).outerWidth(); |
| 112 |
if (newWidth!=prevWidth) { |
| 113 |
if ($(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 |
} |
| 123 |
if (typeof searchBox!=='undefined') { |
| 124 |
searchBox.CloseResultsWindow(); |
| 125 |
} |
| 126 |
prevWidth = newWidth; |
| 127 |
} |
| 128 |
} |
| 129 |
$(window).ready(function() { resetState(); initResizableIfExists(); }); |
| 130 |
$(window).resize(resetState); |
| 131 |
} |
| 132 |
$('#main-menu').smartmenus(); |
| 133 |
} |
| 134 |
|