1 page.title=Search Results 2 @jd:body 3 4 <script src="http://www.google.com/jsapi" type="text/javascript"></script> 5 <script src="{@docRoot}assets/jquery-history.js" type="text/javascript"></script> 6 <script type="text/javascript"> 7 var tabIndex = 0; 8 9 google.load('search', '1'); 10 11 function OnLoad() { 12 document.getElementById("search_autocomplete").style.color = "#000"; 13 14 // create search control 15 searchControl = new google.search.SearchControl(); 16 17 // use our existing search form and use tabs when multiple searchers are used 18 drawOptions = new google.search.DrawOptions(); 19 drawOptions.setDrawMode(google.search.SearchControl.DRAW_MODE_TABBED); 20 drawOptions.setInput(document.getElementById("search_autocomplete")); 21 22 // configure search result options 23 searchOptions = new google.search.SearcherOptions(); 24 searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_OPEN); 25 26 // configure each of the searchers, for each tab 27 devSiteSearcher = new google.search.WebSearch(); 28 devSiteSearcher.setUserDefinedLabel("All Developers Site"); 29 devSiteSearcher.setSiteRestriction("http://developer.android.com/"); 30 31 devGuideSearcher = new google.search.WebSearch(); 32 devGuideSearcher.setUserDefinedLabel("Dev Guide"); 33 devGuideSearcher.setSiteRestriction("http://developer.android.com/guide/"); 34 35 referenceSearcher = new google.search.WebSearch(); 36 referenceSearcher.setUserDefinedLabel("Reference"); 37 referenceSearcher.setSiteRestriction("http://developer.android.com/reference/"); 38 39 blogSearcher = new google.search.WebSearch(); 40 blogSearcher.setUserDefinedLabel("Blog"); 41 blogSearcher.setSiteRestriction("http://android-developers.blogspot.com"); 42 43 groupsSearcher = new google.search.WebSearch(); 44 groupsSearcher.setUserDefinedLabel("Developer Groups"); 45 groupsSearcher.setSiteRestriction("001283715400630100512:ggqrtvkztwm"); 46 47 sourceSiteSearcher = new google.search.WebSearch(); 48 sourceSiteSearcher.setUserDefinedLabel("Android Source"); 49 sourceSiteSearcher.setSiteRestriction("http://source.android.com"); 50 51 homeSiteSearcher = new google.search.WebSearch(); 52 homeSiteSearcher.setUserDefinedLabel("Android Home"); 53 homeSiteSearcher.setSiteRestriction("http://www.android.com"); 54 55 // add each searcher to the search control 56 searchControl.addSearcher(devSiteSearcher, searchOptions); 57 searchControl.addSearcher(devGuideSearcher, searchOptions); 58 searchControl.addSearcher(referenceSearcher, searchOptions); 59 searchControl.addSearcher(groupsSearcher, searchOptions); 60 searchControl.addSearcher(sourceSiteSearcher, searchOptions); 61 searchControl.addSearcher(blogSearcher, searchOptions); 62 63 // configure result options 64 searchControl.setResultSetSize(google.search.Search.LARGE_RESULTSET); 65 searchControl.setLinkTarget(google.search.Search.LINK_TARGET_SELF); 66 searchControl.setTimeoutInterval(google.search.SearchControl.TIMEOUT_LONG); 67 searchControl.setNoResultsString(google.search.SearchControl.NO_RESULTS_DEFAULT_STRING); 68 69 // upon ajax search, refresh the url and search title 70 searchControl.setSearchStartingCallback(this, function(control, searcher, query) { 71 // save the tab index from the hash 72 tabIndex = location.hash.split("&t=")[1]; 73 74 $("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>"); 75 $.history.add('q=' + query + '&t=' + tabIndex); 76 openTab(); 77 }); 78 79 // draw the search results box 80 searchControl.draw(document.getElementById("leftSearchControl"), drawOptions); 81 82 // get query and execute the search 83 if (location.hash.indexOf("&t=") != -1) { 84 searchControl.execute(decodeURI(getQuery(location.hash))); 85 } 86 87 document.getElementById("search_autocomplete").focus(); 88 addTabListeners(); 89 } 90 // End of OnLoad 91 92 93 google.setOnLoadCallback(OnLoad, true); 94 95 // when an event on the browser history occurs (back, forward, load) perform a search 96 $(window).history(function(e, hash) { 97 var query = decodeURI(getQuery(hash)); 98 searchControl.execute(query); 99 100 $("#searchTitle").html("search results for <em>" + escapeHTML(query) + "</em>"); 101 }); 102 103 // forcefully regain key-up event control (previously jacked by search api) 104 $("#search_autocomplete").keyup(function(event) { 105 return search_changed(event, false, '/'); 106 }); 107 108 // open a tab, specified by its array position 109 function openTab() { 110 tabIndex = location.hash.split("&t=")[1]; 111 112 // show the appropriate tab 113 var tabHeaders = $(".gsc-tabHeader"); 114 $(tabHeaders[tabIndex]).click(); 115 } 116 117 // add event listeners to each tab so we can track the browser history 118 function addTabListeners() { 119 var tabHeaders = $(".gsc-tabHeader"); 120 for (var i = 0; i < tabHeaders.length; i++) { 121 $(tabHeaders[i]).attr("id",i).click(function() { 122 var tabHeaders = $(".gsc-tabHeader"); 123 var tabIndex = $(this).attr("id"); 124 $.history.add('q=' + getQuery(location.hash) + '&t=' + tabIndex); // update the hash with the new tab 125 }); 126 } 127 } 128 129 function getQuery(hash) { 130 var hashParts = hash.split('&t='); 131 var queryParts = hashParts[0].split('='); 132 return queryParts[1]; 133 } 134 135 /* returns the given string with all HTML brackets converted to entities 136 TODO: move this to the site's JS library */ 137 function escapeHTML(string) { 138 return string.replace(/</g,"<") 139 .replace(/>/g,">"); 140 } 141 142 </script> 143 144 <div id="mainBodyFixed" style="width:auto; margin:20px"> 145 <h2 id="searchTitle">search results</h2> 146 <img src="{@docRoot}assets/images/hr_gray_main.jpg" /> 147 <div><br /></div> 148 <div id="leftSearchControl" class="search-control">Loading...</div> 149 </div> 150