1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 // Activate the search box:
7 var form = document.getElementById('chrome-docs-cse-search-form');
8 var searchInput = document.getElementById('chrome-docs-cse-input');
10 var cx = '010997258251033819707:7owyldxmpkc';
12 var gcse = document.createElement('script');
13 gcse.type = 'text/javascript';
15 gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') +
16 '//www.google.com/cse/cse.js?cx=' + cx;
17 var s = document.getElementsByTagName('script')[0];
18 s.parentNode.insertBefore(gcse, s);
20 var executeQuery = function(e) {
21 var element = google.search.cse.element.getElement('results');
22 if (searchInput.value == '') {
23 element.clearAllResults();
25 element.execute(searchInput.value);
31 form.addEventListener('submit', executeQuery);
33 // Attach autocomplete to the search box
34 var enableAutoComplete = function() {
35 google.search.CustomSearchControl.attachAutoCompletionWithOptions(
36 cx, searchInput, form,
37 // set to true to prevent the search box form from being submitted, since
38 // the search control displaying the results is on the same page.
39 {'preferOnSubmitToSubmit': true}
43 var myAutocompleteCallback = function() {
44 // Search module is loaded.
45 if (document.readyState == 'complete') {
48 google.setOnLoadCallback(enableAutoComplete, true);
53 callback: myAutocompleteCallback