Skip to content

Commit 74d38f6

Browse files
authored
Merge pull request #2171 from randyl/google-search-option
Google search option
2 parents 0c95459 + 55eeb54 commit 74d38f6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

template/search_template.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,15 @@ $(function(){
6161

6262
return 0;
6363
}
64-
$.each( items.sort(sortBy), function( index, item ) {
64+
var sortedItems = items.sort(sortBy);
65+
var keywords = $("#query").val();
66+
sortedItems.push({
67+
category: 'Site Search',
68+
label: "Search the entire site for " + keywords,
69+
value: keywords,
70+
url: siteSearchUrl( keywords )
71+
});
72+
$.each( sortedItems, function( index, item ) {
6573
var li;
6674
if ( item.category != currentCategory ) {
6775
ul.append( "<li class='ui-autocomplete-category'>" + item.category + "</li>" );
@@ -79,8 +87,7 @@ $(function(){
7987
if ( ! ui.content.length ) {
8088
$('#search').addClass('not-found')
8189
.find('#try-web-search').attr(
82-
'href', 'https://www.google.com/search?q=site%3Adocs.perl6.org+'
83-
+ encodeURIComponent( $("#query").val() )
90+
'href', siteSearchUrl( $("#query").val() )
8491
);
8592
}
8693
else {
@@ -194,6 +201,10 @@ $.extend( $.ui.autocomplete, {
194201
}
195202
} );
196203

204+
function siteSearchUrl( keywords ) {
205+
return 'https://www.google.com/search?q=site%3Adocs.perl6.org+' + encodeURIComponent( keywords );
206+
}
207+
197208
/*
198209
* Courtesy https://siderite.blogspot.com/2014/11/super-fast-and-accurate-string-distance.html
199210
*/

0 commit comments

Comments
 (0)