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/portalsearch/yacy-portalsearch.js

1 line
10 KiB

function yacysearch(a){function g(a,b){var c=a.length;var d=$("#yquery").getValue();for(var e=0,f=c;e<f;++e){if(d.indexOf(a[e])!=-1)$(' <input type="checkbox" checked="checked" class="ynav-cancel" name="ynav'+e+'" value="'+a[e]+'"><span class="ytxt">'+a[e]+"</span><br>").appendTo(b);else a.splice(e,1)}}function f(){window.setTimeout(function(){if($("#ypopup .yloading").length==0){if($("#yquery").getValue()==ycurr){$("#yside").dialog("open");$("#yquery").focus()}}},1e3)}var b=yconf.url+"/yacysearch.json?callback=?";if(a){$("#ypopup").empty();var c="<div class='yloading'><h3 class='linktitle'><em>Loading: "+yconf.url+"</em><br/>";var d="<img src='"+yconf.url+"/yacy/ui/img/loading2.gif' align='absmiddle'/></h3></div>";$("#ypopup").append(c+d);if(!$("#ypopup").dialog("isOpen"))$("#ypopup").dialog("open");else if($("#yside").dialog("isOpen"))$("#yside").dialog("close");$("#yquery").focus()}var e=[];$("#ysearch input").each(function(a){var b={name:$(this).attr("name"),value:$(this).attr("value")};if(b.name=="resource"){if(global)b.value="global";else{b.value="local"}}if(b.name=="query"||b.name=="search"){b.value=$.trim(b.value);if(b.value!=ycurr)ycurr=b.value}e[a]=b});e[e.length]={name:"startRecord",value:startRecord};$.ajaxSetup({timeout:1e4,error:function(b,c){var d="Unknow Error: "+b.responseText;if(b.status==0){d="Unknown Network Error! I try to reload...";yacysearch(true)}else if(b.status==404){d=b.status+" - Requested URL not found."}else if(b.status==500){d=b.status+" - Internel Server Error."}else if(c=="parsererror"){d="Parsing JSON Request failed."}else if(c=="timeout"){d="Request Time out."}if(a)$("#ypopup").empty();var e="<img src='"+yconf.url+"/yacy/ui/img-2/stop.png' class='favicon'/>";var f="<h3 class='linktitle'>"+e+" "+d+"</h3>";var g="<p class='url'><a href=''>Current search terms: "+ycurr+"</a></p>";$(f+g).appendTo("#ypopup")}});$.getJSON(b,e,function(b,c){if(b[0])data=b[0];else data=b;var d="";d=data.channels[0].searchTerms;if($.trim(ycurr.replace(/ /g,"+"))!=d){return false}if(a){$("#ypopup").empty()}var e=data.channels[0].totalResults;if(global)var h="global";else var h="local";var i=0;$.each(data.channels[0].items,function(a,b){if(b){var c="<img src='"+yconf.url+"/ViewImage.png?width=16&height=16&code="+b.faviconCode+"' class='favicon'/>";var d="<h3 class='linktitle'>"+c+"<a href='"+b.link+"' target='_blank'>"+b.title+"</a></h3>";var e="<p class='url'><a href='"+b.link+"' target='_blank'>"+b.link+"</a></p>";var f="<p class='desc'>"+b.description+"</p>";var g="<p class='date'>"+b.pubDate.substring(0,16);var h=" | "+b.sizename+"</p>";$(d+f+e+g+h).appendTo("#ypopup")}i++});if(i==0){if(a)$("#ypopup").empty();var j="<img src='"+yconf.url+"/yacy/ui/img-2/stop.png' class='favicon'/>";var k="<h3 class='linktitle'>"+j+"No search results!</h3>";var l="<p class='url'><a href=''>Current search terms: "+d+"</a></p>";var m="<p class='desc'>You could restate your search, release some navigators or switch to global search...</p>";$(k+m+l).appendTo("#ypopup")}if(a){$("#yside").empty();var n="<a href='"+yconf.link+"' target='_blank'><img style='padding-left: 24px;' src='"+yconf.logo+"' alt='"+yconf.logo+"' title='"+yconf.logo+"' /></a>";var o="Total "+h+" results: "+e;$("<div class='ymsg'><table><tr><td width='55px'>"+n+"</td><td id='yresult'>"+o+"</td></tr></div").appendTo("#yside");$("<hr />").appendTo("#yside");var p='selected="selected">';var q='<select class="selector" id="yglobal"><option value="local"';var r='local</option><option value="global"';var s="global</option></select>";if(global){select=q+">"+r+p+s}else{select=q+p+r+">"+s}$('<div class="ui-widget ynav"><label for="yglobal">Get local/global results:</label><br />'+select+"</div>").appendTo("#yside");$("#yglobal").combobox({selected:function(a,b){if(b.item.value=="global"){global=true}else{global=false}yacysearch(true)}});q='<select class="selector" id="yrecent"><option value="relevance"';r='Relevance</option><option value="date"';s="Date</option></select>";var t=unescape($("#yquery").getValue());if(t.indexOf("/date")!=-1){select=q+">"+r+p+s}else{select=q+p+r+">"+s}$('<div class="ui-widget ynav"><label for="yrecent">Sort result by:</label><br />'+select+"</div>").appendTo("#yside");$("#yrecent").combobox({selected:function(a,b){if(b.item.value=="date"){t=t+" /date"}else{t=t.replace(/\s\/date/g,"")}$("#yquery").setValue($.trim(t));$("#yquery").trigger("keyup")}});$("<hr />").appendTo("#yside");$("<p class='ytxt'>You can narrow down your search by selecting one of the below navigators:</p>").appendTo("#yside");$.each(data.channels[0].navigation,function(a,b){if(b){var c="#y"+b.facetname;var d='<label for="y'+b.facetname+'">'+b.displayname+": </label><br />";var e='<select id="y'+b.facetname+'"><option value="">Select one...</option></select>';$('<div class="ui-widget ynav">'+d+e+"</div>").appendTo("#yside");$.each(b.elements,function(a,b){var d='<option value="'+b.modifier+'">'+b.name+" ("+b.count+")</option>";$(d).appendTo(c)});$(c).combobox({selected:function(a,b){var c=unescape($("#yquery").getValue()+" "+b.item.value);$("#yquery").setValue(c);ynavigators.push(b.item.value);$("#yquery").trigger("submit")}})}});$("<hr />").appendTo("#yside");if(ynavigators.length>0){$("<p class='ytxt'>Uncheck to release navigators:</p>").appendTo("#yside")}g(ynavigators,"#yside");if($("#ypopup .yloading").length==0){$(".ynav-cancel").bind("change",function(a){var b=$("#yquery").getValue();var c=$(a.target).val();var d=ynavigators.indexOf($.trim(c));if(d!=-1)ynavigators.splice(d,1);var e=new RegExp(" "+c.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&"));$("#yquery").setValue($.trim(b.replace(e,"")));startRecord=0;$("#yquery").trigger("submit")});f();if($("#ypopup").dialog("isOpen")){if($("#ypopup h3 :last").position().top<$("#ypopup").dialog("option","height")&&i==maximumRecords){startRecord=startRecord+maximumRecords;yacysearch(false)}}}}})}function yrun(){maximumRecords=parseInt($("#ysearch input[name='maximumRecords']").getValue());global=yconf.global;$("#ypopup").dialog({autoOpen:false,height:yconf.height,width:yconf.width,minWidth:yconf.width,position:yconf.position,modal:yconf.modal,resizable:yconf.resizable,title:yconf.title,show:yconf.show,hide:yconf.hide,drag:function(a,b){var c=$("#ypopup").parent(".ui-dialog").position();var d=$("#ypopup").parent(".ui-dialog").width()+5+c.left;$("#yside").dialog("option","position",[d,c.top+32])},dragStop:function(a,b){var c=$("#ypopup").parent(".ui-dialog").position();var d=$("#ypopup").parent(".ui-dialog").width()+5+c.left;$("#yside").dialog("option","position",[d,c.top+32])},resizeStop:function(a,b){var c=$("#ypopup").parent(".ui-dialog").position();var d=$("#ypopup").parent(".ui-dialog").height()-55;var e=$("#ypopup").parent(".ui-dialog").width()+5+c.left;$("#yside").dialog("option","height",d);$("#yside").dialog("option","position",[e,c.top+32])},close:function(a,b){$("#yquery").setValue("");$("#yside").dialog("destroy");$("#yside").remove()},open:function(a,b){$('<div id="yside" style="padding:0px;"></div>').insertAfter("#ypopup").parent(".ui-dialog-content");var c=$("#ypopup").parent(".ui-dialog").position();$("#yside").dialog({title:"Navigation",autoOpen:false,draggable:false,resizable:false,width:220,height:$("#ypopup").parent(".ui-dialog").height()-55,minHeight:$("#ypopup").parent(".ui-dialog").height()-55,show:"slide",hide:"slide",position:[c.left+$("#ypopup").parent(".ui-dialog").width()+5,c.top+32],open:function(a,b){$("div.ui-widget-shadow").remove();$("#ypopup").dialog("moveToTop")}});$(".ui-widget-shadow").remove();$('div[aria-labelledby="ui-dialog-title-yside"] div.ui-dialog-titlebar').remove();$("#ypopup").bind("scroll",function(a){p1=$("#ypopup h3 :last").position().top;if(p1-$("#ypopup").dialog("option","height")<0){startRecord=startRecord+maximumRecords;yacysearch(false)}})}});$("#ysearch").keyup(function(a){if(a.which==27){$("#ypopup").dialog("close");$("#yquery").setValue("")}if(a.which==18){global=true;ycurr=$("#yquery").getValue();yacysearch(true)}if(ycurr==$("#yquery").getValue()){return false}global=yconf.global;if($("#yquery").getValue()==""){if($("#ypopup").dialog("isOpen"))$("#ypopup").dialog("close")}else{ycurr=$("#yquery").getValue();yacysearch(true)}return false});$("#ysearch").submit(function(){ycurr=$("#yquery").getValue();if(!$("#ypopup").dialog("isOpen"))$("#ypopup").dialog("open");else if($("#yside").dialog("isOpen"))$("#yside").dialog("close");$("#yquery").focus();yacysearch(true);return false})}function statuscheck(){if(load_status<5){return}else{window.clearInterval(loading);yrun()}}$(document).ready(function(){ynavigators=new Array;$.ajaxSetup({timeout:5e3,cache:true});ycurr="";startRecord=0;maximumRecords=10;submit=false;yconf=$.extend({url:"",global:false,theme:"start",title:"YaCy Search Widget",logo:yconf.url+"/yacy/ui/img/yacy-logo.png",link:"http://yacy.net",width:640,height:640,position:[150,50],modal:false,resizable:true,show:"",hide:"",load_js:true,load_css:true},yconf);$('<div id="ypopup" class="classic"></div>').appendTo("#yacylivesearch");if(yconf.load_css){var a=yconf.url+"/portalsearch/yacy-portalsearch.css";var b=yconf.url+"/jquery/themes/"+yconf.theme+"/jquery-ui-1.8.16.custom.css";var c=yconf.url+"/jquery/css/jquery-ui-combobox.css";var d=document.getElementsByTagName("head")[0];$(document.createElement("link")).attr({type:"text/css",href:a,rel:"stylesheet",media:"screen"}).appendTo(d);$(document.createElement("link")).attr({type:"text/css",href:b,rel:"stylesheet",media:"screen"}).appendTo(d);$(document.createElement("link")).attr({type:"text/css",href:c,rel:"stylesheet",media:"screen"}).appendTo(d)}load_status=0;loading=window.setInterval("statuscheck()",200);if(yconf.load_js){var e=yconf.url+"/jquery/js/jquery.query-2.1.7.js";var f=yconf.url+"/jquery/js/jquery.form-2.73.js";var g=yconf.url+"/jquery/js/jquery.field-0.9.2.min.js";var h=yconf.url+"/jquery/js/jquery-ui-1.8.16.custom.min.js";var i=yconf.url+"/jquery/js/jquery-ui-combobox.js";$.getScript(e,function(){load_status++});$.getScript(f,function(){load_status++});$.getScript(g,function(){load_status++});$.getScript(h,function(){load_status++});$.getScript(i,function(){load_status++})}else{yrun()}})