-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
51 lines (42 loc) · 1 KB
/
index.js
File metadata and controls
51 lines (42 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var load = require('load');
/*global google */
function search(cx) {
var searchBox = document.getElementById('cseSearchBox'),
searchResults = document.getElementById('cseSearchResults');
function render() {
var cse = google.search.cse;
if (searchBox) {
cse.element.render({
div: searchBox,
tag: 'searchbox-only',
attributes: {
resultsUrl: '/search.html'
}
});
}
if (searchResults) {
cse.element.render({
div: searchResults,
tag: 'searchresults-only',
attributes: {
linkTarget: '_top' // open links in the same window
}
});
}
}
if (!searchBox && !searchResults) {
return;
}
window.__gcse = {
parsetags: 'explicit',
callback: function() {
if (document.readyState == 'complete') {
render();
} else {
google.setOnLoadCallback(render, true);
}
}
};
load('//www.google.com/cse/cse.js?cx=' + cx, true);
}
module.exports = search;