| 1 |
/* |
| 2 |
* Copyright 2004-2023 H2 Group. Multiple-Licensed under the MPL 2.0, |
| 3 |
* and the EPL 1.0 (https://h2database.com/html/license.html). |
| 4 |
* Initial Developer: H2 Group |
| 5 |
*/ |
| 6 |
|
| 7 |
function scroll() { |
| 8 |
var scroll = document.documentElement.scrollTop; |
| 9 |
if (!scroll) { |
| 10 |
scroll = document.body.scrollTop; |
| 11 |
} |
| 12 |
var c = 255 - Math.min(scroll / 4, 64); |
| 13 |
var goTop = document.getElementById('goTop'); |
| 14 |
goTop.style.color = 'rgb(' + c + ',' + c + ',' + c + ')'; |
| 15 |
} |
| 16 |
|
| 17 |
function loadFrameset() { |
| 18 |
var a = location.search.split('&'); |
| 19 |
var page = decodeURIComponent(a[0].substr(1)); |
| 20 |
var frame = a[1]; |
| 21 |
if(page && frame){ |
| 22 |
var s = "top." + frame + ".location.replace('" + page + "')"; |
| 23 |
eval(s); |
| 24 |
} |
| 25 |
return; |
| 26 |
} |
| 27 |
|
| 28 |
function frameMe(frame) { |
| 29 |
if(location.host.indexOf('h2database') < 0) { |
| 30 |
// allow translation |
| 31 |
return; |
| 32 |
} |
| 33 |
var frameset = "frame.html"; // name of the frameset page |
| 34 |
if(frame == null) { |
| 35 |
frame = 'main'; |
| 36 |
} |
| 37 |
page = new String(self.document.location); |
| 38 |
var pos = page.lastIndexOf("/") + 1; |
| 39 |
var file = page.substr(pos); |
| 40 |
file = encodeURIComponent(file); |
| 41 |
if(window.name != frame) { |
| 42 |
var s = frameset + "?" + file + "&" + frame; |
| 43 |
top.location.replace(s); |
| 44 |
} else { |
| 45 |
highlightFrame(); |
| 46 |
} |
| 47 |
return; |
| 48 |
} |
| 49 |
|
| 50 |
function addHighlight(page, word, count) { |
| 51 |
if(count > 0) { |
| 52 |
if(top.main.document.location.href.indexOf(page) > 0 && top.main.document.body && top.main.document.body.innerHTML) { |
| 53 |
highlight(); |
| 54 |
} else { |
| 55 |
window.setTimeout('addHighlight("'+page+'","'+word+'",'+(count-1)+')', 10); |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
function highlightFrame() { |
| 61 |
var url = new String(top.main.location.href); |
| 62 |
if(url.indexOf('?highlight=') < 0) { |
| 63 |
return; |
| 64 |
} else { |
| 65 |
var page = url.split('?highlight='); |
| 66 |
var word = decodeURIComponent(page[1]); |
| 67 |
top.main.document.body.innerHTML = highlightSearchTerms(top.main.document.body, word); |
| 68 |
top.main.location = '#firstFound'; |
| 69 |
// window.setTimeout('goFirstFound()', 1); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
function highlight() { |
| 74 |
var url = new String(document.location.href); |
| 75 |
if(url.indexOf('?highlight=') < 0) { |
| 76 |
return; |
| 77 |
} else { |
| 78 |
var page = url.split('highlight=')[1].split('&')[0]; |
| 79 |
var search = decodeURIComponent(url.split('search=')[1].split('#')[0]); |
| 80 |
var word = decodeURIComponent(page); |
| 81 |
document.body.innerHTML = highlightSearchTerms(document.body, word); |
| 82 |
document.location = '#firstFound'; |
| 83 |
document.getElementById('search').value = search; |
| 84 |
listWords(search, ''); |
| 85 |
} |
| 86 |
} |
| 87 |
|
| 88 |
function goFirstFound() { |
| 89 |
top.main.location = '#firstFound'; |
| 90 |
/* |
| 91 |
var page = new String(parent.main.location); |
| 92 |
alert('first: ' + page); |
| 93 |
page = page.split('#')[0]; |
| 94 |
paramSplit = page.split('?'); |
| 95 |
page = paramSplit[0]; |
| 96 |
page += '#firstFound'; |
| 97 |
if(paramSplit.length > 0) { |
| 98 |
page += '?' + paramSplit[1]; |
| 99 |
} |
| 100 |
top.main.location = page; |
| 101 |
*/ |
| 102 |
} |
| 103 |
|
| 104 |
function highlightSearchTerms(body, searchText) { |
| 105 |
matchColor = "ffff00,00ffff,00ff00,ff8080,ff0080".split(','); |
| 106 |
highlightEndTag = "</span>"; |
| 107 |
searchArray = searchText.split(","); |
| 108 |
if (!body || typeof(body.innerHTML) == "undefined") { |
| 109 |
return false; |
| 110 |
} |
| 111 |
var bodyText = body.innerHTML; |
| 112 |
for (var i = 0; i < searchArray.length; i++) { |
| 113 |
var color = matchColor[i % matchColor.length]; |
| 114 |
highlightStartTag = "<span "; |
| 115 |
if(i==0) { |
| 116 |
highlightStartTag += "id=firstFound "; |
| 117 |
} |
| 118 |
highlightStartTag += "style='color:#000000; background-color:#"+color+";'>"; |
| 119 |
bodyText = doHighlight(bodyText, searchArray[i], highlightStartTag, highlightEndTag); |
| 120 |
} |
| 121 |
return bodyText; |
| 122 |
} |
| 123 |
|
| 124 |
function doHighlight(bodyText, searchTerm, highlightStartTag, highlightEndTag) { |
| 125 |
if(searchTerm == undefined || searchTerm=="" || searchTerm.length < 3) { |
| 126 |
return bodyText; |
| 127 |
} |
| 128 |
var newText = ""; |
| 129 |
var i = -1; |
| 130 |
var lcSearchTerm = searchTerm.toLowerCase(); |
| 131 |
var lcBodyText = bodyText.toLowerCase(); |
| 132 |
while (bodyText.length > 0) { |
| 133 |
i = lcBodyText.indexOf(lcSearchTerm, i+1); |
| 134 |
if (i < 0) { |
| 135 |
newText += bodyText; |
| 136 |
bodyText = ""; |
| 137 |
} else { |
| 138 |
// skip anything inside an HTML tag |
| 139 |
if (bodyText.lastIndexOf(">", i) >= bodyText.lastIndexOf("<", i)) { |
| 140 |
// skip anything inside a <script> block |
| 141 |
if (lcBodyText.lastIndexOf("/script>", i) >= lcBodyText.lastIndexOf("<script", i)) { |
| 142 |
newText += bodyText.substring(0, i) + highlightStartTag + bodyText.substr(i, searchTerm.length) + highlightEndTag; |
| 143 |
bodyText = bodyText.substr(i + searchTerm.length); |
| 144 |
lcBodyText = bodyText.toLowerCase(); |
| 145 |
i = -1; |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
} |
| 150 |
return newText; |
| 151 |
} |
| 152 |
|
| 153 |
var drag = false; |
| 154 |
var dragSize = 0; |
| 155 |
var dragStart = 0; |
| 156 |
|
| 157 |
function mouseDown(e) { |
| 158 |
dragStart = e.clientX || e.pageX; |
| 159 |
dragSize = parseInt(document.getElementById('searchMenu').style.width); |
| 160 |
drag = true; |
| 161 |
return false; |
| 162 |
} |
| 163 |
|
| 164 |
function mouseUp(e) { |
| 165 |
drag = false; |
| 166 |
return false; |
| 167 |
} |
| 168 |
|
| 169 |
function mouseMove(e) { |
| 170 |
if (drag) { |
| 171 |
var e = e || window.event; |
| 172 |
var x = e.clientX || e.pageX; |
| 173 |
dragSize += x - dragStart; |
| 174 |
dragStart = x; |
| 175 |
document.getElementById('searchMenu').style.width=dragSize + 'px'; |
| 176 |
return false; |
| 177 |
} |
| 178 |
return true; |
| 179 |
} |
| 180 |
|
| 181 |
function switchBnf(x) { |
| 182 |
var bnfList = document.getElementsByName('bnf'); |
| 183 |
for (var i = 0; i < bnfList.length; i++) { |
| 184 |
var bnf = bnfList[i].style; |
| 185 |
bnf.display = bnf.display == '' ? 'none' : ''; |
| 186 |
} |
| 187 |
var railroads = document.getElementsByName('railroad'); |
| 188 |
for (var i = 0; i < railroads.length; i++) { |
| 189 |
var railroad = railroads[i].style; |
| 190 |
railroad.display = railroad.display == '' ? 'none' : ''; |
| 191 |
} |
| 192 |
if (x) { |
| 193 |
document.location = '#' + x.id; |
| 194 |
} |
| 195 |
} |