forked from cockroachdb/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.html
56 lines (50 loc) · 1.59 KB
/
search.html
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
52
53
54
55
56
---
title: Search
toc: false
---
<script>
// http://stackoverflow.com/a/979995/864236
var QueryString = function () {
// This function is anonymous, is executed immediately and
// the return value is assigned to QueryString!
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}();
document.title = 'Search - ' + QueryString.q;
var obj = {
q: QueryString.q,
cx: '014222686769097698638:i_krv_mjv4w',
key: 'AIzaSyCMGfdDaSfjqv5zYoS0mTJnOT3e9MURWkU'
};
$.getJSON('https://www.googleapis.com/customsearch/v1', obj, function (data) {
var div = $('<div/>');
if (data.items) {
data.items.forEach(function(item) {
var h = $('<div/>', {class: 'search-title'});
h.append($('<a/>', {href: item.link}).html(item.htmlTitle));
var r = $('<div/>', {class: 'search-item'});
r.append(h);
r.append($('<div/>', {class: 'search-link'}).html(item.formattedUrl));
r.append($('<div/>', {class: 'search-snippet'}).html(item.htmlSnippet));
div.append(r);
});
}
$('.post-content').html(div);
});
</script>