2017-03-21 21:31:10 +01:00
|
|
|
function search() {
|
|
|
|
|
|
|
|
var searchTerm = document.getElementById('searchfield').value;
|
|
|
|
var searchableElements = document.getElementsByTagName('section');
|
|
|
|
|
2018-07-20 22:44:09 +02:00
|
|
|
var regexMatch = new RegExp(searchTerm, 'i');
|
|
|
|
|
|
|
|
// Attempt to create anchor from search term (will default to 'localhost' on failure)
|
|
|
|
var searchTermUri = document.createElement('a');
|
|
|
|
searchTermUri.href = searchTerm;
|
|
|
|
|
|
|
|
if(searchTermUri.hostname == 'localhost') {
|
|
|
|
searchTermUri = null;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Ignore "www."
|
|
|
|
if(searchTermUri.hostname.indexOf('www.') === 0) {
|
|
|
|
searchTermUri.hostname = searchTermUri.hostname.substr(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-03-21 21:31:10 +01:00
|
|
|
|
|
|
|
for(var i = 0; i < searchableElements.length; i++) {
|
|
|
|
|
|
|
|
var textValue = searchableElements[i].getAttribute('data-ref');
|
2018-07-20 22:44:09 +02:00
|
|
|
var anchors = searchableElements[i].getElementsByTagName('a');
|
|
|
|
|
|
|
|
if(anchors != null && anchors.length > 0) {
|
|
|
|
|
|
|
|
var uriValue = anchors[0]; // First anchor is bridge URI
|
|
|
|
|
|
|
|
// Ignore "www."
|
|
|
|
if(uriValue.hostname.indexOf('www.') === 0) {
|
|
|
|
uriValue.hostname = uriValue.hostname.substr(4);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(textValue != null || uriValue != null) {
|
2017-03-21 21:31:10 +01:00
|
|
|
|
2018-07-20 22:44:09 +02:00
|
|
|
if(textValue.match(regexMatch) != null ||
|
|
|
|
uriValue.hostname.match(regexMatch) ||
|
|
|
|
searchTermUri != null &&
|
|
|
|
uriValue.hostname != 'localhost' && (
|
|
|
|
uriValue.href.match(regexMatch) != null ||
|
|
|
|
uriValue.hostname == searchTermUri.hostname)) {
|
2017-03-21 21:31:10 +01:00
|
|
|
|
2018-07-20 22:44:09 +02:00
|
|
|
searchableElements[i].style.display = 'block';
|
2017-03-21 21:31:10 +01:00
|
|
|
|
2018-07-20 22:44:09 +02:00
|
|
|
} else {
|
2017-03-21 21:31:10 +01:00
|
|
|
|
2018-07-20 22:44:09 +02:00
|
|
|
searchableElements[i].style.display = 'none';
|
2017-03-21 21:31:10 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|