Skip to content

Instantly share code, notes, and snippets.

@freshhold

freshhold/_search.html

Last active Sep 29, 2015
Embed
What would you like to do?
The partial file used to add a custom search page to your NationBuilder site
<style type="text/css">
.gcsc-branding, .gsc-adBlock {
display: none!important;
}
.gsc-table-result, .gsc-thumbnail-inside, .gsc-url-top {
padding-left: 0px!important;
}
.gsc-tabHeader:first-letter {
text-transform: uppercase;
}
.gs-per-result-labels {
display: none;
}
.gsc-adBlockVertical {
display: none!important;
}
.gsc-wrapper.gsc-thinWrapper {
width: 100%!important;
}
</style>
<form method="get" action="/{{ page.slug }}">
<input name="q" type="search" placeholder="Enter keywords..." style="display:inline-block; width:200px; height:40px; margin-bottom:0;">
<input type="submit" class="submit-button" style="height:40px;" value="SEARCH">
</form>
<hr style="margin: 1em 0 0;" />
<div id="cse" style="width:100%;">
<p><img src="/assets/loading.gif" alt="loading" width="24" height="24"> &nbsp;&nbsp; Loading your search results...</p>
</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {
language: 'en',
style: google.loader.themes.CLASSIC
});
google.setOnLoadCallback((function() {
var customSearchControl, customSearchOptions, options, parseParamsFromUrl, queryParamName, urlParams;
customSearchOptions = {};
customSearchControl = new google.search.CustomSearchControl('{{ custom_search_id }}', customSearchOptions);
parseParamsFromUrl = function() {
var i, key, keyValuePair, params, parts;
params = {};
parts = window.location.search.substr(1).split('&');
i = 0;
while (i < parts.length) {
keyValuePair = parts[i].split('=');
key = decodeURIComponent(keyValuePair[0]);
params[key] = keyValuePair[1] ? decodeURIComponent(keyValuePair[1].replace(/\+/g, ' ')) : keyValuePair[1];
i++;
}
return params;
};
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
options = new google.search.DrawOptions;
options.enableSearchResultsOnly();
customSearchControl.draw('cse', options);
urlParams = parseParamsFromUrl();
queryParamName = 'q';
if (urlParams[queryParamName]) {
customSearchControl.execute(urlParams[queryParamName]);
}
}), true);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.