/* * * Javascript library for EDSearch * Using Google Custom Search and ExtJS 2.0 * */ function escapeHTML (str) { var div = document.createElement('div'); var text = document.createTextNode(str); div.appendChild(text); return div.innerHTML; }; var searchForm = null; var referer = ""; function send(message){ var conn = new Ext.data.Connection(); conn.request({ url:'log.php', method:'POST', params: {"keywords": message, "ACTION_ID": "SEARCH", "referer": referer}, success: function(responseObject) { referer = ""; //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 = "010826869990697334465:nzn4eyycb-4"; 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); cseID = "010826869990697334465:dhqjkrlp1hm" searcher.setSiteRestriction(cseID); 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"); // enable autocomplete $(document).ready(function() { enableAutoComplete(); }); } // 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(escapeHTML(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; } function enableAutoComplete() { $("input[name=search]").each(function(k,v) { if (k == 0) $(v).attr('id','hkecl_search_box'); }); if ($("#hkecl_search_box")) { options = { category:'search_engine', minChars:1, maxHeight:300, width:$("#hkecl_search_box").css('width'), onSelect: function(value, data){ search(value); } }; sb = new search_Autocomplete("hkecl_search_box", options); sb.init(); } return; }