You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yacy_search_server/htroot/js/yacysearch.js

84 lines
2.5 KiB

function AllTextSnippets() {
var query = document.getElementsByName("former")[0].value;
var span = document.getElementsByTagName("span");
for(var x=0;x<span.length;x++) {
if (span[x].className == 'snippetLoading') {
var url = document.getElementById("url" + span[x].id);
requestTextSnippet(url,query);
}
}
}
function requestTextSnippet(url, query){
var request=createRequestObject();
request.open('get', '/xml/snippet.xml?url=' + escape(url) + '&search=' + escape(query) + '&remove=true',true);
request.onreadystatechange = function () {handleTextState(request)};
request.send(null);
}
function handleTextState(req) {
if(req.readyState != 4){
return;
}
var response = req.responseXML;
var snippetText = response.getElementsByTagName("text")[0].firstChild.data;
var urlHash = response.getElementsByTagName("urlHash")[0].firstChild.data;
var status = response.getElementsByTagName("status")[0].firstChild.data;
var span = document.getElementById(urlHash)
removeAllChildren(span);
//span.removeChild(span.firstChild);
if (status < 11) {
span.className = "snippetLoaded";
//span.setAttribute("class", "snippetLoaded");
} else {
span.className = "snippetError";
//span.setAttribute("class", "snippetError");
}
// replace "<b>" text by <strong> node
var pos1=snippetText.indexOf("<b>");
var pos2=snippetText.indexOf("</b>");
while (pos1 >= 0 && pos2 > pos1) {
leftString = document.createTextNode(snippetText.substring(0, pos1)); //other text
if (leftString != "") span.appendChild(leftString);
//add the bold text
strongNode=document.createElement("strong");
middleString=document.createTextNode(snippetText.substring(pos1 + 3, pos2));
strongNode.appendChild(middleString);
span.appendChild(strongNode);
// cut out left and middle and go on with remaining text
snippetText=snippetText.substring(pos2 + 4);
pos1=snippetText.indexOf("<b>");
pos2=snippetText.indexOf("</b>");
}
// add remaining string
if (snippetText != "") {
span.appendChild(document.createTextNode(snippetText));
}
}
function addHover() {
if (document.all&&document.getElementById) {
var divs = document.getElementsByTagName("div");
for (i=0; i<divs.length; i++) {
var node = divs[i];
if (node.className=="searchresults") {
node.onmouseover=function() {
this.className+=" hover";
}
node.onmouseout=function() {
this.className=this.className.replace(" hover", "");
}
}
}
}
}