2
Copyright (c) 2008 Google Inc.
4
You are free to copy and use this sample.
5
License can be found here: http://code.google.com/apis/ajaxsearch/faq/#license
7
google.load('search', '1');
9
// the cse class encapsulates a search control and a search form
10
function cse(startSearch)
12
var sFormDiv = document.getElementById("searchForm");
13
var sContrDiv = document.getElementById("searchControl");
15
// create search control and a custom search form
16
this.searchControl = new google.search.SearchControl();
17
this.searchForm = new google.search.SearchForm(true, sFormDiv);
19
// bind clear and submit functions
20
this.searchForm.setOnSubmitCallback(this, cse.prototype.onSubmit);
21
this.searchForm.setOnClearCallback(this, cse.prototype.onClear);
23
// set up for large result sets
24
this.searchControl.setResultSetSize(GSearch.LARGE_RESULTSET);
25
this.searchControl.setLinkTarget(GSearch.LINK_TARGET_SELF);
30
// Site Restrict to CSE ID
31
var cseId = "008742922050479854700:sgrtw8uh7hc";
32
// This is for a complete *.ubuntu-it.org search.
33
//var cseId = "008949059787096431823:nzsphralfw4";
34
searcher = new google.search.WebSearch();
35
options = new google.search.SearcherOptions();
36
searcher.setSiteRestriction(cseId, null);
37
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
38
this.searchControl.addSearcher(searcher, options);
40
this.searchControl.draw(sContrDiv);
42
// execute a starter search
43
if (startCustomSearch && startCustomSearch != "")
44
this.searchForm.execute(startCustomSearch);
47
// when the form fires a submit, grab its
48
// value and call the search control
49
cse.prototype.onSubmit = function(form)
51
var q = form.input.value;
53
this.searchControl.execute(q);
58
// when the form fires a clear, call the search control
59
cse.prototype.onClear = function(form)
61
this.searchControl.clearAllResults();
62
form.input.value = "";
71
google.setOnLoadCallback(OnLoad, true);