| OLD | NEW |
| 1 // Activate the search box: | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 (function() { | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 var form = document.getElementById('chrome-docs-cse-search-form'); | 3 // found in the LICENSE file. |
| 4 var searchInput = document.getElementById('chrome-docs-cse-input'); | |
| 5 | 4 |
| 6 var cx = '010997258251033819707:7owyldxmpkc'; | 5 // Activate the search box: |
| 6 (function() { |
| 7 var form = document.getElementById('chrome-docs-cse-search-form'); |
| 8 var searchInput = document.getElementById('chrome-docs-cse-input'); |
| 7 | 9 |
| 8 var gcse = document.createElement('script'); | 10 var cx = '010997258251033819707:7owyldxmpkc'; |
| 9 gcse.type = 'text/javascript'; | |
| 10 gcse.async = true; | |
| 11 gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + | |
| 12 '//www.google.com/cse/cse.js?cx=' + cx; | |
| 13 var s = document.getElementsByTagName('script')[0]; | |
| 14 s.parentNode.insertBefore(gcse, s); | |
| 15 | 11 |
| 16 var executeQuery = function(e) { | 12 var gcse = document.createElement('script'); |
| 17 var element = google.search.cse.element.getElement('results'); | 13 gcse.type = 'text/javascript'; |
| 18 if (searchInput.value == '') { | 14 gcse.async = true; |
| 19 element.clearAllResults(); | 15 gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + |
| 20 } else { | 16 '//www.google.com/cse/cse.js?cx=' + cx; |
| 21 element.execute(searchInput.value); | 17 var s = document.getElementsByTagName('script')[0]; |
| 22 } | 18 s.parentNode.insertBefore(gcse, s); |
| 23 e.preventDefault(); | 19 |
| 24 return true; | 20 var executeQuery = function(e) { |
| 21 var element = google.search.cse.element.getElement('results'); |
| 22 if (searchInput.value == '') { |
| 23 element.clearAllResults(); |
| 24 } else { |
| 25 element.execute(searchInput.value); |
| 25 } | 26 } |
| 27 e.preventDefault(); |
| 28 return true; |
| 29 } |
| 26 | 30 |
| 27 form.addEventListener('submit', executeQuery); | 31 form.addEventListener('submit', executeQuery); |
| 28 | 32 |
| 29 // Attach autocomplete to the search box | 33 // Attach autocomplete to the search box |
| 30 var enableAutoComplete = function() { | 34 var enableAutoComplete = function() { |
| 31 console.log("running enableAutoComplete"); | 35 google.search.CustomSearchControl.attachAutoCompletionWithOptions( |
| 32 google.search.CustomSearchControl.attachAutoCompletionWithOptions( | 36 cx, searchInput, form, |
| 33 cx, searchInput, form, | 37 // set to true to prevent the search box form from being submitted, since |
| 34 // set to true to prevent the search box form from being submitted, sinc
e | 38 // the search control displaying the results is on the same page. |
| 35 // the search control displaying the results is on the same page. | 39 {'preferOnSubmitToSubmit': true} |
| 36 {'preferOnSubmitToSubmit': true} | 40 ); |
| 37 ); | 41 }; |
| 38 }; | |
| 39 | 42 |
| 40 var myAutocompleteCallback = function() { | 43 var myAutocompleteCallback = function() { |
| 41 // Search module is loaded. | 44 // Search module is loaded. |
| 42 if (document.readyState == 'complete') { | 45 if (document.readyState == 'complete') { |
| 43 enableAutoComplete(); | 46 enableAutoComplete(); |
| 44 } else { | 47 } else { |
| 45 google.setOnLoadCallback(enableAutoComplete, true); | 48 google.setOnLoadCallback(enableAutoComplete, true); |
| 46 } | 49 } |
| 47 }; | 50 }; |
| 48 | 51 |
| 49 window.__gcse = { | 52 window.__gcse = { |
| 50 callback: myAutocompleteCallback | 53 callback: myAutocompleteCallback |
| 51 }; | 54 }; |
| 52 | 55 |
| 53 })(); | 56 })(); |
| 54 | |
| 55 // End of autocomplete | |
| OLD | NEW |