orbit-4-2/app/views/layouts/_search.erb

66 lines
1.9 KiB
Plaintext
Raw Normal View History

2014-03-18 22:20:42 +00:00
<div id="search_container">
<div id='search_head'>
<button type="button" id="search_close" class="close pull-left">&times;</button>
<div id='search_time'></div>
</div>
<div id='search_results'></div>
<div id='search_footer'></div>
</div>
<script>
var Search = function(){
var s = this;
2014-03-18 22:20:42 +00:00
var interval = 0;
var keyword;
var processLock=false;
this.init = function(){
$("#q").keyup(function(){s.queueSearch();});
$("#search_form").submit(function(){s.queueSearch(); return false; });
$("#search_close").click(function(){$("#search_container").fadeOut(300);});
}
2014-03-18 22:20:42 +00:00
this.queueSearch = function(){
2014-03-18 22:20:42 +00:00
if($("#q").val() != keyword && $("#q").val()!=""){
keyword = $("#q").val();
interval=500;
if(!processLock) s.processSearch();
2014-03-18 22:20:42 +00:00
}else if($("#q").val()==""){
keyword = ""
$("#search_container").fadeOut(300);
}
}
this.processSearch = function(){
2014-03-19 06:05:54 +00:00
keyword_tmp = keyword;
2014-03-18 22:20:42 +00:00
processLock = true;
if(interval==0 && keyword!=""){
$.getJSON("/site_search", {"keywords" : keyword}, function(data){
2014-03-19 06:05:54 +00:00
if(keyword_tmp != keyword) {
processLock = false;
s.processSearch();
2014-03-19 06:05:54 +00:00
return;
}
2014-03-18 22:20:42 +00:00
$("#search_results").scrollTop(0);
$("#search_results").html("");
$("#search_time").html("Found "+data.results.length+" Results, Search Time: "+data.time+"ms");
$.each(data.results,function(key,res){
search_result =
"<div class='search_result'>"+
"<a href='"+res.url+"' target='_blank'>"+
"<div class='seach_title'>"+res.title+"</div>"+
2014-03-19 06:05:54 +00:00
"</a>"+
2014-03-18 22:20:42 +00:00
"<span>"+res.content+"</span>"+
"</div>";
$("#search_results").append(search_result);
});
$("#search_container").fadeIn(300);
processLock = false;
});
}else if(interval>0){
interval -= 100;
setTimeout(s.processSearch,100);
2014-03-18 22:20:42 +00:00
}
}
s.init();
}();
2014-03-18 22:20:42 +00:00
</script>