Update site search js and add .ruby-version to .gitignore

This commit is contained in:
manson 2014-04-16 10:03:32 +08:00
parent 3c95f053ab
commit d23a956085
2 changed files with 18 additions and 12 deletions

1
.gitignore vendored
View File

@ -25,3 +25,4 @@ uploads/**/*
config/mongoid.yml config/mongoid.yml
*. *.
sftp-config.json sftp-config.json
.ruby-version

View File

@ -7,34 +7,36 @@
<div id='search_footer'></div> <div id='search_footer'></div>
</div> </div>
<script> <script>
var Search = function(){
var s = this;
var interval = 0; var interval = 0;
var keyword; var keyword;
var processLock=false; 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);});
}
$("#q").keyup(function(){queueSearch();}); this.queueSearch = function(){
$("#search_form").submit(function(){queueSearch(); return false; });
function queueSearch(){
if($("#q").val() != keyword && $("#q").val()!=""){ if($("#q").val() != keyword && $("#q").val()!=""){
keyword = $("#q").val(); keyword = $("#q").val();
interval=500; interval=500;
if(!processLock) processSearch(); if(!processLock) s.processSearch();
}else if($("#q").val()==""){ }else if($("#q").val()==""){
keyword = "" keyword = ""
$("#search_container").fadeOut(300); $("#search_container").fadeOut(300);
} }
} }
this.processSearch = function(){
$("#search_close").click(function(){$("#search_container").fadeOut(300);});
function processSearch(){
keyword_tmp = keyword; keyword_tmp = keyword;
processLock = true; processLock = true;
if(interval==0 && keyword!=""){ if(interval==0 && keyword!=""){
$.getJSON("/site_search?keywords="+keyword, function(data){ $.getJSON("/site_search", {"keywords" : keyword}, function(data){
if(keyword_tmp != keyword) { if(keyword_tmp != keyword) {
processLock = false; processLock = false;
processSearch(); s.processSearch();
return; return;
} }
$("#search_results").scrollTop(0); $("#search_results").scrollTop(0);
@ -55,7 +57,10 @@
}); });
}else if(interval>0){ }else if(interval>0){
interval -= 100; interval -= 100;
setTimeout(processSearch,100); setTimeout(s.processSearch,100);
} }
} }
s.init();
}();
</script> </script>