am 24ef1aa6
: Merge "docs: use new CSE to show results for all sites" into honeycomb-mr2
* commit '24ef1aa672cc15984df7cccc5115fdda3ac85f58': docs: use new CSE to show results for all sites
This commit is contained in:
@ -1,144 +1,140 @@
|
|||||||
page.title=Search Results
|
page.title=Search Results
|
||||||
@jd:body
|
@jd:body
|
||||||
|
|
||||||
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
|
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
|
||||||
<script src="{@docRoot}assets/jquery-history.js" type="text/javascript"></script>
|
<script src="{@docRoot}assets/jquery-history.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var tabIndex = 0;
|
var tabIndex = 0;
|
||||||
|
|
||||||
google.load('search', '1');
|
google.load('search', '1');
|
||||||
|
|
||||||
function OnLoad() {
|
function OnLoad() {
|
||||||
document.getElementById("search_autocomplete").style.color = "#000";
|
document.getElementById("search_autocomplete").style.color = "#000";
|
||||||
|
|
||||||
// create search control
|
// create search control
|
||||||
searchControl = new google.search.SearchControl();
|
searchControl = new google.search.SearchControl();
|
||||||
|
|
||||||
// use our existing search form and use tabs when multiple searchers are used
|
// use our existing search form and use tabs when multiple searchers are used
|
||||||
drawOptions = new google.search.DrawOptions();
|
drawOptions = new google.search.DrawOptions();
|
||||||
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
|
drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED);
|
||||||
drawOptions.setInput(document.getElementById("search_autocomplete"));
|
drawOptions.setInput(document.getElementById("search_autocomplete"));
|
||||||
|
|
||||||
// configure search result options
|
// configure search result options
|
||||||
searchOptions = new google.search.SearcherOptions();
|
searchOptions = new google.search.SearcherOptions();
|
||||||
searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
|
searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
|
||||||
|
|
||||||
// configure each of the searchers, for each tab
|
// configure each of the searchers, for each tab
|
||||||
devSiteSearcher = new google.search.WebSearch();
|
devSiteSearcher = new google.search.WebSearch();
|
||||||
devSiteSearcher.setUserDefinedLabel("All Developers Site");
|
devSiteSearcher.setUserDefinedLabel("All");
|
||||||
devSiteSearcher.setSiteRestriction("http://developer.android.com/");
|
devSiteSearcher.setSiteRestriction("001482626316274216503:zu90b7s047u");
|
||||||
|
|
||||||
devGuideSearcher = new google.search.WebSearch();
|
devGuideSearcher = new google.search.WebSearch();
|
||||||
devGuideSearcher.setUserDefinedLabel("Dev Guide");
|
devGuideSearcher.setUserDefinedLabel("Dev Guide");
|
||||||
devGuideSearcher.setSiteRestriction("http://developer.android.com/guide/");
|
devGuideSearcher.setSiteRestriction("http://developer.android.com/guide/");
|
||||||
|
|
||||||
referenceSearcher = new google.search.WebSearch();
|
referenceSearcher = new google.search.WebSearch();
|
||||||
referenceSearcher.setUserDefinedLabel("Reference");
|
referenceSearcher.setUserDefinedLabel("Reference");
|
||||||
referenceSearcher.setSiteRestriction("http://developer.android.com/reference/");
|
referenceSearcher.setSiteRestriction("http://developer.android.com/reference/");
|
||||||
|
|
||||||
blogSearcher = new google.search.WebSearch();
|
blogSearcher = new google.search.WebSearch();
|
||||||
blogSearcher.setUserDefinedLabel("Blog");
|
blogSearcher.setUserDefinedLabel("Blog");
|
||||||
blogSearcher.setSiteRestriction("http://android-developers.blogspot.com");
|
blogSearcher.setSiteRestriction("http://android-developers.blogspot.com");
|
||||||
|
|
||||||
groupsSearcher = new google.search.WebSearch();
|
groupsSearcher = new google.search.WebSearch();
|
||||||
groupsSearcher.setUserDefinedLabel("Developer Groups");
|
groupsSearcher.setUserDefinedLabel("Developer Groups");
|
||||||
groupsSearcher.setSiteRestriction("001283715400630100512:ggqrtvkztwm");
|
groupsSearcher.setSiteRestriction("001283715400630100512:ggqrtvkztwm");
|
||||||
|
|
||||||
sourceSiteSearcher = new google.search.WebSearch();
|
sourceSiteSearcher = new google.search.WebSearch();
|
||||||
sourceSiteSearcher.setUserDefinedLabel("Android Source");
|
sourceSiteSearcher.setUserDefinedLabel("Android Source");
|
||||||
sourceSiteSearcher.setSiteRestriction("http://source.android.com");
|
sourceSiteSearcher.setSiteRestriction("http://source.android.com");
|
||||||
|
|
||||||
homeSiteSearcher = new google.search.WebSearch();
|
// add each searcher to the search control
|
||||||
homeSiteSearcher.setUserDefinedLabel("Android Home");
|
searchControl.addSearcher(devSiteSearcher, searchOptions);
|
||||||
homeSiteSearcher.setSiteRestriction("http://www.android.com");
|
searchControl.addSearcher(devGuideSearcher, searchOptions);
|
||||||
|
searchControl.addSearcher(referenceSearcher, searchOptions);
|
||||||
// add each searcher to the search control
|
searchControl.addSearcher(groupsSearcher, searchOptions);
|
||||||
searchControl.addSearcher(devSiteSearcher, searchOptions);
|
searchControl.addSearcher(sourceSiteSearcher, searchOptions);
|
||||||
searchControl.addSearcher(devGuideSearcher, searchOptions);
|
searchControl.addSearcher(blogSearcher, searchOptions);
|
||||||
searchControl.addSearcher(referenceSearcher, searchOptions);
|
|
||||||
searchControl.addSearcher(groupsSearcher, searchOptions);
|
// configure result options
|
||||||
searchControl.addSearcher(sourceSiteSearcher, searchOptions);
|
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
|
||||||
searchControl.addSearcher(blogSearcher, searchOptions);
|
searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
|
||||||
|
searchControl.setTimeoutInterval(google.search.SearchControl.TIMEOUT_LONG);
|
||||||
// configure result options
|
searchControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING);
|
||||||
searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET);
|
|
||||||
searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF);
|
// upon ajax search, refresh the url and search title
|
||||||
searchControl.setTimeoutInterval(google.search.SearchControl.TIMEOUT_LONG);
|
searchControl.setSearchStartingCallback(this, function(control, searcher, query) {
|
||||||
searchControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING);
|
// save the tab index from the hash
|
||||||
|
tabIndex = location.hash.split("&t=")[1];
|
||||||
// upon ajax search, refresh the url and search title
|
|
||||||
searchControl.setSearchStartingCallback(this, function(control, searcher, query) {
|
$("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
|
||||||
// save the tab index from the hash
|
$.history.add('q=' + query + '&t=' + tabIndex);
|
||||||
tabIndex = location.hash.split("&t=")[1];
|
openTab();
|
||||||
|
});
|
||||||
$("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
|
|
||||||
$.history.add('q=' + query + '&t=' + tabIndex);
|
// draw the search results box
|
||||||
openTab();
|
searchControl.draw(document.getElementById("leftSearchControl"), drawOptions);
|
||||||
});
|
|
||||||
|
// get query and execute the search
|
||||||
// draw the search results box
|
if (location.hash.indexOf("&t=") != -1) {
|
||||||
searchControl.draw(document.getElementById("leftSearchControl"), drawOptions);
|
searchControl.execute(decodeURI(getQuery(location.hash)));
|
||||||
|
}
|
||||||
// get query and execute the search
|
|
||||||
if (location.hash.indexOf("&t=") != -1) {
|
document.getElementById("search_autocomplete").focus();
|
||||||
searchControl.execute(decodeURI(getQuery(location.hash)));
|
addTabListeners();
|
||||||
}
|
}
|
||||||
|
// End of OnLoad
|
||||||
document.getElementById("search_autocomplete").focus();
|
|
||||||
addTabListeners();
|
|
||||||
}
|
google.setOnLoadCallback(OnLoad, true);
|
||||||
// End of OnLoad
|
|
||||||
|
// when an event on the browser history occurs (back, forward, load) perform a search
|
||||||
|
$(window).history(function(e, hash) {
|
||||||
google.setOnLoadCallback(OnLoad, true);
|
var query = decodeURI(getQuery(hash));
|
||||||
|
searchControl.execute(query);
|
||||||
// when an event on the browser history occurs (back, forward, load) perform a search
|
|
||||||
$(window).history(function(e, hash) {
|
$("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
|
||||||
var query = decodeURI(getQuery(hash));
|
});
|
||||||
searchControl.execute(query);
|
|
||||||
|
// forcefully regain key-up event control (previously jacked by search api)
|
||||||
$("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>");
|
$("#search_autocomplete").keyup(function(event) {
|
||||||
});
|
return search_changed(event, false, '/');
|
||||||
|
});
|
||||||
// forcefully regain key-up event control (previously jacked by search api)
|
|
||||||
$("#search_autocomplete").keyup(function(event) {
|
// open a tab, specified by its array position
|
||||||
return search_changed(event, false, '/');
|
function openTab() {
|
||||||
});
|
tabIndex = location.hash.split("&t=")[1];
|
||||||
|
|
||||||
// open a tab, specified by its array position
|
// show the appropriate tab
|
||||||
function openTab() {
|
var tabHeaders = $(".gsc-tabHeader");
|
||||||
tabIndex = location.hash.split("&t=")[1];
|
$(tabHeaders[tabIndex]).click();
|
||||||
|
}
|
||||||
// show the appropriate tab
|
|
||||||
var tabHeaders = $(".gsc-tabHeader");
|
// add event listeners to each tab so we can track the browser history
|
||||||
$(tabHeaders[tabIndex]).click();
|
function addTabListeners() {
|
||||||
}
|
var tabHeaders = $(".gsc-tabHeader");
|
||||||
|
for (var i = 0; i < tabHeaders.length; i++) {
|
||||||
// add event listeners to each tab so we can track the browser history
|
$(tabHeaders[i]).attr("id",i).click(function() {
|
||||||
function addTabListeners() {
|
var tabHeaders = $(".gsc-tabHeader");
|
||||||
var tabHeaders = $(".gsc-tabHeader");
|
|
||||||
for (var i = 0; i < tabHeaders.length; i++) {
|
|
||||||
$(tabHeaders[i]).attr("id",i).click(function() {
|
|
||||||
var tabHeaders = $(".gsc-tabHeader");
|
|
||||||
var tabIndex = $(this).attr("id");
|
var tabIndex = $(this).attr("id");
|
||||||
$.history.add('q=' + getQuery(location.hash) + '&t=' + tabIndex); // update the hash with the new tab
|
$.history.add('q=' + getQuery(location.hash) + '&t=' + tabIndex); // update the hash with the new tab
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQuery(hash) {
|
function getQuery(hash) {
|
||||||
var hashParts = hash.split('&t=');
|
var hashParts = hash.split('&t=');
|
||||||
var queryParts = hashParts[0].split('=');
|
var queryParts = hashParts[0].split('=');
|
||||||
return queryParts[1];
|
return queryParts[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns the given string with all HTML brackets converted to entities
|
/* returns the given string with all HTML brackets converted to entities
|
||||||
TODO: move this to the site's JS library */
|
TODO: move this to the site's JS library */
|
||||||
function escapeHTML(string) {
|
function escapeHTML(string) {
|
||||||
return string.replace(/</g,"<")
|
return string.replace(/</g,"<")
|
||||||
.replace(/>/g,">");
|
.replace(/>/g,">");
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="mainBodyFixed" style="width:auto; margin:20px">
|
<div id="mainBodyFixed" style="width:auto; margin:20px">
|
||||||
|
Reference in New Issue
Block a user