/* * * Javascript library for EDSearch * Using Google Custom Search and ExtJS 2.0 * */ var searchForm = null; function send(message){ var conn = new Ext.data.Connection(); conn.request({ url:'log.php', method:'POST', params: {"keywords": message, "ACTION_ID": "SEARCH"}, success: function(responseObject) { //alert(responseObject.responseText); }, failure: function() { //alert("Something fail"); } }); } google.load("search", "1"); function cse() { this.leftControl = new GSearchControl(); this.rightControl = new GSearchControl(); searchForm = new google.search.SearchForm(true, document.getElementById("searchform")); // bind clear and submit functions searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit); searchForm.setOnClearCallback(this, cse.prototype.onClear); // // configure left control var searcher = new GwebSearch(); var cseID = "007843203786398856593:fhpxcgy91o4"; searcher.setSiteRestriction(cseID); var options = new GsearcherOptions(); options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN); this.leftControl.addSearcher(searcher,options); this.leftControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING) // configure right control searcher = new GwebSearch(); // // restricted to a group of sites // //cseID = "007843203786398856593:llvc9c9bpva"; //searcher.setSiteRestriction(cseID); searcher.setSiteRestriction( { //crefUrl : "http://www.google.com/cse/samples/vegetarian.xml" } crefUrl : "http://search.hkedcity.net/xml/search.xml" } ); searcher.setSearchCompleteCallback(this, cse.prototype.SearchComplete) this.rightControl.addSearcher(searcher,options); this.rightControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING) // this.leftControl.setResultSetSize(GSearch.LARGE_RESULTSET); this.rightControl.setResultSetSize(GSearch.LARGE_RESULTSET); // draw search control this.leftControl.draw(document.getElementById("leftSearchControl")); this.rightControl.draw(document.getElementById("rightSearchControl")); // execute a starter search //searchForm.execute("profiles"); } // when the form fires a submit, grab its // value and call the left and right control cse.prototype.onSubmit = function(form) { var q = form.input.value; if (q && q!= "") { this.leftControl.execute(q); this.rightControl.execute(q); send(q); setSearchTitle(q); } return false; } // when the form fires a clear, call the left and right control cse.prototype.onClear = function(form) { this.leftControl.clearAllResults(); this.rightControl.clearAllResults(); form.input.value = ""; clearSearchTitle(); return false; } cse.prototype.SearchComplete1 = function(form) { alert("In complete call back"); return false; } // // End of CSE class function OnLoad(){ new cse(); } google.setOnLoadCallback(OnLoad); function setSearchTitle(q) { var st = document.getElementById("div_search_title"); st.innerHTML = "搜尋結果 " + q + ""; return; } function clearSearchTitle() { var st = document.getElementById("div_search_title"); st.innerHTML = "搜尋結果 "; return; } function search(keyword) { searchForm.execute(keyword); return; }